Repository navigation
88 lines (86 loc) · 3.41 KB
/
Copy pathci.yml
File metadata and controls
88 lines (86 loc) · 3.41 KB
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
name: CI
on:
push:
branches: [production, develop]
pull_request:
branches: [production, develop]
jobs:
verify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
# Some editors save files with a UTF-8 BOM, and a tool that reads UTF-8 with
# the wrong encoding turns a dash or an arrow into two or three other
# characters. Both have reached PRs here, so catch them before review.
- name: No BOM or garbled characters
run: |
if git grep -n -I -F -e $'\xEF\xBB\xBF' -e $'\xCE\x93\xC3\x87' -e $'\xCE\x93\xC3\xA5\xC3\x86' \
-e $'\xE2\x94\xAC\xE2\x95\x96' -e $'\xC3\xA2\xE2\x82\xAC' -e $'\xC3\x83\xC2\xA9'; then
echo "::error::The lines above start with a UTF-8 BOM or have text garbled by the wrong encoding. Save the file as UTF-8 without a BOM, and copy garbled lines back from the base branch."
exit 1
fi
- uses: actions/setup-node@v6
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm run lint
- run: npm run test
# Builds the Worker the same way Workers Builds does. This runs `npm run build`
# (next build) first, so there is no separate build step.
- run: npx opennextjs-cloudflare build
# A green next build doesn't mean the Worker runs. v0.7.0 built fine and then
# threw on every request, so start the built Worker in local workerd and
# request every page in the sitemap, the og:image each page links to and a
# missing page.
- name: Request every page from the built Worker
env:
WRANGLER_SEND_METRICS: "false"
run: |
npx wrangler dev --ip 127.0.0.1 --port 8787 > wrangler.log 2>&1 &
base=http://127.0.0.1:8787
for i in $(seq 90); do
curl -s -o /dev/null "$base/robots.txt" && break
sleep 1
done
pages=$(curl -s "$base/sitemap.xml" | grep -o '<loc>[^<]*' | sed -E 's|<loc>https?://[^/]+||')
fail=0
if [ -z "$pages" ]; then
echo "sitemap.xml has no pages"
fail=1
fi
check() {
code=$(curl -s -o body.out -w '%{http_code}' "$base$1" || true)
echo "$code $1"
if [ "$code" != "$2" ]; then fail=1; fi
}
for p in $pages; do
check "$p" 200
img=$(grep -o 'property="og:image" content="[^"]*' body.out | head -1 | sed -E 's|.*content="https?://[^/]+||; s|&|\&|g')
if [ -n "$img" ]; then
check "$img" 200
else
echo "no og:image on $p"
fail=1
fi
done
check /sitemap.xml 200
check /robots.txt 200
check /no-such-page 404
if grep -q 'wrangler:error' wrangler.log; then fail=1; fi
if [ "$fail" != 0 ]; then
echo "The built Worker failed. Wrangler output:"
cat wrangler.log
exit 1
fi
- name: Lighthouse CI performance budgets
run: |
if ! curl -s -o /dev/null http://127.0.0.1:8787/robots.txt; then
npx wrangler dev --ip 127.0.0.1 --port 8787 > wrangler.log 2>&1 &
for i in $(seq 30); do
curl -s -o /dev/null http://127.0.0.1:8787/robots.txt && break
sleep 1
done
fi
npm run lighthouse
pkill -f "wrangler dev" || true