-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a CI check for JSON and YAML files
- Loading branch information
Showing
3 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
name: Code static analysis | ||
on: [pull_request] # yamllint disable-line rule:truthy | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
code-static-analysis: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Validate YAML files (best code practices check included) | ||
id: validate-yaml-files | ||
uses: ibiqlik/[email protected] | ||
with: | ||
config_file: ./ci/yamllint-config.yaml | ||
|
||
# In some YAML files we use JSON strings, let's check these | ||
- name: Validate JSON strings in YAML files (just syntax) | ||
id: validate-json-strings-in-yaml-files | ||
run: | | ||
type json_verify || sudo apt-get install yajl-tools | ||
bash ./ci/check-json.sh | ||
- name: Validate JSON files (just syntax) | ||
id: validate-json-files | ||
run: | | ||
type json_verify || sudo apt-get install yajl-tools | ||
shopt -s globstar | ||
ret_code=0 | ||
echo "-- Checking a regular '*.json' files" | ||
for f in **/*.json; do echo "Checking: '${f}"; echo -n " > "; cat $f | json_verify || ret_code=1; done | ||
echo "-- Checking a 'Pipfile.lock' files" | ||
for f in **/Pipfile.lock; do echo "Checking: '${f}"; echo -n " > "; cat $f | json_verify || ret_code=1; done | ||
echo "-- Checking a '*.ipynb' Jupyter notebook files" | ||
for f in **/*.ipynb; do echo "Checking: '${f}"; echo -n " > "; cat $f | json_verify || ret_code=1; done | ||
if test "${ret_code}" -ne 0; then | ||
echo "There were errors in some of the checked files. Please run `json_verify` on such files and fix issues there." | ||
fi | ||
exit "${ret_code}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
# | ||
# This script serves to check YAML files in this repository that contain particular | ||
# key fields where JSON string is expected. Such JSON strings are extracted and | ||
# validated via `json_verify` tool. | ||
# | ||
# Local execution: ./ci/check-json.sh | ||
# Note: please execute from the root directory so that whole dir tree is checked | ||
# | ||
# In case of the PR on GitHub, this check is tied to GitHub actions automatically, | ||
# see `.github/workflows` directory. | ||
|
||
shopt -s globstar | ||
|
||
function check_json() { | ||
local f="${1}" | ||
local string="${2}" | ||
|
||
local ret_code=0 | ||
|
||
echo "" # Let's make some space from eventual previous file check | ||
echo "Checking: '${f}' - for '${string}':" | ||
|
||
if grep --quiet --extended-regexp "${string}" "${f}"; then | ||
#if $(grep -e "${string}" "${f}"); then | ||
jsons=$(yq -r ".spec.tags[].annotations.\"${string}\"" "${f}") | ||
|
||
while IFS= read -r json; do | ||
echo " ${json}" | ||
echo -n " > "; echo "${json}" | json_verify || ret_code="${?}" | ||
done <<< "${jsons}" | ||
else | ||
echo " Ignoring as this file doesn't contain necessary key field '${string}' for check" | ||
fi | ||
|
||
return "${ret_code}" | ||
} | ||
|
||
ret_code=0 | ||
for f in **/*.yml **/*.yaml; do | ||
check_json "${f}" "opendatahub.io/notebook-software" || ret_code="${?}" | ||
check_json "${f}" "opendatahub.io/notebook-python-dependencies" || ret_code="${?}" | ||
done | ||
|
||
exit "${ret_code}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
|
||
extends: default | ||
|
||
rules: | ||
line-length: disable | ||
new-line-at-end-of-file: | ||
level: warning |