Skip to content

Commit 0710eec

Browse files
committed
Add spotless autofix for PRs
1 parent 05a4eac commit 0710eec

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
run: gh pr checkout ${{ github.event.pull_request.number }}
59+
60+
- name: Download patch
61+
uses: actions/download-artifact@v4
62+
with:
63+
name: patch
64+
65+
- name: Use CLA approved github bot
66+
# IMPORTANT do not call the .github/scripts/use-cla-approved-bot.sh
67+
# since that script could have been compromised in the PR branch
68+
run: |
69+
git config user.name otelbot
70+
git config user.email [email protected]
71+
72+
- uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6
73+
id: otelbot-token
74+
with:
75+
app-id: ${{ vars.OTELBOT_APP_ID }}
76+
private-key: ${{ secrets.OTELBOT_PRIVATE_KEY }}
77+
78+
- name: Apply patch and push
79+
env:
80+
# not using secrets.GITHUB_TOKEN since pushes from that token do not run workflows
81+
GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}
82+
run: |
83+
git apply patch
84+
git commit -a -m "./gradlew spotlessApply"
85+
git push
86+
87+
- if: success()
88+
env:
89+
GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}
90+
run: |
91+
gh pr comment $PR_NUM --body "✅ \`fix:spotless\` applied successfully"
92+
93+
- if: failure()
94+
env:
95+
GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}
96+
run: |
97+
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)