Skip to content

Commit

Permalink
fail on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
M. Fatih Cırıt committed Feb 20, 2024
1 parent 71f4178 commit 35e04c0
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions json-schema-check/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ runs:

- name: Check configuration files
run: |
# Use a file to track failures
touch check_failures
find . -path '*/schema/*.schema.json' -exec bash -c '
schemaFile="${1#./}" # Normalize schema file path to remove leading ./
Expand All @@ -24,23 +27,19 @@ runs:
shopt -s nullglob # Enable nullglob to handle no matches as an empty array

Check warning on line 27 in json-schema-check/action.yaml

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (shopt)

Check warning on line 27 in json-schema-check/action.yaml

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (nullglob)

Check warning on line 27 in json-schema-check/action.yaml

View workflow job for this annotation

GitHub Actions / spell-check-differential

Unknown word (nullglob)
configFiles=("${configDir}/${baseName}"*.param.yaml) # Pattern match for config files
errorFlag=0 # Flag to track validation failures
for configFile in "${configFiles[@]}"; do
echo -n "Validating: $configFile <-> $schemaFile => "
if check-jsonschema --schemafile "$schemaFile" "$configFile"; then
# If validation succeeds, print success message
echo "✅ Passed"
else
# If validation fails, set error flag and print failure message
errorFlag=1
if ! check-jsonschema --schemafile "$schemaFile" "$configFile"; then
# If validation fails, print failure message and record the failure
echo "❌ Failed"
echo "1" > check_failures
fi
done
if [ "$errorFlag" -ne 0 ]; then
echo "❗ Validation encountered errors." >&2 # Print error message to stderr
exit 1 # Exit with error to fail the workflow step
fi
' bash {} \;
if [ "$(cat check_failures)" = "1" ]; then
echo "Validation failed for one or more files."
rm check_failures # Clean up
exit 1
fi
rm check_failures # Clean up
shell: bash

0 comments on commit 35e04c0

Please sign in to comment.