-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (125 loc) · 4.54 KB
/
formatting-check.yaml
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
128
129
130
131
name: Formatting check
on:
pull_request_target:
types: [opened, synchronize, reopened, edited]
permissions:
contents: read
issues: read
checks: write
pull-requests: write
concurrency:
group: format-check-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
env:
JAVA_VERSION: 17
jobs:
checkstyle:
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- run: echo "Concurrency Group = format-check-${{ github.head_ref || github.ref_name }}"
- uses: tibdex/github-app-token@v1
id: generate-token
with:
app_id: ${{ secrets.QUARKUS_HILLA_BOT_ID }}
private_key: ${{ secrets.QUARKUS_HILLA_BOT_PRIVATE_KEY }}
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Java
uses: actions/setup-java@v3
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: 'temurin'
cache: maven
- name: Check
id: spotlessCheck
run: |
set -x -e -o pipefail
mvn -V -e -B -ntp -Pall-modules spotless:check
- name: Prepare failure message
if: ${{ failure() && steps.spotlessCheck.conclusion == 'failure' }}
run: |
set -x -e -o pipefail
mvn -V -e -B -ntp -Pall-modules spotless:apply
git diff --output=/tmp/full-diff.txt
git diff --name-only --output=/tmp/unformatted.txt
export _UNFORMATTED_COUNT=$(cat /tmp/unformatted.txt | wc -l)
export _UNFORMATTED_FILES=$(cat /tmp/unformatted.txt)
export _FULL_DIFF=$(cat /tmp/full-diff.txt)
envsubst < ./.github/scripts/format-check-report.tpl.md > /tmp/message
- name: Prepare success message
if: ${{ success() }}
run: |
set -x -e -o pipefail
echo "# Format Checker Report" >> /tmp/message
echo "" >> /tmp/message
echo "All files are correctly formatted" >> /tmp/message
- name: Comment PR
if: ${{ always() }}
uses: thollander/actions-comment-pull-request@v2
with:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
filePath: /tmp/message
comment_tag: formatting-check
- name: Add format required label to PR
if: ${{ failure() && steps.spotlessCheck.conclusion == 'failure' }}
uses: actions/github-script@v6
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const { owner, repo } = context.repo;
const prNumber = context.payload.pull_request.number;
// Remove the label if it exists
const existingLabels = await github.rest.issues.listLabelsOnIssue({
owner,
repo,
issue_number: prNumber,
}).then(resp => resp.data.map(label => label.name));
if (existingLabels.includes("format:checked")) {
await github.rest.issues.removeLabel({
owner,
repo,
issue_number: prNumber,
name: "format:checked",
});
}
if (!existingLabels.includes("format:required")) {
await github.rest.issues.addLabels({
owner,
repo,
issue_number: prNumber,
labels: ['format:required'],
});
}
- name: Add format checked label to PR
if: ${{ success() }}
uses: actions/github-script@v6
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const { owner, repo } = context.repo;
const prNumber = context.payload.pull_request.number;
// Remove the label if it exists
const existingLabels = await github.rest.issues.listLabelsOnIssue({
owner,
repo,
issue_number: prNumber,
}).then(resp => resp.data.map(label => label.name));
if (existingLabels.includes("format:required")) {
await github.rest.issues.removeLabel({
owner,
repo,
issue_number: prNumber,
name: "format:required",
});
}
if (!existingLabels.includes("format:checked")) {
await github.rest.issues.addLabels({
owner,
repo,
issue_number: prNumber,
labels: ['format:checked'],
});
}