diff --git a/.github/workflows/java.yml b/.github/workflows/java.yml index 7f636d5b1..2ee957633 100644 --- a/.github/workflows/java.yml +++ b/.github/workflows/java.yml @@ -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