Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the Github Actions workflow #2882

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
37 changes: 30 additions & 7 deletions .github/workflows/java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,41 @@ on:

jobs:
build:
name: Check if tests compile cleanly with starter sources
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Set up JDK 1.17
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b
- name: Checkout the latest commit on the main branch
uses: actions/checkout@v4
with:
ref: main

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v3

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: "temurin"
- name: Check if tests compile cleanly with starter sources
run: ./gradlew compileStarterTestJava --continue
working-directory: exercises

- name: Run gradle tasks only for modified files/exercises
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
Expand Down