forked from sagemath/sage
-
Notifications
You must be signed in to change notification settings - Fork 0
267 lines (248 loc) · 10.8 KB
/
doc-build.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
name: Build documentation
on:
pull_request:
merge_group:
push:
tags:
# Match all release tags including beta, rc
- '[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.beta[0-9]+'
- '[0-9]+.[0-9]+.[0-9]+.beta[0-9]+'
- '[0-9]+.[0-9]+.rc[0-9]+'
- '[0-9]+.[0-9]+.[0-9]+.rc[0-9]+'
branches:
- develop
workflow_dispatch:
# Allow to run manually
inputs:
platform:
description: 'Platform'
required: true
default: 'ubuntu-jammy-standard'
docker_tag:
description: 'Docker tag'
required: true
default: 'dev'
concurrency:
# Cancel previous runs of this workflow for the same branch
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
# Same as in build.yml
TOX_ENV: "docker-${{ github.event.inputs.platform || 'ubuntu-jammy-standard' }}-incremental"
BUILD_IMAGE: "localhost:5000/${{ github.repository }}/sage-${{ github.event.inputs.platform || 'ubuntu-jammy-standard' }}-with-targets:ci"
FROM_DOCKER_REPOSITORY: "ghcr.io/sagemath/sage/"
FROM_DOCKER_TARGET: "with-targets"
FROM_DOCKER_TAG: ${{ github.event.inputs.docker_tag || 'dev'}}
EXTRA_CONFIGURE_ARGS: --enable-fat-binary
jobs:
build-doc:
runs-on: ubuntu-latest
services:
# https://docs.docker.com/build/ci/github-actions/local-registry/
registry:
image: registry:2
ports:
- 5000:5000
steps:
- name: Maximize build disk space
uses: easimon/maximize-build-space@v10
with:
# need space in /var for Docker images
root-reserve-mb: 30000
remove-dotnet: true
remove-android: true
remove-haskell: true
remove-codeql: true
remove-docker-images: true
- name: Checkout
uses: actions/checkout@v4
- name: Install test prerequisites
# From docker.yml
run: |
sudo DEBIAN_FRONTEND=noninteractive apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install tox
sudo apt-get clean
df -h
- name: Merge CI fixes from sagemath/sage
run: |
mkdir -p upstream
.ci/merge-fixes.sh 2>&1 | tee upstream/ci_fixes.log
env:
GH_TOKEN: ${{ github.token }}
SAGE_CI_FIXES_FROM_REPOSITORIES: ${{ vars.SAGE_CI_FIXES_FROM_REPOSITORIES }}
# Building
- name: Generate Dockerfile
# From docker.yml
run: |
tox -e ${{ env.TOX_ENV }}
cp .tox/${{ env.TOX_ENV }}/Dockerfile .
env:
# Only generate the Dockerfile, do not run 'docker build' here
DOCKER_TARGETS: ""
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: network=host
- name: Build Docker image
id: image
uses: docker/build-push-action@v6
with:
# push and load may not be set together at the moment
push: true
load: false
context: .
tags: ${{ env.BUILD_IMAGE }}
target: with-targets
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
NUMPROC=6
USE_MAKEFLAGS=-k V=0 SAGE_NUM_THREADS=4 --output-sync=recurse
TARGETS_PRE=build/make/Makefile
TARGETS=ci-build-with-fallback
- name: Start container
id: container
# Try to continue when "exporting to GitHub Actions Cache" failed with timeout
if: (success() || failure())
run: |
docker run --name BUILD -dit \
--mount type=bind,src=$(pwd),dst=$(pwd) \
--workdir $(pwd) \
${{ env.BUILD_IMAGE }} /bin/sh
#
# On PRs and pushes to develop
#
- name: Store old doc
id: worktree
if: (success() || failure()) && steps.container.outcome == 'success' && !startsWith(github.ref, 'refs/tags/')
run: |
git config --global --add safe.directory $(pwd)
git config --global user.email "[email protected]"
git config --global user.name "Build documentation workflow"
mkdir -p doc
# Check if we are on PR
PR_NUMBER=""
if [[ -n "$GITHUB_REF" ]]; then
if [[ "$GITHUB_REF" =~ refs/pull/([0-9]+)/merge ]]; then
PR_NUMBER="${BASH_REMATCH[1]}"
fi
fi
# If so, then prepare to create CHANGES.html
if [[ -n "$PR_NUMBER" ]]; then
# mathjax path in old doc (regex)
mathjax_path_from="[-./A-Za-z_]*/tex-chtml[.]js?v=[0-9a-f]*"
# mathjax path in new doc
mathjax_path_to=$(docker exec -e SAGE_USE_CDNS=yes BUILD /sage/sage -python -c "from sage_docbuild.conf import mathjax_path; print(mathjax_path)")
new_version=$(docker exec BUILD cat src/VERSION.txt)
docker cp BUILD:/sage/local/share/doc/sage/html doc/
# Wipe out chronic diffs between old doc and new doc
(cd doc && \
find . -name "*.html" | xargs sed -i -e '/class="sidebar-brand-text"/ s/Sage [0-9a-z.]* /Sage '"$new_version"' /' \
-e '/<link rel="stylesheet"/ s/?v=[0-9a-f]*"/"/' \
-e 's;'"$mathjax_path_from"';'"$mathjax_path_to"';' \
-e '\;<script type="application/vnd\.jupyter\.widget-state+json">;,\;</script>; d' \
-e 's;#L[0-9]*";";' \
&& true)
# Create git repo from old doc
(cd doc && \
git init && \
(echo "*.svg binary"; echo "*.pdf binary") >> .gitattributes && \
(echo ".buildinfo"; echo '*.inv'; echo '.git*'; echo '*.svg'; echo '*.pdf'; echo '*.png'; echo 'searchindex.js') > .gitignore; \
git add -A && git commit --quiet -m 'old')
fi
- name: Build doc
id: docbuild
if: (success() || failure()) && steps.worktree.outcome == 'success' && !startsWith(github.ref, 'refs/tags/')
# Always non-incremental because of the concern that
# incremental docbuild may introduce broken links (inter-file references) though build succeeds
run: |
export GITHUB_REF=${{ github.ref }}
export PR_SHA=${{ github.event.pull_request.head.sha }}
export MAKE="make -j5 --output-sync=recurse" SAGE_NUM_THREADS=5
make doc-clean doc-uninstall
export SAGE_USE_CDNS=yes
./config.status && make sagemath_doc_html-no-deps
shell: sh .ci/docker-exec-script.sh BUILD /sage {0}
- name: Copy doc
id: copy
if: (success() || failure()) && steps.docbuild.outcome == 'success'
run: |
set -ex
# We copy everything to a local folder
docker cp --follow-link BUILD:/sage/local/share/doc/sage/html doc
docker cp --follow-link BUILD:/sage/local/share/doc/sage/index.html doc
# Check if we are on PR
PR_NUMBER=""
if [[ -n "$GITHUB_REF" ]]; then
if [[ "$GITHUB_REF" =~ refs/pull/([0-9]+)/merge ]]; then
PR_NUMBER="${BASH_REMATCH[1]}"
fi
fi
# If so, then create CHANGES.html
if [[ -n "$PR_NUMBER" ]]; then
(cd doc && git commit -a -m 'new')
# Wipe out chronic diffs of new doc against old doc before creating CHANGES.html
(cd doc && \
find . -name "*.html" | xargs sed -i -e '/This is documentation/ s/ built with GitHub PR .* for development/ for development/' \
-e '/<link rel="stylesheet"/ s/?v=[0-9a-f]*"/"/' \
-e '\;<script type="application/vnd\.jupyter\.widget-state+json">;,\;</script>; d' \
-e 's;#L[0-9]*";";' \
&& git commit -a -m 'wipe-out')
# Since HEAD is at commit 'wipe-out', HEAD~1 is commit 'new' (new doc), HEAD~2 is commit 'old' (old doc)
(cd doc && git diff $(git rev-parse HEAD~2) -- "*.html") > diff.txt
# Restore the new doc dropping changes by "wipe out"
(cd doc && git checkout -q -f HEAD~1)
.ci/create-changes-html.sh diff.txt doc
# Sometimes rm -rf .git errors out because of some diehard hidden files
# So we simply move it out of the doc directory
(cd doc && mv .git ../git && mv .gitattributes ../gitattributes)
mv CHANGES.html doc
fi
# Create the robots.txt file to discourage web crawlers from indexing doc preview webpages
echo "User-agent: *" > doc/robots.txt
echo "Disallow: /" >> doc/robots.txt
# Zip everything for increased performance
zip -r doc.zip doc
- name: Upload doc
id: upload
if: (success() || failure()) && steps.copy.outcome == 'success'
uses: actions/upload-artifact@v4
with:
name: doc
path: doc.zip
#
# On release tags: live doc and wheels
#
- name: Build live doc
id: buildlivedoc
if: (success() || failure()) && startsWith(github.ref, 'refs/tags/')
run: |
export MAKE="make -j5 --output-sync=recurse" SAGE_NUM_THREADS=5
export PATH="build/bin:$PATH"
eval $(sage-print-system-package-command auto update)
eval $(sage-print-system-package-command auto --yes --no-install-recommends install zip)
eval $(sage-print-system-package-command auto --spkg --yes --no-install-recommends install git texlive texlive_luatex free_fonts xindy)
export SAGE_USE_CDNS=yes
export SAGE_LIVE_DOC=yes
export SAGE_JUPYTER_SERVER=binder:sagemath/sage-binder-env/dev
make doc-clean doc-uninstall
./config.status && make sagemath_doc_html-no-deps sagemath_doc_pdf-no-deps
shell: sh .ci/docker-exec-script.sh BUILD /sage {0}
- name: Copy live doc
id: copylivedoc
if: (success() || failure()) && steps.buildlivedoc.outcome == 'success'
run: |
mkdir -p ./livedoc
# We copy everything to a local folder
docker cp --follow-link BUILD:/sage/local/share/doc/sage/html livedoc
docker cp --follow-link BUILD:/sage/local/share/doc/sage/pdf livedoc
docker cp --follow-link BUILD:/sage/local/share/doc/sage/index.html livedoc
zip -r livedoc.zip livedoc
- name: Upload live doc
if: (success() || failure()) && steps.copylivedoc.outcome == 'success'
uses: actions/upload-artifact@v4
with:
name: livedoc
path: livedoc.zip