Skip to content

Commit 000f1fe

Browse files
authored
Merge pull request #62 from team4099/auto-spotless
auto-spotless scirpt
2 parents 4ed2f59 + 8bc5054 commit 000f1fe

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

.github/workflows/spotless.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: spotless.yml
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Build Project"]
6+
types:
7+
- completed
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
spotless:
15+
if: >
16+
github.event.workflow_run.conclusion == 'failure' &&
17+
github.event.workflow_run.actor.login != 'github-actions[bot]'
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout PR branch
22+
uses: actions/checkout@v4
23+
with:
24+
repository: ${{ github.event.workflow_run.head_repository.full_name }}
25+
ref: ${{ github.event.workflow_run.head_branch }}
26+
token: ${{ secrets.GITHUB_TOKEN }}
27+
28+
- name: Make gradlew executable
29+
run: chmod +x ./gradlew
30+
31+
- name: Check if Spotless is the failure cause
32+
id: spotless_check
33+
run: |
34+
if ./gradlew spotlessKotlinCheck; then
35+
echo "needs_fix=false" >> $GITHUB_OUTPUT
36+
else
37+
echo "needs_fix=true" >> $GITHUB_OUTPUT
38+
fi
39+
40+
- name: Run Spotless Apply
41+
if: steps.spotless_check.outputs.needs_fix == 'true'
42+
run: ./gradlew spotlessApply
43+
44+
- name: Commit changes if needed
45+
if: steps.spotless_check.outputs.needs_fix == 'true'
46+
run: |
47+
git config user.name "github-actions[bot]"
48+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
49+
git add .
50+
git diff --cached --quiet || git commit -m "chore: auto-fix Spotless formatting"
51+
52+
- name: Push changes
53+
if: steps.spotless_check.outputs.needs_fix == 'true'
54+
run: git push

0 commit comments

Comments
 (0)