Skip to content

Commit 275a999

Browse files
committed
Add spotless autofix for PRs
1 parent 05a4eac commit 275a999

File tree

1 file changed

+101
-0
lines changed

1 file changed

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