Repository navigation
177 lines (160 loc) · 7.89 KB
/
Copy pathdocs.yml
File metadata and controls
177 lines (160 loc) · 7.89 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
172
173
174
175
176
177
name: Docs
# Copy to .github/workflows/docs.yml. Before the first run, set the repository's
# Pages source to "GitHub Actions": Settings -> Pages -> Source, or
# `gh api -X PUT repos/GeiserX/<repo>/pages -f build_type=workflow` (HTTP 204;
# the API keeps reporting the old source branch afterwards, which is cosmetic).
# A repo with no Pages at all uses `-X POST` with the same field. A repo
# already on the artifact flow needs no change.
#
# Never for a repo whose gh-pages branch holds a Helm chart index (index.yaml,
# artifacthub-repo.yml): Pumperly, LynxPrompt, genieacs-container. Those use
# docs-pages-helm.yml instead.
#
# Pull requests that touch the docs run the strict build and the site check,
# so a broken link, a missing page or an unreachable page fails the check
# instead of reaching the site. A push to main deploys, and only after the
# same build has passed.
#
# The site is published as a Pages artifact: no gh-pages branch, no
# `contents: write`, and one artifact is the whole site.
on:
push:
branches:
- main
paths:
- 'docs/**'
- 'zensical.toml'
- '.github/workflows/docs.yml'
- '.github/scripts/site-check.py'
- '.github/scripts/docs-i18n.py'
# getting-started.md includes docker-compose.yml word for word
# with pymdownx.snippets: a change to it must rebuild the site.
- 'docker-compose.yml'
# Add every file a page includes with pymdownx.snippets (for example
# docker-compose.yml, .env.example): a change to it must rebuild the
# site, and a rename must fail the build.
# No paths filter on pull requests, on purpose: a check skipped by a path
# filter stays Pending and blocks the merge once it is a required check
# (repos.md step 5 makes green checks required). The build takes seconds.
pull_request:
workflow_dispatch:
# A daily redeploy of main. It repairs a deploy that failed all three tries,
# and a release whose push of the compose pins to main did not land. (That
# push is made with a deploy key, so when it lands it starts this workflow.)
schedule:
- cron: '41 8 * * *'
# One run at a time per ref, never cancelled. GitHub keeps one running and one
# pending run per group, and a run that joins later replaces the pending one.
# Runs join in the order GitHub queues them, which is not promised to be push
# order, so a newer push is likely, not certain, to deploy last.
# Locking only the deploy job is not enough: an older push whose build finishes
# later could deploy last and publish a stale site. Pull requests get their own group.
concurrency:
group: pages-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: read
jobs:
build:
name: build (strict)
# Public repo: GitHub-hosted runners are free and unlimited here, and the
# job runs on pull requests, so it must never touch a self-hosted runner.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# This job never pushes; a persisted token is readable by pip and by the build.
persist-credentials: false
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: '3.13'
# pip's download cache only. Zensical's own build cache (.cache/) is
# never kept between runs: its docs advise against it on CI, and
# --clean below starts from nothing anyway.
cache: pip
cache-dependency-path: docs/requirements-docs.txt
- name: Install dependencies
run: pip install -r docs/requirements-docs.txt
# zensical.toml sets `strict = true`; the flag here keeps the build strict
# even if someone removes that line. `python -m zensical`, never the bare
# `zensical` command: it puts the repo root on sys.path, which the awesome
# lists' Markdown extension needs, and every repo builds the same way.
#
# The social plugin downloads its font from Google Fonts on every build
# (--clean empties its cache) and stops the build if that download fails;
# it has no retry of its own. So a failed font download, and only that,
# (the manifest or a font file) gets two more tries. Any other error fails on the first run.
- name: Build
# bash -eo pipefail: without it the `| tee` below reports tee's status,
# so a failed build would pass.
shell: bash
run: |
log="$RUNNER_TEMP/zensical-build.log"
for attempt in 1 2 3; do
if python -m zensical build --clean --strict 2>&1 | tee "$log"; then
exit 0
fi
if ! grep -q -e 'failed to fetch font family' -e 'failed to read Google Fonts manifest' -e 'failed to download font from' -e 'failed to read font from' "$log"; then
exit 1
fi
echo "::warning::Font download for the social cards failed (attempt $attempt of 3)"
sleep 20
done
exit 1
# Every other language is one more build of the same docs into site/<lang>/,
# with the translated pages of docs/i18n/<lang>/ swapped in (docs-i18n.py says
# why: Zensical gives a project one language). The check fails on a translation
# that changed a code block, inline code or a link target, and lists the pages
# whose English source moved on; the build fails on changed heading ids.
- name: Check the translations
run: python -I .github/scripts/docs-i18n.py check
- name: Build the translations
run: python -I .github/scripts/docs-i18n.py build
# What the strict build does not check: a page in no nav entry, a nav
# entry for a missing file, a missing image, a /rooted link, a raw <title>
# in a page. Each one was proven to turn this step red (validate-zensical.sh).
- name: Check the built site
run: python -I .github/scripts/site-check.py site
# Push to main only: workflow_dispatch can be run on any branch, and the
# push filter above does not apply to it. Same line as docs-pages-helm.yml.
- name: Upload the site
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
with:
path: site
deploy:
# Runs on main only (push, schedule or dispatch), after the build job has passed.
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
needs: build
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url || steps.deployment-2.outputs.page_url || steps.deployment-3.outputs.page_url }}
steps:
- uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0
# Pages sometimes answers "Failed to create deployment (status: 500)".
# The same artifact gets two more tries, 30 s apart; the third failure
# fails the job, and the daily schedule above deploys main again.
- id: deployment
continue-on-error: true
uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1
- name: Wait before the second try
if: steps.deployment.outcome == 'failure'
run: |
echo "::warning::Pages deployment failed (attempt 1 of 3)"
sleep 30
- id: deployment-2
if: steps.deployment.outcome == 'failure'
continue-on-error: true
uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1
- name: Wait before the third try
if: steps.deployment-2.outcome == 'failure'
run: |
echo "::warning::Pages deployment failed (attempt 2 of 3)"
sleep 30
- id: deployment-3
if: steps.deployment-2.outcome == 'failure'
uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1