Skip to content

Commit c9d8a63

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

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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-patch:
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 [email protected]
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+
GH_TOKEN: ${{ github.token }}
95+
run: |
96+
git apply patch
97+
git commit -a -m "./gradlew spotlessApply"
98+
git push
99+
100+
- if: success()
101+
env:
102+
# GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}
103+
GH_TOKEN: ${{ github.token }}
104+
run: |
105+
gh pr comment $PR_NUM --body "✅ \`fix:spotless\` applied successfully"
106+
107+
- if: failure()
108+
env:
109+
# GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}
110+
GH_TOKEN: ${{ github.token }}
111+
run: |
112+
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)