Skip to content

Improve shell script quality and fix review issues #96

Improve shell script quality and fix review issues

Improve shell script quality and fix review issues #96

Workflow file for this run

name: Build and Test Java 9 Jigsaw Examples
on:
push:
pull_request:
workflow_dispatch:
jobs:
build:
name: Build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
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: Install shellcheck (Ubuntu)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y shellcheck
- name: Install shellcheck (macOS)
if: runner.os == 'macOS'
run: brew install shellcheck
- name: Install shellcheck (Windows)
if: runner.os == 'Windows'
run: choco install shellcheck --no-progress
- name: Run shellcheck on shell scripts
shell: bash
run: cd jigsaw-examples && shellcheck -ax all*.sh
- 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-${{ matrix.os }}
path: jigsaw-examples/*/run-result
if-no-files-found: ignore
docs:
name: Generate and Deploy Documentation
runs-on: ubuntu-latest
needs: build
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 run results for documentation
uses: actions/download-artifact@v4
with:
name: run-results-ubuntu-latest
path: jigsaw-examples
- 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