-
Notifications
You must be signed in to change notification settings - Fork 216
127 lines (103 loc) · 4.38 KB
/
Copy pathformatter.yml
File metadata and controls
127 lines (103 loc) · 4.38 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
name: Formatter
on:
pull_request:
types: [opened, synchronize, reopened]
# spotless available in 25.x
branches: [main]
merge_group:
# Cancel previous runs if a new one is triggered
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
JAVA_VERSION: '21'
_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
permissions:
contents: read
pull-requests: write
issues: write
jobs:
formatter:
name: Verify Java code format
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- name: Checkout code
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
with:
ref: ${{ env._HEAD_SHA }}
fetch-depth: 0
- name: Set up JDK
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
with:
java-version: "${{ env.JAVA_VERSION }}"
distribution: 'temurin'
cache: 'maven'
- name: Run formatter
id: formatter
run: |
echo "Running formatter..."
mvn -ntp -B -q spotless:apply -P benchmark 2>&1 | grep -v null || true
# Check for modified files
files=$(git status --porcelain | awk '{print $2}')
modified=$(echo "$files" | wc -w | xargs)
echo "modified=$modified" >> $GITHUB_OUTPUT
if [ "$modified" -gt 0 ]; then
echo "Modified files:"
echo "$files"
git diff > formatter-diff.txt
echo "files<<EOF" >> $GITHUB_OUTPUT
echo "$files" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
- name: Upload formatter diff
if: steps.formatter.outputs.modified != '0'
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
with:
name: formatter-diff
path: formatter-diff.txt
retention-days: 30
- name: Find existing comment
if: github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork
uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad # v4.0.0
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: '<!-- tc-formatter -->'
- name: Create or update comment
if: github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork && steps.formatter.outputs.modified != '0'
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body: |
<!-- tc-formatter -->
### Format Checker Report
![BLOCKER][BLOCKER] There are **${{ steps.formatter.outputs.modified }} files** with format errors
[BLOCKER]: https://sonarsource.github.io/sonar-github/severity-blocker.png 'Severity: BLOCKER'
- To see a complete report of formatting issues, download the [differences artifact](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
- To fix the build, please run `mvn spotless:apply` in your branch and commit the changes.
- Optionally you might add the following line in your `.git/hooks/pre-commit` file:
mvn spotless:apply
Here is the list of files with format issues in your PR:
```
${{ steps.formatter.outputs.files }}
```
- name: Delete comment if formatting is correct
if: steps.formatter.outputs.modified == '0' && steps.find-comment.outputs.comment-id != ''
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ steps.find-comment.outputs.comment-id }}
})
- name: Fail if formatting issues exist
if: steps.formatter.outputs.modified != '0'
run: |
echo "::error::There are ${{ steps.formatter.outputs.modified }} files with format errors"
exit 1