Skip to content

Commit ca43b4b

Browse files
committed
Add comment-driven fix on PRs for spotless
1 parent f266e6f commit ca43b4b

1 file changed

Lines changed: 109 additions & 0 deletions

File tree

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: Auto spotless
2+
on:
3+
pull_request_target:
4+
types:
5+
- opened
6+
- synchronize
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
10+
cancel-in-progress: true
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
check:
17+
runs-on: ubuntu-latest
18+
outputs:
19+
patch-created: ${{ steps.create-patch-file.outputs.nonempty }}
20+
steps:
21+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
22+
23+
- name: Check out PR branch
24+
env:
25+
GH_TOKEN: ${{ github.token }}
26+
run: gh pr checkout ${{ github.event.pull_request.number }}
27+
28+
- name: Set up JDK for running Gradle
29+
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
30+
with:
31+
distribution: temurin
32+
java-version: 17
33+
34+
- name: Setup Gradle
35+
uses: gradle/actions/setup-gradle@06832c7b30a0129d7fb559bcc6e43d26f6374244 # v4.3.1
36+
with:
37+
cache-read-only: true
38+
39+
- name: Spotless
40+
run: ./gradlew spotlessApply
41+
42+
- id: create-patch-file
43+
name: Create patch file
44+
run: |
45+
git diff > patch
46+
if [ -s patch ]; then
47+
echo "nonempty=true" >> "$GITHUB_OUTPUT"
48+
fi
49+
50+
- name: Upload patch file
51+
if: steps.create-patch-file.outputs.nonempty == 'true'
52+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
53+
with:
54+
path: patch
55+
name: patch
56+
57+
apply:
58+
runs-on: ubuntu-latest
59+
needs: check
60+
if: needs.check.outputs.patch-created == 'true'
61+
permissions:
62+
contents: write
63+
pull-requests: write
64+
steps:
65+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
66+
67+
- name: Check out PR branch
68+
env:
69+
GH_TOKEN: ${{ github.token }}
70+
run: gh pr checkout ${{ github.event.pull_request.number }}
71+
72+
- name: Download patch
73+
uses: actions/download-artifact@v4
74+
with:
75+
name: patch
76+
77+
- name: Use CLA approved github bot
78+
# IMPORTANT do not call the .github/scripts/use-cla-approved-bot.sh
79+
# since that script could have been compromised in the PR branch
80+
run: |
81+
git config user.name otelbot
82+
git config user.email 197425009+otelbot@users.noreply.github.com
83+
84+
- uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6
85+
id: otelbot-token
86+
with:
87+
app-id: ${{ vars.OTELBOT_APP_ID }}
88+
private-key: ${{ secrets.OTELBOT_PRIVATE_KEY }}
89+
90+
- name: Apply patch and push
91+
env:
92+
# not using secrets.GITHUB_TOKEN since pushes from that token do not run workflows
93+
GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}
94+
run: |
95+
git apply patch
96+
git commit -a -m "./gradlew spotlessApply"
97+
git push
98+
99+
- if: success()
100+
env:
101+
GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}
102+
run: |
103+
gh pr comment $PR_NUM --body "✅ \`fix:spotless\` applied successfully"
104+
105+
- if: failure()
106+
env:
107+
GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}
108+
run: |
109+
gh pr comment $PR_NUM --body "❌ \`fix:spotless\` failed, see logs: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"

0 commit comments

Comments
 (0)