44 pull_request :
55 merge_group :
66 push :
7+ tags :
8+ # Match all release tags including beta, rc
9+ - ' [0-9]+.[0-9]+'
10+ - ' [0-9]+.[0-9]+.[0-9]+'
11+ - ' [0-9]+.[0-9]+.beta[0-9]+'
12+ - ' [0-9]+.[0-9]+.[0-9]+.beta[0-9]+'
13+ - ' [0-9]+.[0-9]+.rc[0-9]+'
14+ - ' [0-9]+.[0-9]+.[0-9]+.rc[0-9]+'
715 branches :
8- - master
916 - develop
1017 workflow_dispatch :
1118 # Allow to run manually
3441 EXTRA_CONFIGURE_ARGS : --enable-fat-binary
3542
3643jobs :
37- build-docs :
44+ build-doc :
3845 runs-on : ubuntu-latest
3946 services :
4047 # https://docs.docker.com/build/ci/github-actions/local-registry/
@@ -114,38 +121,50 @@ jobs:
114121 --workdir $(pwd) \
115122 ${{ env.BUILD_IMAGE }} /bin/sh
116123
117- # Docs
124+ #
125+ # On PRs and pushes to develop
126+ #
118127
119- - name : Store old docs
128+ - name : Store old doc
120129 id : worktree
121- if : (success() || failure()) && steps.container.outcome == 'success'
130+ if : (success() || failure()) && steps.container.outcome == 'success' && !startsWith(github.ref, 'refs/tags/')
122131 run : |
123132 git config --global --add safe.directory $(pwd)
124133 git config --global user.email "ci-sage@example.com"
125134 git config --global user.name "Build documentation workflow"
126- # mathjax path in old doc (regex)
127- mathjax_path_from="[-./A-Za-z_]*/tex-chtml[.]js?v=[0-9a-f]*"
128- # mathjax path in new doc
129- 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)")
130- new_version=$(docker exec BUILD cat src/VERSION.txt)
131- mkdir -p docs/
132- docker cp BUILD:/sage/local/share/doc/sage/html docs/
133- # Wipe out chronic diffs of old doc against new doc
134- (cd docs && \
135- find . -name "*.html" | xargs sed -i -e '/class="sidebar-brand-text"/ s/Sage [0-9a-z.]* /Sage '"$new_version"' /' \
136- -e '/<link rel="stylesheet"/ s/?v=[0-9a-f]*"/"/' \
137- -e 's;'"$mathjax_path_from"';'"$mathjax_path_to"';' \
138- -e '\;<script type="application/vnd\.jupyter\.widget-state+json">;,\;</script>; d')
139- # Create git repo from old doc
140- (cd docs && \
141- git init && \
142- (echo "*.svg binary"; echo "*.pdf binary") >> .gitattributes && \
143- (echo ".buildinfo"; echo '*.inv'; echo '.git*'; echo '*.svg'; echo '*.pdf'; echo '*.png'; echo 'searchindex.js') > .gitignore; \
144- git add -A && git commit --quiet -m "old")
145-
146- - name : Build docs
135+ # Check if we are on PR
136+ PR_NUMBER=""
137+ if [[ -n "$GITHUB_REF" ]]; then
138+ if [[ "$GITHUB_REF" =~ refs/pull/([0-9]+)/merge ]]; then
139+ PR_NUMBER="${BASH_REMATCH[1]}"
140+ fi
141+ fi
142+ # If so, then prepare to create CHANGES.html
143+ if [[ -n "$PR_NUMBER" ]]; then
144+ # mathjax path in old doc (regex)
145+ mathjax_path_from="[-./A-Za-z_]*/tex-chtml[.]js?v=[0-9a-f]*"
146+ # mathjax path in new doc
147+ 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)")
148+ new_version=$(docker exec BUILD cat src/VERSION.txt)
149+ mkdir -p doc/
150+ docker cp BUILD:/sage/local/share/doc/sage/html doc/
151+ # Wipe out chronic diffs between old doc and new doc
152+ (cd doc && \
153+ find . -name "*.html" | xargs sed -i -e '/class="sidebar-brand-text"/ s/Sage [0-9a-z.]* /Sage '"$new_version"' /' \
154+ -e '/<link rel="stylesheet"/ s/?v=[0-9a-f]*"/"/' \
155+ -e 's;'"$mathjax_path_from"';'"$mathjax_path_to"';' \
156+ -e '\;<script type="application/vnd\.jupyter\.widget-state+json">;,\;</script>; d')
157+ # Create git repo from old doc
158+ (cd doc && \
159+ git init && \
160+ (echo "*.svg binary"; echo "*.pdf binary") >> .gitattributes && \
161+ (echo ".buildinfo"; echo '*.inv'; echo '.git*'; echo '*.svg'; echo '*.pdf'; echo '*.png'; echo 'searchindex.js') > .gitignore; \
162+ git add -A && git commit --quiet -m 'old')
163+ fi
164+
165+ - name : Build doc
147166 id : docbuild
148- if : (success() || failure()) && steps.worktree.outcome == 'success'
167+ if : (success() || failure()) && steps.worktree.outcome == 'success' && !startsWith(github.ref, 'refs/tags/')
149168 # Always non-incremental because of the concern that
150169 # incremental docbuild may introduce broken links (inter-file references) though build succeeds
151170 run : |
@@ -157,50 +176,57 @@ jobs:
157176 ./config.status && make sagemath_doc_html-no-deps
158177 shell : sh .ci/docker-exec-script.sh BUILD /sage {0}
159178
160- - name : Copy docs
179+ - name : Copy doc
161180 id : copy
162181 if : (success() || failure()) && steps.docbuild.outcome == 'success'
163182 run : |
164183 set -ex
165184 # We copy everything to a local folder
166- docker cp BUILD:/sage/local/share/doc/sage/html docs
167- docker cp BUILD:/sage/local/share/doc/sage/index.html docs
168- (cd docs && git commit -a -m 'new')
169- # Wipe out chronic diffs of new doc against old doc
170- (cd docs && \
171- find . -name "*.html" | xargs sed -i -e '/This is documentation for/ s/ built with GitHub PR .*. Doc/. Doc/' \
172- -e '/<link rel="stylesheet"/ s/?v=[0-9a-f]*"/"/')
173- .ci/create-changes-html.sh $(cd docs && git rev-parse HEAD^) docs
174- # Restore the new doc from changes by "wipe out"
175- (cd docs && git checkout -f)
176- (cd docs && rm -rf .git)
177- mv CHANGES.html docs
178- # We also need to replace the symlinks because netlify is not following them
179- # CHECK IF STILL NEEDED
180- #cp -r -L $DOC_DIR ./docs
185+ docker cp --follow-link BUILD:/sage/local/share/doc/sage/html doc
186+ docker cp --follow-link BUILD:/sage/local/share/doc/sage/index.html doc
187+ # Check if we are on PR
188+ PR_NUMBER=""
189+ if [[ -n "$GITHUB_REF" ]]; then
190+ if [[ "$GITHUB_REF" =~ refs/pull/([0-9]+)/merge ]]; then
191+ PR_NUMBER="${BASH_REMATCH[1]}"
192+ fi
193+ fi
194+ # If so, then create CHANGES.html
195+ if [[ -n "$PR_NUMBER" ]]; then
196+ (cd doc && git commit -a -m 'new')
197+ # Wipe out chronic diffs of new doc against old doc before creating CHANGES.html
198+ (cd doc && \
199+ find . -name "*.html" | xargs sed -i -e '/This is documentation of/ s/ built with GitHub PR .* for development/ for development/' \
200+ -e '/<link rel="stylesheet"/ s/?v=[0-9a-f]*"/"/' \
201+ -e '\;<script type="application/vnd\.jupyter\.widget-state+json">;,\;</script>; d' \
202+ && git commit -a -m 'wipe-out')
203+ # Since HEAD is at commit 'wipe-out', HEAD~1 is commit 'new' (new doc), HEAD~2 is commit 'old' (old doc)
204+ .ci/create-changes-html.sh $(cd doc && git rev-parse HEAD~2) doc
205+ # Restore the new doc with changes made in create-changes-html.sh but dropping changes by "wipe out"
206+ (cd doc && git stash -q && git checkout -q -f HEAD~1 && git stash pop -q)
207+ # Sometimes rm -rf .git errors out because of some diehard hidden files
208+ # So we simply move it out of the doc directory
209+ (cd doc && mv .git ../git && mv .gitattributes ../gitattributes)
210+ mv CHANGES.html doc
211+ fi
181212 # Zip everything for increased performance
182- zip -r docs .zip docs
213+ zip -r doc .zip doc
183214
184- - name : Upload docs
215+ - name : Upload doc
185216 id : upload
186217 if : (success() || failure()) && steps.copy.outcome == 'success'
187- uses : actions/upload-artifact@v3
218+ uses : actions/upload-artifact@v4
188219 with :
189- name : docs
190- path : docs .zip
220+ name : doc
221+ path : doc .zip
191222
192- - name : Save space
193- id : savespace
194- if : (success() || failure()) && steps.upload.outcome == 'success' && github.repository == 'sagemath/sage' && github.ref == 'refs/heads/develop'
195- run : |
196- set -ex
197- # Save space on runner device before we start to build livedoc
198- rm -rf docs/
199- rm -f docs.zip
223+ #
224+ # On release tags: live doc and wheels
225+ #
200226
201227 - name : Build live doc
202228 id : buildlivedoc
203- if : (success() || failure()) && steps.savespace.outcome == 'success'
229+ if : (success() || failure()) && startsWith(github.ref, 'refs/tags/')
204230 run : |
205231 export MAKE="make -j5 --output-sync=recurse" SAGE_NUM_THREADS=5
206232 export PATH="build/bin:$PATH"
@@ -222,12 +248,12 @@ jobs:
222248 # We copy everything to a local folder
223249 docker cp --follow-link BUILD:/sage/local/share/doc/sage/html livedoc
224250 docker cp --follow-link BUILD:/sage/local/share/doc/sage/pdf livedoc
225- docker cp BUILD:/sage/local/share/doc/sage/index.html livedoc
251+ docker cp --follow-link BUILD:/sage/local/share/doc/sage/index.html livedoc
226252 zip -r livedoc.zip livedoc
227253
228254 - name : Upload live doc
229255 if : (success() || failure()) && steps.copylivedoc.outcome == 'success'
230- uses : actions/upload-artifact@v3
256+ uses : actions/upload-artifact@v4
231257 with :
232258 name : livedoc
233259 path : livedoc.zip
0 commit comments