Skip to content

Commit

Permalink
Fix Julia scripts to return exit code if an error is encountered
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiangrimberg committed Aug 29, 2023
1 parent 1d55bc4 commit ff59336
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

- name: Check JSON Schema
run: |
OUTPUT=$(find examples -name *.json -exec ./scripts/validate-config {} \;)
OUTPUT=$(find examples -name *.json | xargs ./scripts/validate-config)
if echo $OUTPUT | grep -q 'Validation failed'; then
echo 'Error: Configuration file validation failed!'
echo 'Summary of output:'
Expand Down
14 changes: 11 additions & 3 deletions scripts/format-source
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,22 @@ if $FORMAT_JL; then
-type f \( -iname \*.md -o -iname \*.jl \) -exec echo -n '"{}", ' \;)
FORMAT_JL_FILES="$(find $SOURCE_DIR -maxdepth 1 \
-type f -iname \*.md -exec echo -n '"{}", ' \;)$FORMAT_JL_FILES"
echo "
JULIA_CMD=$(
cat << EOF
try
@eval using JuliaFormatter
catch
using Pkg; Pkg.UPDATED_REGISTRY_THIS_SESSION[] = true
Pkg.activate(; temp=true); Pkg.add(\"JuliaFormatter\")
@eval using JuliaFormatter
end
format([$FORMAT_JL_FILES], $FORMAT_JL_ARGS)
" | $JULIA
try
format([$FORMAT_JL_FILES], $FORMAT_JL_ARGS)
catch e
showerror(stderr, e.msg)
exit(1)
end
EOF
)
echo "$JULIA_CMD" | $JULIA
fi
32 changes: 20 additions & 12 deletions scripts/validate-config
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,31 @@ if ! command -v $JULIA &> /dev/null; then
exit 1
fi

echo "
JULIA_CMD=$(
cat << EOF
try
using JSON
using JSONSchema
catch
using Pkg; Pkg.UPDATED_REGISTRY_THIS_SESSION[] = true
Pkg.activate(; temp=true); Pkg.add([\"JSON\", \"JSONSchema\"])
Pkg.activate(; temp=true); Pkg.add(["JSON", "JSONSchema"])
end
include(joinpath(\"$SCRIPT_DIR\", \"schema\", \"ValidateConfig.jl\"))
include(joinpath("$SCRIPT_DIR", "schema", "ValidateConfig.jl"))
using .ValidateConfig
result = validate_config_file(;
config_file=\"$CONFIG\",
schema_file=joinpath(\"$SCRIPT_DIR\", \"schema\", \"config-schema.json\")
)
if result != nothing
println(\"Dry-run: Configuration file \\\"$CONFIG\\\" contains errors!\")
else
println(\"Dry-run: No errors detected in configuration file \\\"$CONFIG\\\"\")
try
result = validate_config_file(;
config_file="$CONFIG",
schema_file=joinpath("$SCRIPT_DIR", "schema", "config-schema.json")
)
if result != nothing
println("Dry-run: Configuration file \"$CONFIG\" contains errors!")
else
println("Dry-run: No errors detected in configuration file \"$CONFIG\"")
end
catch e
showerror(stderr, e.msg)
exit(1)
end
" | $JULIA
EOF
)
echo "$JULIA_CMD" | $JULIA

0 comments on commit ff59336

Please sign in to comment.