Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add announcement banner also for PRs over stable release #38332

Merged
merged 34 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
fd92c05
Fix doc build for releases
kwankyu Jun 23, 2024
748ff77
No master branch
kwankyu Jun 23, 2024
fd31453
Add more if
kwankyu Jun 23, 2024
e7a64ff
Fix doc-pdf
kwankyu Jun 23, 2024
7fa8c48
Only pushes to develop
kwankyu Jun 23, 2024
6e64826
Add a comment
kwankyu Jun 23, 2024
10f0fa6
Add more comments
kwankyu Jun 23, 2024
1374064
Fix random error by replacing rm by mv
kwankyu Jun 24, 2024
11ce8cc
Deploy twice to have a way to refer to doc latest
kwankyu Jun 24, 2024
c2eb28c
Fix broken changes.html
kwankyu Jun 25, 2024
990ac7d
Add version selector
kwankyu Jun 27, 2024
e06401a
Add current version at top
kwankyu Jun 30, 2024
4d75b1b
Add more old docs
kwankyu Jun 30, 2024
99de93f
Fetch versions.txt from doc-release--sagemath.netlify.app
kwankyu Jul 1, 2024
c8339a8
Store versions.txt in src/doc/en/website
kwankyu Jul 1, 2024
a14b215
Initially do not display selector
kwankyu Jul 1, 2024
0ef948c
Small fix
kwankyu Jul 1, 2024
2350f16
Add _headers file to avoid CORS problem
kwankyu Jul 1, 2024
2f509c2
Improve style
kwankyu Jul 1, 2024
bb228b3
Fix versions.txt
kwankyu Jul 1, 2024
c3dc3c1
Fix errors
kwankyu Jul 1, 2024
687c4f0
Put version selector in the left sidebar
kwankyu Jul 2, 2024
4087242
Insert develop version on the fly
kwankyu Jul 2, 2024
67729be
Backing up
kwankyu Jul 2, 2024
02fcfe4
Fix css
kwankyu Jul 2, 2024
e9d58da
Fix doc-release url
kwankyu Jul 2, 2024
e01bc4e
Squeeze fetch-related error
kwankyu Jul 2, 2024
ed0c21e
Improve version selector for local doc
kwankyu Jul 2, 2024
a9decf4
Announcement banner also for PRs over stable release
kwankyu Jul 3, 2024
a51b571
Change 'of' back to 'for'
kwankyu Jul 3, 2024
9b272c0
Provision for merge before 10.4 release
kwankyu Jul 3, 2024
663dc45
Merge branch 'develop' into p/38285/add-version-selector-top
kwankyu Jul 5, 2024
ed3e1f1
Merge branch 'p/38285/add-version-selector-top' into p/38332/improve-…
kwankyu Jul 5, 2024
30638a1
Delete a spurious space
kwankyu Jul 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 55 additions & 35 deletions .github/workflows/doc-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,25 +132,35 @@ jobs:
git config --global --add safe.directory $(pwd)
git config --global user.email "[email protected]"
git config --global user.name "Build documentation workflow"
# 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)
mkdir -p doc/
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')
# 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')
# 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)
mkdir -p doc/
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')
# 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
Expand All @@ -174,21 +184,31 @@ jobs:
# 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
(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 for/ s/ built with GitHub PR .*. Doc/. Doc/' \
-e '/<link rel="stylesheet"/ s/?v=[0-9a-f]*"/"/' \
-e '\;<script type="application/vnd\.jupyter\.widget-state+json">;,\;</script>; d' \
&& 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)
.ci/create-changes-html.sh $(cd doc && git rev-parse HEAD~2) doc
# Restore the new doc with changes made in create-changes-html.sh but dropping changes by "wipe out"
(cd doc && git stash -q && git checkout -q -f HEAD~1 && git stash pop -q)
# 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
# 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 of/ 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' \
&& 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)
.ci/create-changes-html.sh $(cd doc && git rev-parse HEAD~2) doc
# Restore the new doc with changes made in create-changes-html.sh but dropping changes by "wipe out"
(cd doc && git stash -q && git checkout -q -f HEAD~1 && git stash pop -q)
# 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
# Zip everything for increased performance
zip -r doc.zip doc

Expand Down Expand Up @@ -228,7 +248,7 @@ jobs:
# 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 BUILD:/sage/local/share/doc/sage/index.html livedoc
docker cp --follow-link BUILD:/sage/local/share/doc/sage/index.html livedoc
zip -r livedoc.zip livedoc

- name: Upload live doc
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/doc-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ jobs:
run: unzip livedoc.zip -d livedoc
if: steps.download-doc.outcome == 'success'

- name: Create _headers file for permissive CORS
run: |
cat <<EOF > livedoc/livedoc/_headers
/*
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
Access-Control-Allow-Headers: Content-Type
EOF
if: steps.download-doc.outcome == 'success'

- name: Deploy to netlify with doc-TAG alias
id: deploy-netlify
uses: netlify/actions/cli@master
Expand Down
20 changes: 20 additions & 0 deletions src/bin/sage-update-version
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,25 @@ export SAGE_VERSION
export SAGE_RELEASE_DATE
envsubst <"$SAGE_ROOT/CITATION.cff.in" >"$SAGE_ROOT/CITATION.cff"

# Update src/doc/versions.txt file storing the URLs of the docs for the recent stable releases
if [[ $SAGE_VERSION =~ ^[0-9]+(\.[0-9]+)*$ ]]; then
file_path="$SAGE_ROOT/src/doc/en/website/versions.txt"
# Extract the most recent version line from versions.txt
line_number=$(grep -n '^[0-9]' "$file_path" | head -n 1 | cut -d: -f1)
version_line=$(sed -n "${line_number}p" "$file_path")
domain=${version_line#*--}
version=${SAGE_VERSION//./-}
# For the origin of this format, see .github/workflows/doc-publish.yml
url="doc-$version--$domain"
# Add new line to versions.txt
sed -i "${line_number}i $SAGE_VERSION $url" "$file_path"
# If the number of version lines is more than 10, remove the last line
line_count=$(grep -c '^[0-9]' "$file_path")
if [ "$line_count" -gt 10 ]; then
sed -i '$ d' "$file_path"
fi
fi

# Commit auto-generated changes
git commit -m "Updated SageMath version to $SAGE_VERSION" -- \
"$SAGE_ROOT/VERSION.txt" \
Expand All @@ -124,6 +143,7 @@ git commit -m "Updated SageMath version to $SAGE_VERSION" -- \
"$SAGE_ROOT/build/pkgs/*/version_requirements.txt" \
"$SAGE_ROOT"/pkgs/*/VERSION.txt \
"$SAGE_ROOT/.upstream.d/20-github.com-sagemath-sage-releases" \
"$SAGE_ROOT/src/doc/en/website/versions.txt" \
|| die "Error committing to the repository."

git tag -a "$SAGE_VERSION" -m "$SAGE_VERSION_BANNER" \
Expand Down
47 changes: 43 additions & 4 deletions src/doc/common/static/custom-furo.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,53 @@ a.pdf:hover {
/* Style for announcement banner */

.announcement {
background: orange;
background: orange;
}

.announcement-content {
color: black;
color: black;
}

.announcement-content a {
color: white;
text-decoration: none;
color: white;
text-decoration: none;
}

/* Style for the floating versions menu */

.sidebar-drawer {
z-index: 100;
}

.select-wrapper {
display: block;
text-align: center;
}

#versions-menu {
display: inline-block;
font-size: small;
opacity: 1;
border: none;
background-color: transparent;
color: var(--color-sidebar-link-text--top-level);;
}

#versions-menu:focus {
outline: none;
}

body[data-theme="dark"] {
#versions-menu {
background-color: transparent;
}
}

@media (prefers-color-scheme: dark) {
body[data-theme="auto"] { /* the same styles with body[data-theme="dark"] */
#versions-menu {
background-color: transparent;
}
}
}

72 changes: 36 additions & 36 deletions src/doc/common/static/custom-jupyter-sphinx.css
Original file line number Diff line number Diff line change
Expand Up @@ -96,41 +96,41 @@ body[data-theme="dark"] {
}

@media (prefers-color-scheme: dark) {
body[data-theme="auto"] { /* the same styles with body[data-theme="dark"] */
.jupyter_container {
color: white;
background-color: black;
}

.jupyter_container .highlight {
background-color: black;
}

.thebelab-button {
color: #d0d0d0;
background-color: #383838;
}

.thebelab-button:active {
color: #368ce2;
}

#thebelab-activate-button {
background-color: #383838;
}

#thebelab-activate-button:active {
color: #368ce2;
}

.thebelab-cell .jp-OutputArea-output {
color: white;
background-color: black;
}

.thebelab-cell .jp-OutputArea-output pre {
color: white;
background-color: black;
body[data-theme="auto"] { /* the same styles with body[data-theme="dark"] */
.jupyter_container {
color: white;
background-color: black;
}

.jupyter_container .highlight {
background-color: black;
}

.thebelab-button {
color: #d0d0d0;
background-color: #383838;
}

.thebelab-button:active {
color: #368ce2;
}

#thebelab-activate-button {
background-color: #383838;
}

#thebelab-activate-button:active {
color: #368ce2;
}

.thebelab-cell .jp-OutputArea-output {
color: white;
background-color: black;
}

.thebelab-cell .jp-OutputArea-output pre {
color: white;
background-color: black;
}
}
}
}
65 changes: 65 additions & 0 deletions src/doc/common/static/jupyter-sphinx-furo.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,71 @@ const observer2 = new MutationObserver(callback);
observer2.observe(document.getElementsByClassName("content")[0], { childList: true, subtree: true });


//
// Version selector
//

function fetchVersions() {
try {
let menu = document.getElementById('versions-menu');

// For the origin of the this site, see .github/workflows/doc-publish.yml
fetch('https://doc-release--sagemath.netlify.app/html/en/versions.txt')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
}
return response.text();
})
.then(text => {
const lines = text.split('\n');
lines.forEach(line => {
if (!line.startsWith('#')) { // Ignore the comment line
let [ver, url] = line.split(' ');
if (ver && url) {
if (!url.startsWith('https://')) {
url = 'https://' + url;
}
let option = document.createElement('option');
option.value = url;
option.text = ver;
menu.add(option);
}
}
});
})
.catch(error => {
console.log('Failed to fetch versions.txt file.');
});
} catch (error) {
console.log('Failed to fetch versions.txt file.');
}
}

fetchVersions()

// Function to change the version based on versions menu selection
function changeVersion() {
let select_element = document.getElementById("versions-menu");
let selected_ver = select_element.options[select_element.selectedIndex].text;
let selected_url = select_element.value;
if (selected_url) {
if (window.location.protocol == 'file:') {
let pathname = window.location.pathname;
let cutoff_point = pathname.indexOf('doc/sage');
if (cutoff_point !== -1) {
pathname = pathname.substring(cutoff_point + 8);
window.location.href = selected_url + pathname;
} else {
window.location.href = selected_url + 'html/en/index.html';
}
} else {
window.location.href = selected_url + window.location.pathname;
}
}
}


// Listen to the kernel status changes
// https://thebe.readthedocs.io/en/stable/events.html
thebelab.on("status", function (evt, data) {
Expand Down
6 changes: 6 additions & 0 deletions src/doc/common/templates-furo/sidebar/version-selector.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="select-wrapper">
<select id="versions-menu" onchange="changeVersion()">
<option value="" selected>other version</option>
<option value="https://doc-develop--sagemath.netlify.app">develop</option>
</select>
</div>
16 changes: 16 additions & 0 deletions src/doc/en/website/versions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file is used by the version selector of the Sage doc
# and updated by the script src/bin/sage-update-version
#
# The lines are for recent stable releases (at most 10 lines)
# A line consists of the version and the URL to the doc
#
# The sage-update-version script adds a new line for a new stable release
# when run by the Sage release manager to prepare a new release
#
10.3 doc-10-3--sagemath.netlify.app
10.2 doc-10-2--sagemath.netlify.app
10.1 doc-10-1--sagemath.netlify.app
10.0 doc-10-0--sagemath.netlify.app
9.8 doc-9-8--sagemath.netlify.app
9.7 doc-9-7--sagemath.netlify.app
9.6 doc-9-6--sagemath.netlify.app
Loading
Loading