File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments