From 5986c0d253ee1d2812eae3fbf04b76e2e77cc353 Mon Sep 17 00:00:00 2001 From: josealonso Date: Sat, 28 Dec 2024 02:11:48 +0100 Subject: [PATCH 1/7] The workflow is triggered only when Java files are changed. --- .github/workflows/java.yml | 27 ++++++++++++++++++++------- exercises/build.gradle | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/.github/workflows/java.yml b/.github/workflows/java.yml index 7f636d5b1..99ae79530 100644 --- a/.github/workflows/java.yml +++ b/.github/workflows/java.yml @@ -11,19 +11,32 @@ on: workflow_dispatch: jobs: - build: - name: Check if tests compile cleanly with starter sources + check-java-exercises: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - - name: Set up JDK 1.17 - uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b + - uses: actions/setup-java@v3 with: java-version: 17 distribution: "temurin" - - name: Check if tests compile cleanly with starter sources - run: ./gradlew compileStarterTestJava --continue - working-directory: 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 diff --git a/exercises/build.gradle b/exercises/build.gradle index 734815214..2ea14f5c3 100644 --- a/exercises/build.gradle +++ b/exercises/build.gradle @@ -12,6 +12,24 @@ subprojects { apply plugin: "checkstyle" + task.register('runOnGitHub') { + group = 'Verification' + description = 'Run checks for GitHub Actions' + + dependsOn 'checkstyleMain' + dependsOn 'checkstyleTest' + dependsOn 'checkstyleStarterSource' + dependsOn 'checkstyleStarterTest' + + // Define the task actions + doLast { + tasks.checkstyleMain.execute() + tasks.checkstyleTest.execute() + tasks.checkstyleStarterSource.execute() + tasks.checkstyleStarterTest.execute() + } + } + // Add a task that copies test source files into a build directory. // All @Disabled annotations are removed during this copying, // so that when we run the copied tests, none are skipped and all should execute. From 88db07b13eaff3892ce160579ed9eea997462528 Mon Sep 17 00:00:00 2001 From: josealonso Date: Sat, 28 Dec 2024 19:36:22 +0100 Subject: [PATCH 2/7] Validate the Gradle wrapper. --- .github/workflows/java.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/java.yml b/.github/workflows/java.yml index 99ae79530..1633bba51 100644 --- a/.github/workflows/java.yml +++ b/.github/workflows/java.yml @@ -15,6 +15,7 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + - uses: actions/wrapper-validation-action@v1 - uses: actions/setup-java@v3 with: java-version: 17 From dcac31ddaf7b56bf84ad94563a4585f00eab64b1 Mon Sep 17 00:00:00 2001 From: josealonso Date: Sat, 28 Dec 2024 21:07:51 +0100 Subject: [PATCH 3/7] Use the checkout action, version 4. More info in https://github.com/actions/checkout --- .github/workflows/java.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/java.yml b/.github/workflows/java.yml index 1633bba51..cee0e5099 100644 --- a/.github/workflows/java.yml +++ b/.github/workflows/java.yml @@ -14,7 +14,11 @@ jobs: check-java-exercises: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + - name: Checkout the latest commit on the main branch + uses: actions/checkout@v4 + with: + ref: main + - uses: actions/wrapper-validation-action@v1 - uses: actions/setup-java@v3 with: From df09d268546a09e6dbe1e395520e8af5a6011ed2 Mon Sep 17 00:00:00 2001 From: josealonso Date: Sat, 28 Dec 2024 23:01:42 +0100 Subject: [PATCH 4/7] Use latest version of wrapper-validation-action. More info on https://github.com/gradle/wrapper-validation-action --- .github/workflows/java.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/java.yml b/.github/workflows/java.yml index cee0e5099..dde4cf846 100644 --- a/.github/workflows/java.yml +++ b/.github/workflows/java.yml @@ -19,11 +19,16 @@ jobs: with: ref: main - - uses: actions/wrapper-validation-action@v1 - - uses: actions/setup-java@v3 + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 with: java-version: 17 distribution: "temurin" + + - name: Run gradle tasks only for modified files/exercises - uses: dorny/paths-filter@v3 id: changes with: From 921f6aa20659361cd246490cbc81f01a3b157071 Mon Sep 17 00:00:00 2001 From: josealonso Date: Sat, 28 Dec 2024 23:09:13 +0100 Subject: [PATCH 5/7] Fix syntax error. --- .github/workflows/java.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/java.yml b/.github/workflows/java.yml index dde4cf846..981ca2048 100644 --- a/.github/workflows/java.yml +++ b/.github/workflows/java.yml @@ -29,7 +29,7 @@ jobs: distribution: "temurin" - name: Run gradle tasks only for modified files/exercises - - uses: dorny/paths-filter@v3 + uses: dorny/paths-filter@v3 id: changes with: filters: | From 0a449ef0d7f6140a6d0ce8ca5289896fe4d4565b Mon Sep 17 00:00:00 2001 From: josealonso Date: Sat, 28 Dec 2024 23:30:25 +0100 Subject: [PATCH 6/7] Use latest version of the setup-java action. More info on https://github.com/actions/setup-java --- .github/workflows/java.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/java.yml b/.github/workflows/java.yml index 981ca2048..2ee957633 100644 --- a/.github/workflows/java.yml +++ b/.github/workflows/java.yml @@ -11,7 +11,7 @@ on: workflow_dispatch: jobs: - check-java-exercises: + build: runs-on: ubuntu-22.04 steps: - name: Checkout the latest commit on the main branch @@ -23,7 +23,7 @@ jobs: uses: gradle/wrapper-validation-action@v3 - name: Set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: 17 distribution: "temurin" From cc1c95fede8af5d7e0c2a88bcb89efad50f2e909 Mon Sep 17 00:00:00 2001 From: josealonso Date: Sun, 29 Dec 2024 00:57:47 +0100 Subject: [PATCH 7/7] Revert all the changes to build.gradle. --- exercises/build.gradle | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/exercises/build.gradle b/exercises/build.gradle index 2ea14f5c3..734815214 100644 --- a/exercises/build.gradle +++ b/exercises/build.gradle @@ -12,24 +12,6 @@ subprojects { apply plugin: "checkstyle" - task.register('runOnGitHub') { - group = 'Verification' - description = 'Run checks for GitHub Actions' - - dependsOn 'checkstyleMain' - dependsOn 'checkstyleTest' - dependsOn 'checkstyleStarterSource' - dependsOn 'checkstyleStarterTest' - - // Define the task actions - doLast { - tasks.checkstyleMain.execute() - tasks.checkstyleTest.execute() - tasks.checkstyleStarterSource.execute() - tasks.checkstyleStarterTest.execute() - } - } - // Add a task that copies test source files into a build directory. // All @Disabled annotations are removed during this copying, // so that when we run the copied tests, none are skipped and all should execute.