Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion .github/workflows/java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ on:
workflow_dispatch:

jobs:
build:
build-all:
name: Check if tests compile cleanly with starter sources
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
Expand All @@ -25,6 +26,22 @@ jobs:
run: ./gradlew compileStarterTestJava --continue
working-directory: exercises

build-changed:
name: Check if changed exercise tests compile cleanly with starter sources
if: github.event_name == 'pull_request'
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
fetch-depth: 0
- name: Set up JDK 21
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654
with:
java-version: 21
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use Java 25 (the test runner uses Java 25).

distribution: "temurin"
- name: Check if changed exercise tests compile cleanly
run: bin/build-changed-exercise

lint:
name: Lint Java files using Checkstyle
runs-on: ubuntu-24.04
Expand Down
54 changes: 54 additions & 0 deletions bin/build-changed-exercise
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
set -eo pipefail

# Determine the base branch of the PR
BASE_BRANCH=${GITHUB_BASE_REF:-main}

# Fetch full history for proper diff
git fetch origin "$BASE_BRANCH"

# Compute merge base
MERGE_BASE=$(git merge-base HEAD origin/"$BASE_BRANCH")

# Get changed files relative to merge base
changed_files=$(git diff --name-only "$MERGE_BASE" HEAD)

# If any Gradle build file changed, run the full suite and exit
if echo "$changed_files" | grep -qE '\.(gradle|gradlew|bat)$|settings\.gradle'; then
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also need to also check the Gradle wrapper files (gradle-wrapper.jar and gradle-wrapper.properties)

Copy link
Copy Markdown
Member Author

@jagdish-15 jagdish-15 May 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, should we also add the following in the yml file:

  pull_request:
    paths:
      - "**/*.java"
      - "**/*.gradle"
      - "**/gradle-wrapper.properties"
      - "**/gradle-wrapper.jar"
      - "**/gradlew"
      - "**/gradlew.bat"

Currently it's:

  pull_request:
    paths:
      - "**/*.java"
      - "**/*.gradle"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially, I just added this line since that is what we did for the test-changed task

echo "Gradle build files changed, running full build suite..."
cd exercises && ./gradlew compileStarterTestJava --continue
exit 0
fi

# Extract unique exercise directories
changed_exercises=$(echo "$changed_files" | \
grep -E '^exercises/(practice|concept)/[^/]+/.+\.java$' | \
cut -d/ -f1-3 | sort -u || true)

if [ -z "$changed_exercises" ]; then
echo "No relevant exercises changed, skipping compile checks."
exit 0
fi

# Print exercises
echo "Changed exercises detected:"
echo "$changed_exercises"
echo "----------------------------------------"

# Run build compile checks
exit_code=0
for dir in $changed_exercises; do
slug=$(basename "$dir")

echo "========================================"
echo "=== Running compileStarterTestJava for $slug ==="
echo "========================================"

if [[ $dir == exercises/practice/* ]]; then
./exercises/gradlew -p exercises ":practice:$slug:compileStarterTestJava" || exit_code=1
elif [[ $dir == exercises/concept/* ]]; then
./exercises/gradlew -p exercises ":concept:$slug:compileStarterTestJava" || exit_code=1
fi
done

exit $exit_code