@@ -114,59 +114,77 @@ jobs:
114114 - name : Start container
115115 id : container
116116 # Try to continue when "exporting to GitHub Actions Cache" failed with timeout
117- if : (success() || failure())
118117 run : |
119118 docker run --name BUILD -dit \
120119 --mount type=bind,src=$(pwd),dst=$(pwd) \
121120 --workdir $(pwd) \
122121 ${{ env.BUILD_IMAGE }} /bin/sh
123122
124123 #
125- # On PRs and pushes to develop
124+ # On pull request and push to develop events
126125 #
127126
127+ - name : Get workflow run-id
128+ id : get_run_id
129+ if : steps.container.outcome == 'success' && !startsWith(github.ref, 'refs/tags/') && github.event_name == 'pull_request'
130+ run : |
131+ RESPONSE=$(curl -s -L \
132+ -H "Accept: application/vnd.github+json" \
133+ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
134+ "https://api.github.com/repos/${{ github.repository }}/actions/runs?event=push&branch=develop&status=completed")
135+ RUN_ID=$(echo "$RESPONSE" | jq -r --arg name "${{ github.workflow }}" --arg conclusion "success" \
136+ '.workflow_runs[] | select(.name == $name and .conclusion == $conclusion) | .id' | head -n 1)
137+ echo "RUN_ID=$RUN_ID" >> $GITHUB_ENV
138+
139+ - name : Download old doc
140+ id : download-doc
141+ if : steps.get_run_id.outcome == 'success'
142+ uses : actions/download-artifact@v4
143+ with :
144+ name : doc-develop
145+ github-token : ${{ secrets.GITHUB_TOKEN }}
146+ repository : ${{ github.repository }}
147+ run-id : ${{ env.RUN_ID }}
148+
128149 - name : Store old doc
129150 id : worktree
130- if : (success() || failure()) && steps.container .outcome == 'success' && !startsWith(github.ref, 'refs/tags/')
151+ if : steps.download-doc .outcome == 'success'
131152 run : |
132153 git config --global --add safe.directory $(pwd)
133154 git config --global user.email "[email protected] " 134155 git config --global user.name "Build documentation workflow"
135- mkdir -p doc
136- # Check if we are on PR
156+ unzip doc.zip
137157 PR_NUMBER=""
138- if [[ -n "$GITHUB_REF" ]]; then
139- if [[ "$GITHUB_REF" =~ refs/pull/([0-9]+)/merge ]]; then
140- PR_NUMBER="${BASH_REMATCH[1]}"
141- fi
158+ if [[ "$GITHUB_REF" =~ refs/pull/([0-9]+)/merge ]]; then
159+ PR_NUMBER="${BASH_REMATCH[1]}"
142160 fi
143- # If so, then prepare to create CHANGES.html
161+ # Create CHANGES.html
144162 if [[ -n "$PR_NUMBER" ]]; then
145163 # mathjax path in old doc (regex)
146164 mathjax_path_from="[-./A-Za-z_]*/tex-chtml[.]js?v=[0-9a-f]*"
147165 # mathjax path in new doc
148166 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)")
149167 new_version=$(docker exec BUILD cat src/VERSION.txt)
150- docker cp BUILD:/sage/local/share/doc/sage/html doc/
151168 # Wipe out chronic diffs between old doc and new doc
152169 (cd doc && \
153170 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]*"/"/ ' \
171+ -e 's; ?v=[0-9a-f]*";"; ' \
155172 -e 's;'"$mathjax_path_from"';'"$mathjax_path_to"';' \
156173 -e '\;<script type="application/vnd\.jupyter\.widget-state+json">;,\;</script>; d' \
157174 -e 's;#L[0-9]*";";' \
175+ -e 's;tab-set--[0-9]*-;tab-set-;' \
158176 && true)
159177 # Create git repo from old doc
160178 (cd doc && \
161179 git init && \
162- (echo "*.svg binary"; echo "*.pdf binary") >> .gitattributes && \
163- (echo ".buildinfo"; echo '*.inv'; echo '.git*'; echo '*.svg'; echo '*.pdf'; echo '*.png'; echo 'searchindex.js') > .gitignore; \
180+ (echo "*.svg binary"; echo "*.pdf binary") > .gitattributes && \
181+ (echo ".buildinfo"; echo '*.inv'; echo '.git*'; echo '*.svg'; echo '*.pdf'; echo '*.png'; echo 'searchindex.js') > .gitignore && \
164182 git add -A && git commit --quiet -m 'old')
165183 fi
166184
167185 - name : Build doc
168186 id : docbuild
169- if : (success() || failure()) && steps.worktree .outcome == 'success' && !startsWith(github.ref, 'refs/tags/')
187+ if : steps.container .outcome == 'success' && !startsWith(github.ref, 'refs/tags/')
170188 # Always non-incremental because of the concern that
171189 # incremental docbuild may introduce broken links (inter-file references) though build succeeds
172190 run : |
@@ -175,18 +193,22 @@ jobs:
175193 export MAKE="make -j5 --output-sync=recurse" SAGE_NUM_THREADS=5
176194 make doc-clean doc-uninstall
177195 export SAGE_USE_CDNS=yes
196+ export SAGE_DOCBUILD_OPTS="--include-tests-blocks"
178197 ./config.status && make sagemath_doc_html-no-deps
179198 shell : sh .ci/docker-exec-script.sh BUILD /sage {0}
180199
181200 - name : Copy doc
182201 id : copy
183- if : (success() || failure()) && steps.docbuild.outcome == 'success'
202+ if : steps.docbuild.outcome == 'success'
184203 run : |
185204 set -ex
186- # We copy everything to a local folder
187- docker cp --follow-link BUILD:/sage/local/share/doc/sage/html doc
188- docker cp --follow-link BUILD:/sage/local/share/doc/sage/index.html doc
189- # Check if we are on PR
205+ # Simpler "docker cp --follow-link ... doc" does not work
206+ mkdir -p doc
207+ mkdir -p temp
208+ docker cp --follow-link BUILD:/sage/local/share/doc/sage/html temp
209+ docker cp --follow-link BUILD:/sage/local/share/doc/sage/index.html temp
210+ cp -r -L temp/* doc/
211+ # Check if we are on pull request event
190212 PR_NUMBER=""
191213 if [[ -n "$GITHUB_REF" ]]; then
192214 if [[ "$GITHUB_REF" =~ refs/pull/([0-9]+)/merge ]]; then
@@ -199,9 +221,10 @@ jobs:
199221 # Wipe out chronic diffs of new doc against old doc before creating CHANGES.html
200222 (cd doc && \
201223 find . -name "*.html" | xargs sed -i -e '/This is documentation/ s/ built with GitHub PR .* for development/ for development/' \
202- -e '/<link rel="stylesheet"/ s/ ?v=[0-9a-f]*"/"/ ' \
224+ -e 's; ?v=[0-9a-f]*";"; ' \
203225 -e '\;<script type="application/vnd\.jupyter\.widget-state+json">;,\;</script>; d' \
204226 -e 's;#L[0-9]*";";' \
227+ -e 's;tab-set--[0-9]*-;tab-set-;' \
205228 && git commit -a -m 'wipe-out')
206229 # Since HEAD is at commit 'wipe-out', HEAD~1 is commit 'new' (new doc), HEAD~2 is commit 'old' (old doc)
207230 (cd doc && git diff $(git rev-parse HEAD~2) -- "*.html") > diff.txt
@@ -221,20 +244,31 @@ jobs:
221244
222245 - name : Upload doc
223246 id : upload
224- if : (success() || failure()) && steps.copy.outcome == 'success'
247+ if : steps.copy.outcome == 'success'
225248 uses : actions/upload-artifact@v4
226249 with :
227250 name : doc
228251 path : doc.zip
229252
253+ - name : Upload doc-develop
254+ # artifact doc-develop is used for doc build on pull request event
255+ id : upload-push
256+ if : steps.copy.outcome == 'success' && github.event_name == 'push'
257+ uses : actions/upload-artifact@v4
258+ with :
259+ name : doc-${{ github.ref_name }}
260+ path : doc.zip
261+
230262 #
231- # On release tags: live doc and wheels
263+ # On release tag event
232264 #
233265
234266 - name : Build live doc
235267 id : buildlivedoc
236- if : (success() || failure()) && startsWith(github.ref, 'refs/tags/')
268+ if : startsWith(github.ref, 'refs/tags/')
237269 run : |
270+ # Avoid running out of disk space
271+ rm -rf upstream
238272 export MAKE="make -j5 --output-sync=recurse" SAGE_NUM_THREADS=5
239273 export PATH="build/bin:$PATH"
240274 eval $(sage-print-system-package-command auto update)
@@ -249,7 +283,7 @@ jobs:
249283
250284 - name : Copy live doc
251285 id : copylivedoc
252- if : (success() || failure()) && steps.buildlivedoc.outcome == 'success'
286+ if : steps.buildlivedoc.outcome == 'success'
253287 run : |
254288 mkdir -p ./livedoc
255289 # We copy everything to a local folder
@@ -259,7 +293,7 @@ jobs:
259293 zip -r livedoc.zip livedoc
260294
261295 - name : Upload live doc
262- if : (success() || failure()) && steps.copylivedoc.outcome == 'success'
296+ if : steps.copylivedoc.outcome == 'success'
263297 uses : actions/upload-artifact@v4
264298 with :
265299 name : livedoc
0 commit comments