Repository navigation
171 lines (161 loc) · 6.25 KB
/
Copy pathpages.yml
File metadata and controls
171 lines (161 loc) · 6.25 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
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
name: pages
on:
push:
branches: [main]
paths:
- "*.md"
- ".order"
- "mkdocs.yml"
- "assets/**"
- ".github/workflows/pages.yml"
workflow_dispatch:
permissions:
contents: read
concurrency:
group: pages
cancel-in-progress: false
env:
MKDOCS_IMAGE: squidfunk/mkdocs-material:9.8.2@sha256:fd13d78a4b1da637405c0336c9f0a4e0594b59271df106bd9cd64cae56cd1f38
jobs:
build:
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
contents: read
pages: read
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Configure Pages
id: pages
uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0
- name: Stage pages listed in .order and the fixed files of assets/ (config/ and .order stay out)
run: |
set -euo pipefail
stage="$RUNNER_TEMP/mkdocs"
mkdir -p "$stage/build-docs" "$stage/site"
cp -- mkdocs.yml "$stage/"
while IFS= read -r name || [ -n "$name" ]; do
name="${name%$'\r'}"
name="${name#$'\xEF\xBB\xBF'}"
if [ -z "$name" ]; then continue; fi
if ! [[ "$name" =~ ^[A-Za-z0-9._-]+$ ]]; then
echo "unexpected page name in .order: $name" >&2
exit 1
fi
cp -- "$name.md" "$stage/build-docs/"
done < .order
ls -1 "$stage/build-docs"
# assets/: fixed names (same list and order as tools/build-site.ps1), plain folder,
# regular files only, nothing else in the folder, size cap, static SVG content only
if [ -L assets ] || [ ! -d assets ]; then
echo "assets must be a plain folder" >&2
exit 1
fi
shopt -s nullglob dotglob
for f in assets/*; do
case "${f#assets/}" in
logo.svg|favicon.svg) ;;
*) printf 'unexpected entry in assets/: %q\n' "${f#assets/}" >&2; exit 1 ;;
esac
done
shopt -u nullglob dotglob
mkdir -p "$stage/build-docs/assets"
for name in logo.svg favicon.svg; do
if [ -L "assets/$name" ] || [ ! -f "assets/$name" ]; then
echo "assets/$name is missing or not a regular file" >&2
exit 1
fi
if ! [ "$(wc -c < "assets/$name")" -le 8192 ]; then
echo "assets/$name is larger than 8192 bytes" >&2
exit 1
fi
cp -- "assets/$name" "$stage/build-docs/assets/"
done
if ! [ "$(ls -A "$stage/build-docs/assets" | wc -l)" -eq 2 ]; then
echo "staged asset count is not 2" >&2
exit 1
fi
svg_deny=(
'<script'
'<foreignobject'
'<!'
'<\?'
'(^|[^a-z0-9_-])on[a-z]+[[:space:]]*='
'(javascript|vbscript|data)[[:space:]]*:'
'href[[:space:]]*=[[:space:]]*.[^#]'
'url[[:space:]]*\('
'@import|@font-face|expression[[:space:]]*\('
'<(a|set|animate[a-z]*|image|img|iframe|embed|object|feimage|audio|video|canvas|link|meta|base|handler|listener|style|metadata)([[:space:]/>]|$)'
'xmlns:|xlink:|xml:base|sodipodi|inkscape|rdf:'
'[&\]'
'//'
'style[[:space:]]*='
'image-set|image[[:space:]]*\(|cross-fade|src[[:space:]]*\('
)
for name in logo.svg favicon.svg; do
f="$stage/build-docs/assets/$name"
if ! [ "$(LC_ALL=C tr -d '\011\012\040-\176' < "$f" | wc -c)" -eq 0 ]; then
echo "assets/$name has bytes other than printable ASCII, tab and LF" >&2
exit 1
fi
if [ "$(head -c 4 "$f")" != "<svg" ] ||
[ "$(tail -c 7 "$f" | od -An -tx1 | tr -d ' \n')" != "3c2f7376673e0a" ] ||
! [ "$(grep -oi '<svg' "$f" | wc -l)" -eq 1 ] ||
! grep -q 'viewBox="' "$f" ||
! grep -q 'xmlns="http://www.w3.org/2000/svg"' "$f"; then
echo "assets/$name must start with <svg, end with </svg> and LF, and hold one <svg with xmlns and viewBox" >&2
exit 1
fi
t="$(tr '\n\t' ' ' < "$f" | sed -E 's#xmlns="http://www\.w3\.org/2000/svg"##g; s/url\(#[A-Za-z0-9_-]+\)//g')"
for p in "${svg_deny[@]}"; do
rc=0; grep -Eiq -e "$p" <<< "$t" || rc=$?
if [ "$rc" -ne 1 ]; then
echo "assets/$name: disallowed SVG content or check error (pattern $p, grep rc $rc)" >&2
exit 1
fi
done
rc=0; grep -Eiq -e '(javascript|vbscript|data):' <<< "$(tr -d '[:space:]' <<< "$t")" || rc=$?
if [ "$rc" -ne 1 ]; then
echo "assets/$name: disallowed SVG content or check error (scheme split by whitespace, grep rc $rc)" >&2
exit 1
fi
done
ls -1 "$stage/build-docs/assets"
- name: Build site (strict, pinned image, no network)
env:
SITE_URL: ${{ steps.pages.outputs.base_url }}/
run: |
set -euo pipefail
stage="$RUNNER_TEMP/mkdocs"
docker run --rm \
--network none \
--read-only --tmpfs /tmp \
--cap-drop ALL \
--security-opt no-new-privileges \
--user "$(id -u):$(id -g)" \
-e SITE_URL \
--mount "type=bind,source=$stage,target=/docs,readonly" \
--mount "type=bind,source=$stage/site,target=/docs/site" \
"$MKDOCS_IMAGE" build -f mkdocs.yml --strict
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
with:
path: ${{ runner.temp }}/mkdocs/site
deploy:
needs: build
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1