178 lines (155 loc) · 6.25 KB
/
site.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
#####################################################################################
# GitHub Action to generate Checkstyle site.
#
# Workflow starts when:
# 1) issue comment - created, edited
#
# 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: "Site"
env:
AWS_REGION: "us-east-2"
AWS_BUCKET_NAME: "checkstyle-diff-reports"
on:
issue_comment:
types: [ created, edited ]
permissions:
contents: read
pull-requests: write
concurrency:
group: ${{ github.workflow }}-${{ github.event.issue.number || github.ref }}
cancel-in-progress: false
jobs:
parse_pr_info:
if: github.event.comment.body == 'GitHub, generate web site'
|| github.event.comment.body == 'GitHub, generate website'
|| github.event.comment.body == 'GitHub, generate site'
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.branch.outputs.ref }}
commit_sha: ${{ steps.branch.outputs.commit_sha }}
steps:
- uses: shanegenschaw/pull-request-comment-trigger@v2.1.0
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: Getting PR description
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p .ci-temp
curl --fail-with-body -X GET "${{github.event.issue.pull_request.url}}" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token $GITHUB_TOKEN" \
-o .ci-temp/info.json
jq .head.ref .ci-temp/info.json > .ci-temp/branch
jq .head.sha .ci-temp/info.json > .ci-temp/commit_sha
- name: Set branch
id: branch
run: |
echo "ref=$(xargs < .ci-temp/branch)" >> "$GITHUB_OUTPUT"
echo "commit_sha=$(xargs < .ci-temp/commit_sha | cut -c 1-7)" >> "$GITHUB_OUTPUT"
generate_site:
needs: parse_pr_info
runs-on: ubuntu-latest
outputs:
message: ${{ steps.out.outputs.message}}
steps:
- name: Checkout repository from origin
uses: actions/checkout@v4
# fetch-depth - number of commits to fetch.
# 0 indicates all history for all branches and tags.
# 0, because we need access to all branches to create a report.
# ref - branch to checkout.
- name: Download checkstyle for PR
uses: actions/checkout@v4
env:
USER_LOGIN: ${{ github.event.issue.user.login }}
with:
repository: ${{ env.USER_LOGIN }}/checkstyle
ref: ${{needs.parse_pr_info.outputs.branch}}
path: .ci-temp/checkstyle
fetch-depth: 0
- 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: Setup local maven cache
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: checkstyle-maven-cache-${{ hashFiles('**/pom.xml') }}
- name: Generate site
run: |
bash
cd .ci-temp/checkstyle
mvn -e --no-transfer-progress clean site -Pno-validations -Dmaven.javadoc.skip=false
- name: Copy site to AWS S3 Bucket
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPOSITORY_OWNER: ${{ github.repository_owner }}
run: |
bash
TIME=$(date +%Y%H%M%S)
FOLDER="${{needs.parse_pr_info.outputs.commit_sha}}_$TIME"
SITE=".ci-temp/checkstyle/target/site"
LINK="https://${{env.AWS_BUCKET_NAME}}.s3.${{env.AWS_REGION}}.amazonaws.com"
aws s3 cp "$SITE" "s3://${{env.AWS_BUCKET_NAME}}/$FOLDER/" --recursive
echo "$LINK/$FOLDER/index.html" > .ci-temp/message
./.ci/generate-extra-site-links.sh ${{ github.event.issue.number }} "$LINK/$FOLDER"
- 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: [ generate_site ]
if: failure() || success()
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get message
env:
MSG: ${{needs.generate_site.outputs.message}}
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"
echo "API_LINK=${API_LINK}"
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 "Site generation job 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 }}