-
Notifications
You must be signed in to change notification settings - Fork 14
187 lines (169 loc) · 6.15 KB
/
main.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
# Copyright 2023, Proofcraft Pty Ltd
# Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
#
# SPDX-License-Identifier: BSD-2-Clause
---
name: PR
on:
pull_request:
types: [opened, synchronize]
jobs:
snapshot:
name: "Build site"
runs-on: 'ubuntu-latest'
outputs:
linkchecker_failed: ${{ steps.linkchecker_status.outputs.linkchecker_failed }}
validator_failed: ${{ steps.validator_status.outputs.validator_failed }}
validator_msg: ${{ steps.msg.outputs.validator_msg }}
linkcheck_msg: ${{ steps.linkmsg.outputs.linkcheck_msg }}
steps:
- uses: actions/checkout@v4
# sets up ruby accourding to .ruby-version and caches bundler deps
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: 'Site'
id: 'site'
run: |
make build
# Link checking etc is done on the main build, PR preview builds the site
# again, but since all dependencies are installed now, this should be fast.
- name: 'Prepare Preview'
run: |
echo 'baseurl: "/website_pr_hosting/PR_${{ github.event.number }}"' >> _preview.yml
make preview
- name: 'Link Check'
id: 'linkchecker_status'
run: |
make checklinks > linkchecker.log 2>&1 || touch .linkchecker_failed
if [ -e ".linkchecker_failed" ]; then
echo "linkchecker_failed=true" >> $GITHUB_OUTPUT
else
echo "linkchecker_failed=false" >> $GITHUB_OUTPUT
fi
- name: 'Prepare Link Check Message'
id: linkmsg
run: |
output="linkchecker-msg.txt"
sed 's|/github/workspace/||g' linkchecker.log | \
sed 's|\\|\\\\|g' | \
sed 's|\"|\\\"|g' >> "$output"
MSG="$(cat "$output")"
# Replaces newlines with the string '\n'
MSG="${MSG//$'\n'/'\n'}"
echo "linkcheck_msg=$MSG" >> $GITHUB_OUTPUT
- name: HTML5 Validator
id: validate
uses: Cyb3r-Jak3/html5validator-action@v7.2.0
with:
root: _site
format: text
blacklist: pr_checks
continue-on-error: true
- name: Check status of HTML5 validator
id: validator_status
run: |
if [ "${{ steps.validate.outputs.result }}" -eq "0" ]; then
echo "validator_failed=false" >> $GITHUB_OUTPUT
else
echo "validator_failed=true" >> $GITHUB_OUTPUT
fi
- name: Fix up HTML5 validator log paths + escape quotes
id: msg
run: |
output="_site/localhost/pr_checks/validator.log"
mkdir -p "$(dirname "$output")"
sed 's|/github/workspace/||g' log.log | \
sed 's|\\|\\\\|g' | \
sed 's|\"|\\\"|g' >> "$output"
MSG="$(cat "$output")"
# Replaces newlines with the string '\n'
MSG="${MSG//$'\n'/'\n'}"
echo "validator_msg=$MSG" >> $GITHUB_OUTPUT
- name: Deploy Preview
if: github.repository_owner == 'seL4' && github.event.pull_request.head.repo.full_name == 'seL4/website'
uses: peaceiris/actions-gh-pages@v4
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
external_repository: seL4/website_pr_hosting
publish_dir: ./_preview
destination_dir: PR_${{ github.event.number }}
linkchecker:
name: "Link checker"
runs-on: 'ubuntu-latest'
needs: snapshot
env:
LINKCHECK_MSG: ${{ needs.snapshot.outputs.linkcheck_msg }}
continue-on-error: true
steps:
- name: show linkchecker status
run: |
if ${{ needs.snapshot.outputs.linkchecker_failed }}; then
echo -e "$LINKCHECK_MSG"
exit 1
fi
exit 0
htmlvalidator:
name: "HTML5 Validator"
runs-on: 'ubuntu-latest'
needs: snapshot
env:
VALIDATOR_MSG: ${{ needs.snapshot.outputs.validator_msg }}
continue-on-error: true
steps:
- name: show validator status
run: |
if ${{ needs.snapshot.outputs.validator_failed }}; then
echo -e "$VALIDATOR_MSG"
exit 1
fi
exit 0
comment:
name: "PR Comment"
runs-on: 'ubuntu-latest'
needs: [snapshot]
env:
LINKCHECK_MSG: ${{ needs.snapshot.outputs.linkcheck_msg }}
VALIDATOR_MSG: ${{ needs.snapshot.outputs.validator_msg }}
steps:
# TODO: in the future, when this issue is resolved: https://github.com/peaceiris/actions-gh-pages/issues/348, the link
# generated should be for the commit itself, not just the tip.
- name: Build message
id: msg
run: |
rm -f msg.txt
touch msg.txt
echo "Preview your changes [here](https://sel4.github.io/website_pr_hosting/PR_${{ github.event.number }})" >> msg.txt
if ${{ needs.snapshot.outputs.linkchecker_failed }}; then
echo "" >> msg.txt
echo "The link checker found some issues!" >> msg.txt
echo \`\`\` >> msg.txt
echo "$LINKCHECK_MSG" >> msg.txt
echo \`\`\` >> msg.txt
fi
if ${{ needs.snapshot.outputs.validator_failed }}; then
echo "" >> msg.txt
echo "The HTML5 validator found some issues!" >> msg.txt
echo \`\`\` >> msg.txt
echo "$VALIDATOR_MSG" >> msg.txt
echo \`\`\` >> msg.txt
fi
export MSG="$(cat msg.txt)"
# The following replaces newlines with the string '\n' for the JS call further below
MSG="${MSG//$'\n'/'\n'}"
echo "MSG=$MSG" >> $GITHUB_ENV
- name: Print message
run: |
echo "$MSG"
- name: Leave comment with link to site, and results of checks
uses: actions/github-script@v7
if: github.repository_owner == 'seL4' && github.event.pull_request.head.repo.full_name == 'seL4/website'
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "${{ env.MSG }}"
})