22name : Java Formatting
33
44on :
5- push :
6- branches :
7- - master
8- paths : ['src/main/java/**', 'src/test/**']
95 pull_request :
106 paths : ['src/main/java/**', 'src/test/**']
117
128concurrency :
13- group : format-${{ github.head_ref || github.ref }}
9+ group : format-${{ inputs.target_branch || github.ref }}
1410 cancel-in-progress : true
1511
1612jobs :
@@ -24,19 +20,29 @@ jobs:
2420
2521 steps :
2622 - name : Checkout Repository
27- uses : actions/checkout@v4
23+ uses : actions/checkout@v6
2824 with :
29- ref : ${{ github.head_ref }}
25+ ref : ${{ inputs.target_branch || github.ref }}
3026
3127 - name : Setup Build
3228 uses : ./.github/actions/build_setup
3329
30+ - name : Check if PR is from a fork
31+ id : fork-check
32+ run : |
33+ if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then
34+ echo "is_fork=true" >> $GITHUB_OUTPUT
35+ else
36+ echo "is_fork=false" >> $GITHUB_OUTPUT
37+ fi
38+ shell : bash
39+
3440 - name : Run Spotless Formatting Check with Gradle
3541 id : build
36- run : ./gradlew --info spotlessCheck
42+ run : ./gradlew --info --stacktrace spotlessCheck
3743
3844 - name : Attempt to make a PR fixing spotless errors
39- if : failure() && steps.build.conclusion == 'failure'
45+ if : failure() && steps.build.conclusion == 'failure' && steps.fork-check.outputs.is_fork == 'false'
4046 run : |
4147 git reset --hard
4248 git checkout "${PR_BRANCH}"
5460 --body "Automatic spotless apply to fix formatting errors, applies to PR #${PR_NUMBER}" \
5561 2>&1 | tee pr-message.log || true
5662 gh pr comment "${PR_BRANCH}" -F pr-message.log || true
57- shell : bash # ensures set -eo pipefail
63+ shell : bash
5864 env :
5965 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
6066 PR_BRANCH : ${{ github.event.pull_request.head.ref }}
6167 PR_NUMBER : ${{ github.event.pull_request.number }}
6268 FIXED_BRANCH : ${{ github.head_ref }}-spotless-fixes
69+
70+ - name : Comment to PR if from fork and formatting failed
71+ if : failure() && steps.build.conclusion == 'failure' && steps.fork-check.outputs.is_fork == 'true'
72+ run : |
73+ gh pr comment ${{ github.event.pull_request.number }} --body "I can't get automatic fixes by spotless in CI. Please run '. /gradlew spotlessApply' and push again."
74+ env :
75+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments