forked from sagemath/sage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sagemathgh-36483: Remove spurious diffs in doc build changes
Remove all spurious and chronic diffs in the changes of our documentation preview. Improve CHANGES.html using diffsite. See https://deploy-preview-36483-- sagemath-tobias.netlify.app/changes diffsite allows to compare changes visually. Scroll until vertical alignment breaks or search for some diff text. <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes sagemath#1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes sagemath#12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - sagemath#12345: short description why this is a dependency - sagemath#34567: ... --> - sagemath#36475 <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: sagemath#36483 Reported by: Kwankyu Lee Reviewer(s): Matthias Köppe
- Loading branch information
Showing
28 changed files
with
214 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,13 +56,19 @@ jobs: | |
git config --global --add safe.directory $(pwd) | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "Build & Test workflow" | ||
# mathjax path in old doc | ||
mathjax_path_from=$(SAGE_USE_CDNS=no /sage/sage -python -c "from sage_docbuild.conf import mathjax_path; print(mathjax_path)") | ||
.ci/retrofit-worktree.sh worktree-image /sage | ||
# Keep track of changes to built HTML | ||
new_version=$(cat src/VERSION.txt) | ||
# mathjax path in new doc | ||
mathjax_path_to=$(SAGE_USE_CDNS=yes /sage/sage -python -c "from sage_docbuild.conf import mathjax_path; print(mathjax_path)") | ||
new_version=$(cat src/VERSION.txt) | ||
# Wipe out chronic diffs between old doc and new doc | ||
(cd /sage/local/share/doc/sage/html/en && \ | ||
find . -name "*.html" | xargs sed -i -e '/class="sidebar-brand-text"/ s/Sage [0-9a-z.]* /Sage '"$new_version"' /' \ | ||
-e 's;'"$mathjax_path_from"';'"$mathjax_path_to"';' \ | ||
-e '\;<script type="application/vnd\.jupyter\.widget-state+json">;,\;</script>; d') | ||
# Create git repo from old doc | ||
(cd /sage/local/share/doc/sage/html/en && \ | ||
find . -name "*.html" | xargs sed -i '/class="sidebar-brand-text"/s/Sage [0-9a-z.]* /Sage '$new_version' /;s,'$mathjax_path_from,$mathjax_path_to,';'; \ | ||
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; \ | ||
|
@@ -125,12 +131,58 @@ jobs: | |
run: | | ||
set -ex | ||
mkdir -p ./docs | ||
# Create changelog | ||
echo '## Preview of CHANGES.html' | ||
(cd /sage/local/share/doc/sage/html/en && git diff --name-only) | tee ./docs/CHANGES.txt | ||
(cd /sage/local/share/doc/sage/html/en && git diff; rm -rf .git) > ./docs/html.diff | ||
echo '## Preview of html.diff'; head -n 400 ./docs/html.diff | ||
(echo '<p><a href="html.diff">HTML diff</a>'; sed -E 's,(.*),<p><a href="\1">\1</a>,' ./docs/CHANGES.txt) > ./docs/CHANGES.html | ||
(cd /sage/local/share/doc/sage/html/en && git commit -a -m 'new') | ||
# Wipe out chronic diffs between old doc and new doc | ||
(cd /sage/local/share/doc/sage/html/en && \ | ||
find . -name "*.html" | xargs sed -i -e '\;<script type="application/vnd\.jupyter\.widget-state+json">;,\;</script>; d') | ||
# Create CHANGES.html | ||
echo '<html>' > ./docs/CHANGES.html | ||
echo '<head>' >> ./docs/CHANGES.html | ||
echo '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">' >> ./docs/CHANGES.html | ||
echo '<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>' >> ./docs/CHANGES.html | ||
echo '<script>hljs.highlightAll();</script>' >> ./docs/CHANGES.html | ||
cat >> ./docs/CHANGES.html << EOF | ||
<script> | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const diffSite = 'https://pianomister.github.io/diffsite/' | ||
const baseDocURL = 'https://sagemath-tobias.netlify.app/' | ||
const diffParagraphs = document.querySelectorAll('p.diff'); | ||
diffParagraphs.forEach(paragraph => { | ||
const rootURL = window.location.origin + '/'; | ||
const docAnchor = paragraph.querySelector('a'); | ||
const path = docAnchor.textContent; // .href doesn't work | ||
const anchor = document.createElement('a'); | ||
anchor.href = diffSite + '?url1=' + rootURL + path + '&url2=' + baseDocURL + path; | ||
anchor.textContent = 'compare with the base'; | ||
anchor.setAttribute('target', '_blank'); | ||
paragraph.appendChild(anchor); | ||
}); | ||
}); | ||
</script> | ||
EOF | ||
echo '</head>' >> ./docs/CHANGES.html | ||
echo '<body>' >> ./docs/CHANGES.html | ||
(cd /sage/local/share/doc/sage/html/en && git diff HEAD^; rm -rf .git) > ./docs/diff.txt | ||
/sage/sage -python - << EOF | ||
import re, html | ||
with open('./docs/diff.txt', 'r') as f: | ||
diff_text = f.read() | ||
diff_blocks = re.split(r'^(?=diff --git)', diff_text, flags=re.MULTILINE) | ||
out_blocks = [] | ||
for block in diff_blocks: | ||
match = re.search(r'^diff --git a/(.*) b/\1', block, flags=re.MULTILINE) | ||
if match: | ||
path = match.group(1) | ||
out_blocks.append(f'<p class="diff"><a href="{path}">{path}</a> </p>\n<pre><code class="language-diff">' + html.escape(block).strip() + '</code></pre>') | ||
output_text = '\n'.join(out_blocks) | ||
with open('./docs/diff.html', 'w') as f: | ||
f.write(output_text) | ||
EOF | ||
cat ./docs/diff.html >> ./docs/CHANGES.html | ||
echo '</body>' >> ./docs/CHANGES.html | ||
echo '</html>' >>./docs/CHANGES.html | ||
rm ./docs/diff.txt ./docs/diff.html | ||
(cd /sage/local/share/doc/sage/html/en && git reset --hard HEAD) | ||
# For some reason the deploy step below cannot find /sage/... | ||
# So copy everything from there to local folder | ||
# We also need to replace the symlinks because netlify is not following them | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.