Fix unparseable pom.xml: -- is not allowed inside an XML comment #16
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 | |
| # No parser jar is committed, so setenv.bat fetches one into external_lib\ | |
| # on first use. This step only proves that bootstrap works from a clean | |
| # checkout; the demo steps below would trigger it anyway. | |
| - name: setenv.bat bootstraps the parser from Maven | |
| shell: cmd | |
| run: | | |
| if exist external_lib\gsqlparser-*.jar ( | |
| echo ::error::a parser jar is committed to this repository; it must be fetched, not vendored | |
| exit /b 1 | |
| ) | |
| call setenv\fetch-parser.bat | |
| dir external_lib | |
| for %%f in (external_lib\gsqlparser-*.jar) do exit /b 0 | |
| echo ::error::fetch-parser.bat produced no parser jar | |
| exit /b 1 | |
| # Phase 1: every compile_<demo>.bat must succeed. This is the check that | |
| # matters, and the one that would have caught the whole family going stale | |
| # when the demos moved directory. `pause` at the end of each script would | |
| # block forever on a runner with no keyboard, so stdin is fed from NUL. | |
| - name: Compile all 39 demos via compile_*.bat | |
| shell: cmd | |
| run: | | |
| setlocal enabledelayedexpansion | |
| set FAILED=0 | |
| set COUNT=0 | |
| for /r "%GITHUB_WORKSPACE%\src\main\java" %%s in (compile_*.bat) do ( | |
| set /a COUNT+=1 | |
| pushd "%%~dps" | |
| call "%%~nxs" < NUL > "%GITHUB_WORKSPACE%\c.txt" 2>&1 | |
| findstr /i /c:"error" /c:"file not found" /c:"no source files" "%GITHUB_WORKSPACE%\c.txt" >NUL && ( | |
| echo ::error::%%~nxs failed | |
| type "%GITHUB_WORKSPACE%\c.txt" | |
| set /a FAILED+=1 | |
| ) || echo ok %%~nxs | |
| popd | |
| ) | |
| echo. | |
| echo compiled !COUNT! demos, !FAILED! failed | |
| if not !FAILED!==0 exit /b 1 | |
| # Phase 2: every run_<demo>.bat must at least start its class. Run with no | |
| # arguments, so most print their own usage line; what this proves is that | |
| # the class name in the script still resolves and the classpath is right. | |
| # A stale class name after a package move shows up here as | |
| # ClassNotFoundException, which is exactly what had happened. | |
| - name: Launch all 50 demos via run_*.bat | |
| shell: cmd | |
| run: | | |
| setlocal enabledelayedexpansion | |
| set FAILED=0 | |
| set COUNT=0 | |
| for /r "%GITHUB_WORKSPACE%\src\main\java" %%s in (run_*.bat) do ( | |
| set /a COUNT+=1 | |
| pushd "%%~dps" | |
| call "%%~nxs" < NUL > "%GITHUB_WORKSPACE%\r.txt" 2>&1 | |
| findstr /c:"ClassNotFoundException" /c:"NoClassDefFoundError" /c:"Main method not found" "%GITHUB_WORKSPACE%\r.txt" >NUL && ( | |
| echo ::error::%%~nxs could not launch its class | |
| type "%GITHUB_WORKSPACE%\r.txt" | |
| set /a FAILED+=1 | |
| ) || echo ok %%~nxs | |
| popd | |
| ) | |
| echo. | |
| echo launched !COUNT! demos, !FAILED! failed | |
| if not !FAILED!==0 exit /b 1 | |
| # `pause` at the end of each script would block forever on a runner with | |
| # no keyboard, so stdin is fed from NUL. | |
| # | |
| # These four cover the shapes the scripts come in: a file+vendor demo, a | |
| # bare-filename demo, one that takes no arguments at all, and one nested a | |
| # directory deeper (so its cd depth differs). They are generated from one | |
| # template and go stale as a set, which is exactly what happened when the | |
| # demos moved directory, so this is a canary rather than full coverage. | |
| # Phase 3: a few demos driven with real arguments and checked against a | |
| # string their output must contain, so this is not only a smoke test. | |
| - name: Run four demos with real arguments | |
| shell: cmd | |
| run: | | |
| echo SELECT a.id FROM ta a; > "%GITHUB_WORKSPACE%\q.sql" | |
| rem dir compile script run script args expected in output | |
| call :demo checksyntax checksyntax checksyntax "/f %GITHUB_WORKSPACE%\q.sql /t oracle" "syntax errors: 0" || exit /b 1 | |
| call :demo formatsql formatsql formatsql "%GITHUB_WORKSPACE%\q.sql" "SELECT" || exit /b 1 | |
| call :demo listGSPInfo listGSPInfo listGSPInfo "" "Supported DBs" || exit /b 1 | |
| call :demo modifysql modifysql replaceTablename "" "output sql" || exit /b 1 | |
| echo All .bat demos passed. | |
| exit /b 0 | |
| :demo | |
| setlocal | |
| set DEMO=%~1 | |
| set CSCRIPT=%~2 | |
| set RSCRIPT=%~3 | |
| set ARGS=%~4 | |
| set EXPECT=%~5 | |
| echo. | |
| echo ==== %DEMO% : compile_%CSCRIPT%.bat / run_%RSCRIPT%.bat ==== | |
| cd /d "%GITHUB_WORKSPACE%\src\main\java\gudusoft\gsqlparser\demos\%DEMO%" | |
| call compile_%CSCRIPT%.bat < NUL > "%GITHUB_WORKSPACE%\c.txt" 2>&1 | |
| type "%GITHUB_WORKSPACE%\c.txt" | |
| findstr /i /c:"error" "%GITHUB_WORKSPACE%\c.txt" >NUL && ( | |
| echo ::error::compile_%CSCRIPT%.bat reported an error | |
| endlocal & exit /b 1 | |
| ) | |
| call run_%RSCRIPT%.bat %ARGS% < NUL > "%GITHUB_WORKSPACE%\r.txt" 2>&1 | |
| type "%GITHUB_WORKSPACE%\r.txt" | |
| findstr /c:"%EXPECT%" "%GITHUB_WORKSPACE%\r.txt" >NUL || ( | |
| echo ::error::run_%RSCRIPT%.bat did not print "%EXPECT%" | |
| endlocal & exit /b 1 | |
| ) | |
| endlocal & exit /b 0 |