Verify the .bat scripts on Windows in CI, and make them actually work #12
This file contains hidden or 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
| name: Build and test | |
| # These demos used to be a vendored tree inside the gsp_java library repo, whose | |
| # CI ran their tests via `mvn test -pl gsp_demo_java`. That tree has been | |
| # retired, so this workflow keeps the tests running rather than letting the | |
| # signal disappear with it. | |
| # | |
| # The parser is resolved from Gudu's public Maven repository, declared in | |
| # pom.xml, so nothing here needs credentials. | |
| on: | |
| push: | |
| branches: [master] | |
| pull_request: | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| # The parser jar is Java 8 bytecode and the POM pins source/target 1.8. | |
| # Building on both proves the demos stay consumable from an old JDK and | |
| # keep compiling on a current LTS. | |
| java: ["8", "21"] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK ${{ matrix.java }} | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: ${{ matrix.java }} | |
| cache: maven | |
| - name: Build | |
| run: mvn -B package -DskipTests | |
| # Three tests in analyzespTest compare stored-procedure output against | |
| # golden strings written for an older parser and currently fail. They are | |
| # deliberately not deleted -- see the README -- so the suite is expected | |
| # to be red on exactly those three. `|| true` would hide a real | |
| # regression, so instead assert the failure count has not grown. | |
| - name: Test | |
| id: test | |
| continue-on-error: true | |
| run: mvn -B test | |
| - name: Check only the known failures are failing | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| if [ ! -d target/surefire-reports ]; then | |
| echo "::error::no surefire reports produced" | |
| exit 1 | |
| fi | |
| total=$(grep -ho "Tests run: [0-9]*" target/surefire-reports/*.txt | awk '{s+=$3} END {print s+0}') | |
| fails=$(grep -hoE "Failures: [0-9]*" target/surefire-reports/*.txt | awk '{s+=$2} END {print s+0}') | |
| errs=$(grep -hoE "Errors: [0-9]*" target/surefire-reports/*.txt | awk '{s+=$2} END {print s+0}') | |
| echo "tests=$total failures=$fails errors=$errs" | |
| if [ "$errs" -ne 0 ]; then | |
| echo "::error::$errs test error(s); expected 0" | |
| grep -l -E "Errors: [1-9]" target/surefire-reports/*.txt || true | |
| exit 1 | |
| fi | |
| if [ "$fails" -gt 3 ]; then | |
| echo "::error::$fails failures, expected at most the 3 known analyzespTest ones" | |
| grep -l -E "Failures: [1-9]" target/surefire-reports/*.txt || true | |
| exit 1 | |
| fi | |
| if [ "$fails" -lt 3 ]; then | |
| echo "::notice::only $fails failures — if analyzespTest was fixed, lower the threshold in this workflow and update the README" | |
| fi | |
| - name: Smoke test a demo | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| printf 'SELECT a.id, b.name FROM ta a JOIN tb b ON a.id = b.id WHERE a.x > 1;\n' > q.sql | |
| out=$(mvn -q exec:java \ | |
| -Dexec.mainClass=gudusoft.gsqlparser.demos.checksyntax.checksyntax \ | |
| -Dexec.args="/f q.sql /t oracle" -Dexec.classpathScope=compile) | |
| echo "$out" | |
| grep -q "syntax errors: 0" <<<"$out" | |
| # The .bat scripts are the original Windows, no-Maven workflow: edit | |
| # setenv\setenv.bat, cd into a demo folder, run compile_<demo>.bat then | |
| # run_<demo>.bat. They had been stale for years -- compiling | |
| # src\main\java\demos\<demo>\ and cd-ing up five levels, both correct only | |
| # before the demos moved under gudusoft\gsqlparser\demos\ -- and nothing ever | |
| # noticed, because nothing ran them. This job runs them. | |
| windows-bat: | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| # The .bat scripts want a JDK 8 era toolchain, and setenv.bat now keeps | |
| # whatever JAVA_HOME it is given rather than hardcoding one. | |
| - name: Set up JDK 8 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: "8" | |
| cache: maven | |
| # These scripts predate the parser being resolved from Maven. lib\ only | |
| # carries old parser jars now, so on its own compile_<demo>.bat fails on | |
| # symbols those jars predate. Drop the current parser into external_lib\, | |
| # which setenv.bat puts ahead of lib\ on the classpath for exactly this | |
| # reason. Not vendored: fetched here, and gitignored. | |
| - name: Fetch the parser into external_lib | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| ver=$(mvn -q help:evaluate -Dexpression=gsp.core.version -DforceStdout) | |
| echo "parser version: $ver" | |
| mvn -q dependency:copy \ | |
| -Dartifact=com.gudusoft:gsqlparser:"$ver" \ | |
| -DoutputDirectory=external_lib | |
| ls external_lib | |
| # `pause` at the end of each script would block forever on a runner with | |
| # no keyboard, so stdin is fed from NUL. | |
| - name: compile_checksyntax.bat then run_checksyntax.bat | |
| shell: cmd | |
| run: | | |
| cd src\main\java\gudusoft\gsqlparser\demos\checksyntax | |
| call compile_checksyntax.bat < NUL | |
| if not exist "%GITHUB_WORKSPACE%\build\gudusoft\gsqlparser\demos\checksyntax\checksyntax.class" ( | |
| echo ::error::compile_checksyntax.bat did not produce checksyntax.class | |
| exit /b 1 | |
| ) | |
| cd /d "%GITHUB_WORKSPACE%" | |
| echo SELECT a.id FROM ta a; > q.sql | |
| cd src\main\java\gudusoft\gsqlparser\demos\checksyntax | |
| call run_checksyntax.bat /f "%GITHUB_WORKSPACE%\q.sql" /t oracle < NUL > "%GITHUB_WORKSPACE%\out.txt" 2>&1 | |
| type "%GITHUB_WORKSPACE%\out.txt" | |
| findstr /c:"syntax errors: 0" "%GITHUB_WORKSPACE%\out.txt" >NUL || ( | |
| echo ::error::run_checksyntax.bat did not report "syntax errors: 0" | |
| exit /b 1 | |
| ) |