-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
action.yml
216 lines (199 loc) · 8.55 KB
/
action.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
name: 'Run Hugo/Pagefind and deploy to GitHub Pages'
description: 'Runs Hugo and Pagefind and then deploys the result to GitHub Pages.'
# This composite Action requires the following things in the calling workflow:
#
# permissions:
# contents: write # to push changes (if any)
# pages: write # to deploy to GitHub Pages
# id-token: write # to verify that the deployment source is legit
# environment:
# name: github-pages
# url: ${{ steps.<id-of-deployment-step>.outputs.url }}
inputs:
github-token:
description: The GitHub token used to create an authenticated client
default: ${{ github.token }}
required: true
cloudflare-token:
description: The Cloudflare API token used to purge Cloudflare caches.
required: false
cloudflare-zone:
description: The Cloudflare zone to purge.
required: false
outputs:
url:
description: The URL to which the site was deployed
value: ${{ steps.deploy.outputs.page_url }}
runs:
using: "composite"
steps:
- name: push changes (if needed)
shell: bash
run: |
test "$(git rev-parse HEAD)" = "$(git rev-parse refs/remotes/origin/${{ github.ref_name }})" ||
git push origin HEAD:${{ github.ref }}
- name: un-sparse worktree to prepare for deployment
shell: bash
run: git sparse-checkout disable
- name: setup GitHub Pages
id: pages
uses: actions/configure-pages@v5
- name: configure Hugo and Pagefind version
shell: bash
run: |
set -x &&
echo "HUGO_VERSION=$(sed -n 's/^ *hugo_version: *//p' <hugo.yml)" >>$GITHUB_ENV
echo "PAGEFIND_VERSION=$(sed -n 's/^ *pagefind_version: *//p' <hugo.yml)" >>$GITHUB_ENV
- name: install Hugo ${{ env.HUGO_VERSION }}
shell: bash
run: |
set -x &&
curl -Lo /tmp/hugo.deb https://github.com/gohugoio/hugo/releases/download/v$HUGO_VERSION/hugo_extended_${HUGO_VERSION}_linux-amd64.deb &&
sudo dpkg -i /tmp/hugo.deb
- name: run Hugo to build the pages
env:
HUGO_RELATIVEURLS: false
shell: bash
run: hugo config && hugo --baseURL "${{ steps.pages.outputs.base_url }}/"
- name: run Pagefind ${{ env.PAGEFIND_VERSION }} to build the search index
shell: bash
run: npx -y pagefind@${{ env.PAGEFIND_VERSION }} --site public
- name: Temporarily copy some Rails assets to help the transition
shell: bash
run: |
# To help with the transition from the Rails app to the Hugo/Pagefind site, where
# at least for a while the cached version of git-scm.com might be served via
# Cloudflare, according to the first transition attempt on Sep 20, 2024, potentially
# partially, i.e. _some_ assets might still be cached, _some_ others might not, let's
# copy the most prominent assets to the new page so that, say, the original front page
# won't fail to load the style sheet and Javascript libraries that it needs.
set -x &&
mkdir -p public/assets &&
for f in application-93865c5c820c24f4c599e8b9c544bcd8a0d03260f9b16c9ba80b6a00082112c9.css \
application-f7a750114a26afea236a5cc26f6ff3925a14c5901e9ea9018fb869432d0cbee3.js \
modernize-b3ebe0c31c24f230dc62179d3e1030d2e57a53b1668d9382c0a27dbd44a94beb.js
do
curl -Lfo public/assets/$f https://git-scm.com/assets/$f ||
echo "::error::could not copy $f from https://git-scm.com/" >&2
done
- name: upload GitHub Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./public
- name: deploy
id: deploy
uses: actions/deploy-pages@v4
- name: Purge Cloudflare cache
id: cloudflare
shell: bash
env:
CLOUDFLARE_ZONE: ${{ inputs.cloudflare-zone }}
CLOUDFLARE_TOKEN: ${{ inputs.cloudflare-token }}
if: env.CLOUDFLARE_TOKEN != ''
run: |
curl "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE/purge_cache" \
-H "Authorization: Bearer $CLOUDFLARE_TOKEN" \
-H "Content-Type: application/json" \
-d '{ "purge_everything": true }'
- name: construct `--remap` options for lychee
id: remap
shell: bash
run: |
base_url='${{ steps.pages.outputs.base_url }}'
echo "result=$(echo "$base_url" |
sed 's|^\(.*\)\(/git-scm\.com\)$|(\1)?\2(.*)|') file://$PWD/public\$2" \
>>$GITHUB_OUTPUT
# When running in forks, do detect when links try to break out of the
# `/git-scm.com/` subdirectory
echo "remap-dotdot=$(echo "$base_url" |
sed -n 's|^\(https\?:\/\/.*\)\(/git-scm\.com\)$|--remap '\''(\1.*) file://../$1'\''|p')" \
>>$GITHUB_OUTPUT
- name: check for broken links
id: lychee
uses: lycheeverse/lychee-action@v2
with:
args: >-
--offline
--fallback-extensions html
--base '${{ steps.pages.outputs.base_url }}'
--remap '${{ steps.remap.outputs.result }}'
${{ steps.remap.outputs.remap-dotdot }}
--exclude file:///path/to/repo.git/
--exclude file:///caminho/para/o/reposit%C3%B3rio.git/
--exclude file:///ruta/a/repositorio.git/
--exclude file:///sl%C3%B3%C3%B0/til/hirsla.git/
--exclude file:///Pfad/zum/Repo.git/
--exclude file:///chemin/du/d%C3%A9p%C3%B4t.git/
--exclude file:///srv/git/project.git
public/
output: lychee.md
jobSummary: true
fail: false
failIfEmpty: false # needed because its default overrides `fail = false`
- name: ${{ env.lychee_exit_code != '0' && 'open or update' || 'maybe close' }} link checker issue
if: env.lychee_exit_code != ''
uses: actions/github-script@v7
with:
github-token: ${{ inputs.github-token }}
script: |
const fs = await import('fs')
// GitHub issues can only have 64k characters in their body
const body = (s => {
if (s.length < 65535) return s
return s.replace(/^([^]{0,65000}\n)[^]*\n(.+)\n?$/, '$1\n[...]\n\n$2')
})(await fs.promises.readFile('lychee.md', 'utf8'))
const req = { owner: context.repo.owner, repo: context.repo.repo }
const issues = await (async () => {
const q = `"Link+Checker+Report"+in:title+is:issue+label:linkchecker+is:open+repo:${req.owner}/${req.repo}`
try {
return await github.rest.search.issuesAndPullRequests({ ...req, q, sort: 'created', per_page: 1 })
} catch (e) {
console.log(`Warning: ${e}; sleeping for 30 seconds and falling back to calling listForRepo()`)
await new Promise(r => setTimeout(r, 30000))
const issues = await github.rest.issues.listForRepo({...req, state: 'open', per_page: 100})
return {
data: {
items: issues.data.filter(
e => e.title === 'Link Checker Report'
&& e.labels.filter(l => l.name === 'linkchecker').length > 0
)
}
}
}
})()
if (issues.data.items.length === 0) {
if (process.env.lychee_exit_code !== '0') {
await github.rest.issues.create({ ...req, title: 'Link Checker Report', body, labels: ['linkchecker'] })
}
} else {
req.issue_number = issues.data.items[0].number
await github.rest.issues.createComment({ ...req, body })
if (process.env.lychee_exit_code === '0') {
await github.rest.issues.update({ ...req, state: 'closed' })
}
}
- name: Install @playwright/test
shell: bash
run: npm install @playwright/test
- name: Edit /etc/hosts to map git-scm.com to GitHub
shell: bash
# This side-steps the Cloudflare caches
run: sudo sh -c 'echo "185.199.108.153 git-scm.com" >>/etc/hosts'
- name: Run Playwright tests
shell: bash
id: playwright
env:
PLAYWRIGHT_TEST_URL: ${{ steps.pages.outputs.base_url }}
run: |
# avoid test failures when HTTPS is enforced half-way through
case "$PLAYWRIGHT_TEST_URL" in
https://*|http://git-scm.com) ;; # okay, leave as-is
http://*) PLAYWRIGHT_TEST_URL="https://${PLAYWRIGHT_TEST_URL#http://}";;
esac &&
echo "result=$PLAYWRIGHT_TEST_URL" >>$GITHUB_OUTPUT &&
npx playwright test --project=chrome
- uses: actions/upload-artifact@v4
if: always() && steps.playwright.outputs.result != ''
with:
name: playwright-report
path: playwright-report/