From 8506bf539338ac97c82d5204084aa8e425298e07 Mon Sep 17 00:00:00 2001 From: Matthew Pope <81593196+popematt@users.noreply.github.com> Date: Thu, 14 Nov 2024 11:55:22 -0800 Subject: [PATCH] Fix check-syntax script (#130) --- .github/workflows/main.yaml | 4 ++-- check-syntax | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index cc8ba17..0483fb8 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -11,11 +11,11 @@ on: - '**:**' jobs: - validate: + check-conformance-test-syntax: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Install Ion CLI - run: cargo install ion-cli@0.8.0 + run: cargo install ion-cli@0.9.1 - name: Run validation script run: ./check-syntax diff --git a/check-syntax b/check-syntax index 222b907..cda4204 100755 --- a/check-syntax +++ b/check-syntax @@ -1,9 +1,34 @@ #!/bin/bash +set -eu # Checks the syntax of the conformance test files against an ISL grammar for the conformance DSL. -# This requires at least ion-cli@0.8.0 for the `-R` option. -# We have to include the `--no-auto-decompress` flag because there's an issue that prevents Ion CLI from -# correctly reading files that start with a line comment. -# See: https://github.com/amazon-ion/ion-cli/issues/162 -ion schema -X validate --no-auto-decompress -RE -f conformance/grammar.isl test_file conformance/**/*.ion +# This requires at least ion-cli@0.9.1 because a bugfix in ion-rust +readonly ion_cli_min_version="ion 0.9.1" + +# Check the Ion CLI version so that we aren't erroneously passing because of an unfixed bug +readonly ion_cli_version=$(printf "%s\n%s" "$ion_cli_min_version" "$(ion -V)" | sort --version-sort | head -n 1) + +if [[ "$ion_cli_version" != "$ion_cli_min_version" ]]; then + echo "This script requires $ion_cli_min_version; found $ion_cli_version" + exit 1 +fi + +readonly command=\ +'ion schema -X validate -RE -f conformance/grammar.isl test_file conformance/**/*.ion' + +# Macs come with older versions of bash which don't support globstar, so if we're on an older +# version of bash, we'll attempt to use zsh instead, but we don't use zsh by default because +# it doesn't come pre-installed on GitHub Actions runners +if [ -z "${BASH_VERSION}" ] || [ "${BASH_VERSION%%.*}" -lt 4 ]; then + if which -s zsh; then + printf "bash version requirements not met; using zsh\n\n" + echo "$command" | zsh + else + echo "The check-syntax script requires either bash >=4.0.0 or zsh" + exit 1 + fi +else + shopt -s globstar + eval "$command" +fi