Skip to content

Commit a68ba0f

Browse files
committed
Add comment-driven fix on PRs for spotless
1 parent a87bb01 commit a68ba0f

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

.github/workflows/fix-spotless.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Fix spotless
2+
on:
3+
issue_comment:
4+
types:
5+
- created
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
create-patch:
12+
runs-on: ubuntu-latest
13+
if: github.event.issue.pull_request && github.event.comment.body == '/fix:spotless'
14+
steps:
15+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
16+
with:
17+
ref: refs/pull/${{ github.event.issue.number }}/head
18+
19+
- name: Free disk space
20+
run: .github/scripts/gha-free-disk-space.sh
21+
22+
- name: Set up JDK for running Gradle
23+
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
24+
with:
25+
distribution: temurin
26+
java-version-file: .java-version
27+
28+
- name: Setup Gradle
29+
uses: gradle/actions/setup-gradle@06832c7b30a0129d7fb559bcc6e43d26f6374244 # v4.3.1
30+
with:
31+
cache-read-only: true
32+
33+
- name: Spotless
34+
run: ./gradlew spotlessApply
35+
36+
- run: git diff > patch
37+
38+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
39+
with:
40+
path: patch
41+
42+
apply-patch:
43+
runs-on: ubuntu-latest
44+
needs: create-patch
45+
permissions:
46+
contents: write
47+
pull-requests: write
48+
steps:
49+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
50+
with:
51+
ref: refs/pull/${{ github.event.issue.number }}/head
52+
53+
- name: Download patch
54+
uses: actions/download-artifact@v4
55+
with:
56+
name: patch
57+
58+
- name: Use CLA approved github bot
59+
run: .github/scripts/use-cla-approved-github-bot.sh
60+
61+
- uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6
62+
id: otelbot-token
63+
with:
64+
app-id: ${{ vars.OTELBOT_APP_ID }}
65+
private-key: ${{ secrets.OTELBOT_PRIVATE_KEY }}
66+
67+
- name: Apply patch and push
68+
run: |
69+
git apply patch
70+
git commit -a -m "./gradlew spotlessApply"
71+
git push
72+
env:
73+
# not using secrets.GITHUB_TOKEN since pushes from that token do not run workflows
74+
GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}
75+
76+
- name: Comment success
77+
if: ${{ !failure() && !cancelled() }}
78+
run: |
79+
gh pr comment $PR_NUM --body "✅ \`fix:spotless\` applied successfully"
80+
env:
81+
GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}
82+
83+
- name: Comment failure
84+
if: ${{ failure() || cancelled() }}
85+
run: |
86+
gh pr comment $PR_NUM --body "❌ \`fix:spotless\` failed, see logs: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
87+
env:
88+
GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}

0 commit comments

Comments
 (0)