-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (88 loc) · 3.32 KB
/
spotless.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: Spotless Formatting
on:
push:
paths:
- "**/*.kt"
- "**/*.kts"
- "**/*.yml"
- "**/*.yaml"
pull_request:
branches: ["main"]
paths:
- "**/*.kt"
- "**/*.kts"
- "**/*.yml"
- "**/*.yaml"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: write
pull-requests: write
jobs:
spotless:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "zulu"
cache: "gradle"
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: ${{ github.ref != 'refs/heads/main' }}
- name: Make Gradle wrapper executable
run: chmod +x ./gradlew
- name: Run Spotless Check
id: check
continue-on-error: true
run: |
OUTPUT=$(./gradlew spotlessCheck --parallel --no-daemon 2>&1)
echo "::set-output name=output::$OUTPUT"
- name: Comment on PR
if: github.event_name == 'pull_request' && steps.check.outcome == 'failure'
uses: actions/github-script@v7
with:
script: |
const output = process.env.SPOTLESS_OUTPUT;
const comment = `### ❌ Spotless Formatting — Check Failed
Your pull request includes code that does not comply with the project's formatting standards. To resolve this issue, please follow the steps below:
1. Execute the following command in your local repository to automatically apply the correct formatting:
\`\`\`bash
./gradlew spotlessApply
\`\`\`
2. After running the command, review the updated files to ensure all changes are expected.
3. Stage the updated files, commit them with an appropriate message, and push the changes to your branch.
---
_This is an automated message generated by the [Spotless code formatting check system](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/blob/main/.github/workflows/spotless.yml)._
<details>
<summary>Detailed Output</summary>
\`\`\`
${output}
\`\`\`
</details>`;
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
env:
SPOTLESS_OUTPUT: ${{ steps.check.outputs.output }}
- name: Run Spotless Apply
if: steps.check.outcome == 'failure'
run: ./gradlew spotlessApply --parallel --no-daemon
- name: Commit and push changes
if: steps.check.outcome == 'failure' && github.event_name != 'pull_request'
run: |
git config --local user.name 'github-actions[bot]'
git config --local user.email 'github-actions[bot]@users.noreply.github.com'
git add -A
git diff --quiet && git diff --staged --quiet || (git commit -m "style: apply spotless formatting [skip ci]" && git push)