forked from checkstyle/checkstyle
-
Notifications
You must be signed in to change notification settings - Fork 0
247 lines (217 loc) · 9.25 KB
/
diff-report.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#####################################################################################
# GitHub Action to generate Checkstyle report.
#
# Workflow starts when:
# 1) issue comment - created
#
# Requirements:
# 1) secrets.AWS_ACCESS_KEY_ID - access key for AWS S3 service user
# 2) secrets.AWS_SECRET_ACCESS_KEY - security access key for AWS S3 service user
#
# If you need to change bucket name or region, change AWS_REGION and AWS_BUCKET_NAME variables.
# For another bucket, you will need to change the secrets.
#####################################################################################
name: Diff-Report
env:
AWS_REGION: us-east-2
AWS_BUCKET_NAME: "checkstyle-diff-reports"
# yamllint disable-line rule:line-length
DEFAULT_PROJECTS_LINK: "https://raw.githubusercontent.com/checkstyle/contribution/master/checkstyle-tester/projects-to-test-on-for-github-action.properties"
USER_LOGIN: ${{ github.event.issue.user.login }}
on:
issue_comment:
types: [ created, edited ]
permissions:
contents: read
pull-requests: write
concurrency:
# run_id is guaranteed to be unique and present
group: ${{ github.run_id }}
cancel-in-progress: false
jobs:
# Parse PR Body, search for links to .properties and .xml files
parse_body:
if: github.event.comment.body == 'GitHub, generate report'
runs-on: ubuntu-latest
outputs:
projects_link: ${{ steps.parse.outputs.projects_link }}
config_link: ${{ steps.parse.outputs.config_link }}
new_module_config_link: ${{ steps.parse.outputs.new_module_config_link }}
patch_config_link: ${{ steps.parse.outputs.patch_config_link }}
report_label: ${{ steps.parse.outputs.report_label }}
branch: ${{ steps.branch.outputs.ref }}
commit_sha: ${{ steps.branch.outputs.commit_sha }}
steps:
- uses: shanegenschaw/[email protected]
name: React with rocket on run
with:
trigger: ','
reaction: rocket
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
- run: 'echo We print it here for this action to work'
if: 'true'
- name: Checkout repository
uses: actions/checkout@v4
- name: Getting PR description
env:
ISSUE_BODY: ${{ github.event.issue.body }}
PULL_REQUEST_URL: ${{ github.event.issue.pull_request.url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p .ci-temp
# convert windows line endings to unix in event text
echo "$ISSUE_BODY" > .ci-temp/windows.txt
tr -d '\15\32' < .ci-temp/windows.txt > .ci-temp/text
curl --fail-with-body -X GET "${PULL_REQUEST_URL}" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token $GITHUB_TOKEN" \
-o .ci-temp/info.json
jq --raw-output .head.ref .ci-temp/info.json > .ci-temp/branch
jq --raw-output .head.sha .ci-temp/info.json > .ci-temp/commit_sha
- name: Parsing content of PR description
id: parse
run: |
./.ci/diff-report.sh parse-pr-description-text
- name: Set branch
id: branch
run: |
./.ci/append-to-github-output.sh "ref" "$(cat .ci-temp/branch)"
# shellcheck disable=SC2002
./.ci/append-to-github-output.sh "commit_sha" "$(cat .ci-temp/commit_sha | cut -c 1-7)"
echo "GITHUB_OUTPUT:"
# need to 'echo' to see output in Github CI
# shellcheck disable=SC2005
echo "$(cat "$GITHUB_OUTPUT")"
make_report:
runs-on: ubuntu-latest
needs: parse_body
if: needs.parse_body.outputs.config_link != ''
|| needs.parse_body.outputs.new_module_config_link != ''
outputs:
message: ${{ steps.out.outputs.message }}
steps:
- name: Download checkstyle
uses: actions/checkout@v4
- name: Download files
env:
NEW_MODULE_CONFIG_LINK: ${{ needs.parse_body.outputs.new_module_config_link }}
DIFF_CONFIG_LINK: ${{ needs.parse_body.outputs.config_link }}
PATCH_CONFIG_LINK: ${{ needs.parse_body.outputs.patch_config_link }}
LINK_FROM_PR: ${{ needs.parse_body.outputs.projects_link }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
./.ci/diff-report.sh download-files
# set main checkstyle repo as an upstream
# Diff report will be generated taking upstream's master branch as a base branch
- name: set upstream
run: |
bash
MAIN_REPO_GIT_URL="https://github.com/checkstyle/checkstyle.git"
git remote add upstream "$MAIN_REPO_GIT_URL"
git fetch upstream
FORK_REPO_GIT_URL="https://github.com/$USER_LOGIN/checkstyle.git"
git remote add forked "$FORK_REPO_GIT_URL"
git fetch forked
- name: Setup local maven cache
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: checkstyle-maven-cache-${{ hashFiles('**/pom.xml') }}
- name: Download contribution
uses: actions/checkout@v4
with:
repository: checkstyle/contribution
path: .ci-temp/contribution
- name: Prepare environment
run: |
mv .ci-temp/project.properties ./.ci-temp/contribution/checkstyle-tester/
mv .ci-temp/*.xml ./.ci-temp/contribution/checkstyle-tester/
sudo apt install groovy
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Generate report
env:
BRANCH: ${{ needs.parse_body.outputs.branch }}
run: |
cd .ci-temp/contribution/checkstyle-tester
bash
REF="forked/$BRANCH"
REPO="../../../../checkstyle"
BASE_BRANCH="upstream/master"
export MAVEN_OPTS="-Xmx5g"
if [ -f new_module_config.xml ]; then
groovy diff.groovy -r "$REPO" -p "$REF" -pc new_module_config.xml -m single\
-l project.properties -xm "-Dcheckstyle.failsOnError=false"\
--allowExcludes
elif [ -f patch_config.xml ]; then
groovy diff.groovy -r "$REPO" -b "$BASE_BRANCH" -p "$REF" -bc diff_config.xml\
-pc patch_config.xml -l project.properties -xm "-Dcheckstyle.failsOnError=false"\
--allowExcludes
else
groovy diff.groovy -r "$REPO" -b "$BASE_BRANCH" -p "$REF" -c diff_config.xml\
-l project.properties -xm "-Dcheckstyle.failsOnError=false"\
--allowExcludes
fi
- name: Copy Report to AWS S3 Bucket
env:
LABEL: ${{ needs.parse_body.outputs.report_label }}
run: |
bash
TIME=$(date +%Y%H%M%S)
FOLDER="${{needs.parse_body.outputs.commit_sha}}_$TIME"
DIFF="./.ci-temp/contribution/checkstyle-tester/reports/diff"
LINK="https://${{env.AWS_BUCKET_NAME}}.s3.${{env.AWS_REGION}}.amazonaws.com"
aws s3 cp $DIFF "s3://${{env.AWS_BUCKET_NAME}}/$FOLDER/reports/diff/" --recursive
if [ -n "$LABEL" ]; then
echo "$LABEL: " > .ci-temp/message
fi
echo "$LINK/$FOLDER/reports/diff/index.html" >> .ci-temp/message
- name: Set output
id: out
run: |
./.ci/append-to-github-output.sh "message" "$(cat .ci-temp/message)"
# should be always last step
send_message:
runs-on: ubuntu-latest
needs: [ parse_body, make_report ]
if: failure() || success()
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get message
env:
MSG: ${{ needs.make_report.outputs.message }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p .ci-temp
if [ -z "$MSG" ]; then
JOBS_LINK="https://github.com/checkstyle/checkstyle/actions/runs/${{github.run_id}}"
API_LINK="https://api.github.com/repos/checkstyle/checkstyle/actions/runs/"
API_LINK="${API_LINK}${{github.run_id}}/jobs"
curl --fail-with-body -X GET "${API_LINK}" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token $GITHUB_TOKEN" \
-o .ci-temp/info.json
jq '.jobs' .ci-temp/info.json > ".ci-temp/jobs"
jq '.[] | select(.conclusion == "failure") | .name' .ci-temp/jobs > .ci-temp/job_name
jq '.[] | select(.conclusion == "failure") | .steps' .ci-temp/jobs > .ci-temp/steps
jq '.[] | select(.conclusion == "failure") | .name' .ci-temp/steps > .ci-temp/step_name
echo "Report generation failed on phase $(cat .ci-temp/job_name)," > .ci-temp/message
echo "step $(cat .ci-temp/step_name).<br>Link: $JOBS_LINK" >> .ci-temp/message
else
echo "$MSG" > .ci-temp/message
fi
- name: Set message
id: out
run: |
./.ci/append-to-github-output.sh "message" "$(cat .ci-temp/message)"
- name: Comment PR
uses: checkstyle/contribution/comment-action@master
with:
message: ${{steps.out.outputs.message}}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}