From ff593361a1f378bdbe4423fc5dd9d650ff3551bb Mon Sep 17 00:00:00 2001 From: Sebastian Grimberg Date: Mon, 28 Aug 2023 18:54:19 -0700 Subject: [PATCH] Fix Julia scripts to return exit code if an error is encountered --- .github/workflows/style.yml | 2 +- scripts/format-source | 14 +++++++++++--- scripts/validate-config | 32 ++++++++++++++++++++------------ 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 4eec87b4d..58dcc1f35 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -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:' diff --git a/scripts/format-source b/scripts/format-source index 0ab5d7d11..539418e40 100755 --- a/scripts/format-source +++ b/scripts/format-source @@ -104,7 +104,8 @@ 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 @@ -112,6 +113,13 @@ catch 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 diff --git a/scripts/validate-config b/scripts/validate-config index e14a875f9..110f4fe0b 100755 --- a/scripts/validate-config +++ b/scripts/validate-config @@ -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