Skip to content

Commit 5986c0d

Browse files
committed
The workflow is triggered only when Java files are changed.
1 parent 4cf2236 commit 5986c0d

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

.github/workflows/java.yml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,32 @@ on:
1111
workflow_dispatch:
1212

1313
jobs:
14-
build:
15-
name: Check if tests compile cleanly with starter sources
14+
check-java-exercises:
1615
runs-on: ubuntu-22.04
1716
steps:
1817
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
19-
- name: Set up JDK 1.17
20-
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b
18+
- uses: actions/setup-java@v3
2119
with:
2220
java-version: 17
2321
distribution: "temurin"
24-
- name: Check if tests compile cleanly with starter sources
25-
run: ./gradlew compileStarterTestJava --continue
26-
working-directory: exercises
22+
- uses: dorny/paths-filter@v3
23+
id: changes
24+
with:
25+
filters: |
26+
java:
27+
- 'exercises/**/*.java'
28+
29+
- name: Check if modified tests compile cleanly with starter sources
30+
if: steps.changes.outputs.java == 'true'
31+
run: |
32+
for file in ${{ steps.changes.outputs.java_files }}; do
33+
# Extract the exercise name from the file path
34+
exercise=$(echo "$file" | sed -E 's/exercises\/(.*)\/.*\.java/\1/')
35+
# Compile, check and run tests for the modified exercise
36+
./gradlew ":${exercise}:compileStarterTestJava" --continue
37+
./gradlew ":${exercise}:check" --exclude-task test --continue
38+
./gradlew ":${exercise}:test"
39+
done
2740
2841
lint:
2942
name: Lint Java files using Checkstyle

exercises/build.gradle

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ subprojects {
1212

1313
apply plugin: "checkstyle"
1414

15+
task.register('runOnGitHub') {
16+
group = 'Verification'
17+
description = 'Run checks for GitHub Actions'
18+
19+
dependsOn 'checkstyleMain'
20+
dependsOn 'checkstyleTest'
21+
dependsOn 'checkstyleStarterSource'
22+
dependsOn 'checkstyleStarterTest'
23+
24+
// Define the task actions
25+
doLast {
26+
tasks.checkstyleMain.execute()
27+
tasks.checkstyleTest.execute()
28+
tasks.checkstyleStarterSource.execute()
29+
tasks.checkstyleStarterTest.execute()
30+
}
31+
}
32+
1533
// Add a task that copies test source files into a build directory.
1634
// All @Disabled annotations are removed during this copying,
1735
// so that when we run the copied tests, none are skipped and all should execute.

0 commit comments

Comments
 (0)