Improve the Github Actions workflow #262
Workflow file for this run
This file contains 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: Java | |
on: | |
pull_request: | |
paths: | |
- "**/*.java" | |
- "**/*.gradle" | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
check-java-exercises: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | |
- uses: actions/setup-java@v3 | |
with: | |
java-version: 17 | |
distribution: "temurin" | |
- uses: dorny/paths-filter@v3 | |
id: changes | |
with: | |
filters: | | |
java: | |
- 'exercises/**/*.java' | |
- name: Check if modified tests compile cleanly with starter sources | |
if: steps.changes.outputs.java == 'true' | |
run: | | |
for file in ${{ steps.changes.outputs.java_files }}; do | |
# Extract the exercise name from the file path | |
exercise=$(echo "$file" | sed -E 's/exercises\/(.*)\/.*\.java/\1/') | |
# Compile, check and run tests for the modified exercise | |
./gradlew ":${exercise}:compileStarterTestJava" --continue | |
./gradlew ":${exercise}:check" --exclude-task test --continue | |
./gradlew ":${exercise}:test" | |
done | |
lint: | |
name: Lint Java files using Checkstyle | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | |
- name: Set up JDK 1.17 | |
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b | |
with: | |
java-version: 17 | |
distribution: "temurin" | |
- name: Run checkstyle | |
run: ./gradlew check --exclude-task test --continue | |
working-directory: exercises | |
test: | |
name: Test all exercises using java-test-runner | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | |
- name: Test all exercises using java-test-runner | |
run: bin/test-with-test-runner | |
- name: Archive test results | |
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 | |
with: | |
name: test-results | |
path: exercises/**/build/results.json | |
if: failure() |