@@ -132,25 +132,35 @@ jobs:
132132 git config --global --add safe.directory $(pwd)
133133 git config --global user.email "[email protected] " 134134 git config --global user.name "Build documentation workflow"
135- # mathjax path in old doc (regex)
136- mathjax_path_from="[-./A-Za-z_]*/tex-chtml[.]js?v=[0-9a-f]*"
137- # mathjax path in new doc
138- 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)")
139- new_version=$(docker exec BUILD cat src/VERSION.txt)
140- mkdir -p doc/
141- docker cp BUILD:/sage/local/share/doc/sage/html doc/
142- # Wipe out chronic diffs between old doc and new doc
143- (cd doc && \
144- find . -name "*.html" | xargs sed -i -e '/class="sidebar-brand-text"/ s/Sage [0-9a-z.]* /Sage '"$new_version"' /' \
145- -e '/<link rel="stylesheet"/ s/?v=[0-9a-f]*"/"/' \
146- -e 's;'"$mathjax_path_from"';'"$mathjax_path_to"';' \
147- -e '\;<script type="application/vnd\.jupyter\.widget-state+json">;,\;</script>; d')
148- # Create git repo from old doc
149- (cd doc && \
150- git init && \
151- (echo "*.svg binary"; echo "*.pdf binary") >> .gitattributes && \
152- (echo ".buildinfo"; echo '*.inv'; echo '.git*'; echo '*.svg'; echo '*.pdf'; echo '*.png'; echo 'searchindex.js') > .gitignore; \
153- git add -A && git commit --quiet -m 'old')
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
154164
155165 - name : Build doc
156166 id : docbuild
@@ -174,21 +184,31 @@ jobs:
174184 # We copy everything to a local folder
175185 docker cp --follow-link BUILD:/sage/local/share/doc/sage/html doc
176186 docker cp --follow-link BUILD:/sage/local/share/doc/sage/index.html doc
177- (cd doc && git commit -a -m 'new')
178- # Wipe out chronic diffs of new doc against old doc before creating CHANGES.html
179- (cd doc && \
180- find . -name "*.html" | xargs sed -i -e '/This is documentation for/ s/ built with GitHub PR .*. Doc/. Doc/' \
181- -e '/<link rel="stylesheet"/ s/?v=[0-9a-f]*"/"/' \
182- -e '\;<script type="application/vnd\.jupyter\.widget-state+json">;,\;</script>; d' \
183- && git commit -a -m 'wipe-out')
184- # Since HEAD is at commit 'wipe-out', HEAD~1 is commit 'new' (new doc), HEAD~2 is commit 'old' (old doc)
185- .ci/create-changes-html.sh $(cd doc && git rev-parse HEAD~2) doc
186- # Restore the new doc with changes made in create-changes-html.sh but dropping changes by "wipe out"
187- (cd doc && git stash -q && git checkout -q -f HEAD~1 && git stash pop -q)
188- # Sometimes rm -rf .git errors out because of some diehard hidden files
189- # So we simply move it out of the doc directory
190- (cd doc && mv .git ../git && mv .gitattributes ../gitattributes)
191- mv CHANGES.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
192212 # Zip everything for increased performance
193213 zip -r doc.zip doc
194214
@@ -228,7 +248,7 @@ jobs:
228248 # We copy everything to a local folder
229249 docker cp --follow-link BUILD:/sage/local/share/doc/sage/html livedoc
230250 docker cp --follow-link BUILD:/sage/local/share/doc/sage/pdf livedoc
231- 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
232252 zip -r livedoc.zip livedoc
233253
234254 - name : Upload live doc
0 commit comments