Fix Maven 4 CI setup with separate JDK install #97
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 Java 9 Jigsaw Examples | |
| on: | |
| push: | |
| pull_request: | |
| workflow_dispatch: | |
| jobs: | |
| shellcheck: | |
| name: Shellcheck | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install shellcheck | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y shellcheck | |
| - name: Run shellcheck on orchestration scripts | |
| shell: bash | |
| run: cd jigsaw-examples && shellcheck -ax all*.sh | |
| - name: Run shellcheck on m4 scripts | |
| shell: bash | |
| run: | | |
| cd jigsaw-examples | |
| for m4_dir in */m4; do | |
| echo "=== Checking ${m4_dir} ===" | |
| (cd "${m4_dir}" && shellcheck -ax *.sh) | |
| done | |
| build-legacy: | |
| name: Build (legacy) on ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| needs: shellcheck | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| steps: | |
| - name: Disable CRLF conversion | |
| run: git config --global core.autocrlf false | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 8 (non macOS) | |
| id: setup-jdk8 | |
| uses: actions/setup-java@v5 | |
| if: runner.os != 'macOS' | |
| with: | |
| distribution: 'temurin' | |
| java-version: '8' | |
| - name: Set up JDK 8 (macOS) | |
| id: setup-jdk8-mac | |
| uses: actions/setup-java@v5 | |
| if: runner.os == 'macOS' | |
| with: | |
| distribution: 'zulu' | |
| java-version: '8' | |
| - name: Set up JDK 11 | |
| id: setup-jdk11 | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: 'temurin' | |
| # tag::java-version-minimal[] | |
| java-version: '11.0.28' | |
| # end::java-version-minimal[] | |
| - name: Set up JDK 17 | |
| id: setup-jdk17 | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| - name: Create .envrc with Java paths | |
| shell: bash | |
| env: | |
| JAVA8_PATH: ${{ steps.setup-jdk8.outputs.path || steps.setup-jdk8-mac.outputs.path }} | |
| JAVA11_PATH: ${{ steps.setup-jdk11.outputs.path }} | |
| JAVA17_PATH: ${{ steps.setup-jdk17.outputs.path }} | |
| run: | | |
| # Convert Windows paths to Unix paths if on Windows | |
| if [[ "$RUNNER_OS" == "Windows" ]]; then | |
| JAVA8_PATH="$(cygpath -u "$JAVA8_PATH")" | |
| JAVA11_PATH="$(cygpath -u "$JAVA11_PATH")" | |
| JAVA17_PATH="$(cygpath -u "$JAVA17_PATH")" | |
| fi | |
| cat > .envrc << EOF | |
| # Environment configuration for Java 9 Jigsaw Examples | |
| # Auto-generated by GitHub Actions | |
| # Path to JDK 17 or later (required for example_gradle-project with Gradle 9.x) | |
| export JAVA17_HOME=$JAVA17_PATH | |
| # Path to JDK 11 (required for most examples, JDK 17 is also fine) | |
| export JAVA_HOME=$JAVA11_PATH | |
| # Path to JDK 8 (only needed for example_compile-target-jdk8) | |
| export JAVA8_HOME=$JAVA8_PATH | |
| # Add Java to PATH to ensure it is the first Java version found by any shell execution | |
| export PATH="\$JAVA_HOME/bin:\$PATH" | |
| EOF | |
| echo "=== Created .envrc file ===" | |
| cat .envrc | |
| - name: Verify Java setup | |
| shell: bash | |
| run: | | |
| set -eu | |
| source .envrc | |
| echo "=== Verifying JDK 8 ===" | |
| PATH="$JAVA8_HOME/bin:$PATH" | |
| java -version | |
| echo "✓ JDK 8 is available at: $JAVA8_HOME" | |
| echo "" | |
| echo "=== Verifying JDK 11 ===" | |
| PATH="$JAVA_HOME/bin:$PATH" | |
| java -version | |
| echo "✓ JDK 11 is available at: $JAVA_HOME" | |
| echo "" | |
| echo "=== Verifying JDK 17 ===" | |
| PATH="$JAVA17_HOME/bin:$PATH" | |
| java -version | |
| echo "✓ JDK 17 is available at: $JAVA17_HOME" | |
| - name: Compile all Samples | |
| shell: bash | |
| run: | | |
| source .envrc | |
| cd jigsaw-examples | |
| ./allcompile.sh | |
| - name: Run all Samples | |
| shell: bash | |
| run: | | |
| source .envrc | |
| cd jigsaw-examples | |
| ./allrun.sh | |
| - name: Verify all Samples | |
| shell: bash | |
| run: | | |
| source .envrc | |
| cd jigsaw-examples | |
| ./allverify.sh --only | |
| - name: Collect failure information | |
| if: failure() | |
| shell: bash | |
| run: | | |
| echo "Environment:" | |
| env | sort | |
| echo "=== Listing contents of RUNNER_TOOL_CACHE ===" | |
| if test "$(uname)" == "Windows_NT"; then | |
| ls -l "$RUNNER_TOOL_CACHE" "$RUNNER_TOOL_CACHE\\*" "$RUNNER_TOOL_CACHE\\Java*\\*" | |
| else | |
| ls -l "$RUNNER_TOOL_CACHE" "$RUNNER_TOOL_CACHE/*" "$RUNNER_TOOL_CACHE/Java*/*" | |
| fi | |
| echo | |
| - name: Upload run results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: run-results-legacy-${{ matrix.os }} | |
| path: jigsaw-examples/*/run-result | |
| if-no-files-found: ignore | |
| build-m4: | |
| name: Build (m4) on ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| needs: shellcheck | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| steps: | |
| - name: Disable CRLF conversion | |
| run: git config --global core.autocrlf false | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 11 | |
| id: setup-jdk11 | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '11.0.28' | |
| - name: Set up JDK 17 | |
| id: setup-jdk17 | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| - name: Set up Maven 4 | |
| uses: stCarolas/setup-maven@v5 | |
| with: | |
| maven-version: '4.0.0-rc-4' | |
| - name: Create .envrc with Java and Maven paths | |
| shell: bash | |
| env: | |
| JAVA11_PATH: ${{ steps.setup-jdk11.outputs.path }} | |
| JAVA17_PATH: ${{ steps.setup-jdk17.outputs.path }} | |
| run: | | |
| # Detect Maven home | |
| if command -v mvn > /dev/null; then | |
| MVN_PATH="$(command -v mvn)" | |
| # Resolve symlinks | |
| if [[ "$RUNNER_OS" == "Linux" ]] || [[ "$RUNNER_OS" == "macOS" ]]; then | |
| MVN_PATH="$(readlink -f "$MVN_PATH" 2>/dev/null || realpath "$MVN_PATH" 2>/dev/null || echo "$MVN_PATH")" | |
| fi | |
| # Maven home is two directories up from the mvn binary | |
| MAVEN4_PATH="$(dirname "$(dirname "$MVN_PATH")")" | |
| else | |
| echo "ERROR: Maven not found in PATH" | |
| exit 1 | |
| fi | |
| # Convert Windows paths to Unix paths if on Windows | |
| if [[ "$RUNNER_OS" == "Windows" ]]; then | |
| JAVA11_PATH="$(cygpath -u "$JAVA11_PATH")" | |
| JAVA17_PATH="$(cygpath -u "$JAVA17_PATH")" | |
| MAVEN4_PATH="$(cygpath -u "$MAVEN4_PATH")" | |
| fi | |
| cat > .envrc << EOF | |
| # Environment configuration for Java 9 Jigsaw Examples (Maven 4 builds) | |
| # Auto-generated by GitHub Actions | |
| # Path to JDK 17 (default for Maven 4 builds) | |
| export JAVA17_HOME=$JAVA17_PATH | |
| # Path to JDK 17 is the default JAVA_HOME for Maven 4 | |
| export JAVA_HOME=$JAVA17_PATH | |
| # Path to JDK 11 (for compatibility with examples that need it) | |
| export JAVA11_HOME=$JAVA11_PATH | |
| # Path to Maven 4 (required for m4 builds) | |
| export M4_HOME=$MAVEN4_PATH | |
| # Add Java to PATH | |
| export PATH="\$JAVA_HOME/bin:\$PATH" | |
| EOF | |
| echo "=== Created .envrc file ===" | |
| cat .envrc | |
| - name: Verify Java and Maven setup | |
| shell: bash | |
| run: | | |
| set -eu | |
| source .envrc | |
| echo "=== Verifying JDK 17 (default) ===" | |
| PATH="$JAVA_HOME/bin:$PATH" | |
| java -version | |
| echo "✓ JDK 17 is available at: $JAVA_HOME" | |
| echo "✓ JDK 17 is also at: $JAVA17_HOME" | |
| echo "" | |
| echo "=== Verifying JDK 11 (compatibility) ===" | |
| PATH="$JAVA11_HOME/bin:$PATH" | |
| java -version | |
| echo "✓ JDK 11 is available at: $JAVA11_HOME" | |
| echo "" | |
| echo "=== Verifying Maven 4 ===" | |
| mvn --version | |
| echo "✓ Maven 4 is available at: $M4_HOME" | |
| - name: Compile all m4 Samples | |
| shell: bash | |
| run: | | |
| source .envrc | |
| cd jigsaw-examples | |
| ./allcompile.sh m4 | |
| - name: Run all m4 Samples | |
| shell: bash | |
| run: | | |
| source .envrc | |
| cd jigsaw-examples | |
| ./allrun.sh m4 | |
| - name: Verify all m4 Samples | |
| shell: bash | |
| run: | | |
| source .envrc | |
| cd jigsaw-examples | |
| ./allverify.sh m4 --only | |
| - name: Collect failure information | |
| if: failure() | |
| shell: bash | |
| run: | | |
| echo "Environment:" | |
| env | sort | |
| echo "=== Listing contents of RUNNER_TOOL_CACHE ===" | |
| if test "$(uname)" == "Windows_NT"; then | |
| ls -l "$RUNNER_TOOL_CACHE" "$RUNNER_TOOL_CACHE\\*" "$RUNNER_TOOL_CACHE\\Java*\\*" | |
| else | |
| ls -l "$RUNNER_TOOL_CACHE" "$RUNNER_TOOL_CACHE/*" "$RUNNER_TOOL_CACHE/Java*/*" | |
| fi | |
| echo | |
| - name: Upload run results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: run-results-m4-${{ matrix.os }} | |
| path: jigsaw-examples/*/m4/run-result | |
| if-no-files-found: ignore | |
| docs: | |
| name: Generate and Deploy Documentation | |
| runs-on: ubuntu-latest | |
| needs: [build-legacy, build-m4] | |
| if: "!cancelled()" | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| pages: write | |
| id-token: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| - name: Download Linux legacy run results for documentation | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: run-results-legacy-ubuntu-latest | |
| path: jigsaw-examples | |
| continue-on-error: true | |
| - name: Download Linux m4 run results for documentation | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: run-results-m4-ubuntu-latest | |
| path: jigsaw-examples | |
| continue-on-error: true | |
| - name: Generate documentation | |
| run: ./mvnw verify | |
| - name: Create index.html from README.html | |
| run: cp target/generated-docs/README.html target/generated-docs/index.html | |
| - name: Upload documentation artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: generated-docs | |
| path: target/generated-docs | |
| retention-days: 30 | |
| - name: Deploy to Netlify (Preview) | |
| if: github.event_name == 'pull_request' | |
| uses: nwtgck/actions-netlify@v3 | |
| with: | |
| publish-dir: './target/generated-docs' | |
| production-deploy: false | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| deploy-message: "Deploy from GitHub Actions - PR #${{ github.event.pull_request.number }}" | |
| enable-pull-request-comment: true | |
| enable-commit-comment: false | |
| overwrites-pull-request-comment: true | |
| env: | |
| NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
| NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | |
| - name: Deploy to Netlify (Branch Preview) | |
| if: github.event_name == 'push' && github.ref != 'refs/heads/main' | |
| uses: nwtgck/actions-netlify@v3 | |
| with: | |
| publish-dir: './target/generated-docs' | |
| production-deploy: false | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| deploy-message: "Deploy from GitHub Actions - branch ${{ github.ref_name }}" | |
| alias: ${{ github.ref_name }} | |
| env: | |
| NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
| NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | |
| - name: Upload to GitHub Pages | |
| if: github.event_name == 'push' | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: ./target/generated-docs | |
| - name: Deploy to GitHub Pages | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| uses: actions/deploy-pages@v4 | |
| id: deployment |