Skip to content

Commit 29523ad

Browse files
committed
Add spotless autofix for PRs
1 parent 05a4eac commit 29523ad

File tree

1 file changed

+99
-0
lines changed

1 file changed

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