Skip to content

Commit 33b2c79

Browse files
committed
Improve announcement banner
1 parent e5f42fa commit 33b2c79

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

.github/workflows/doc-build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ jobs:
129129
# Wipe out chronic diffs between old doc and new doc
130130
(cd docs && \
131131
find . -name "*.html" | xargs sed -i -e '/class="sidebar-brand-text"/ s/Sage [0-9a-z.]* /Sage '"$new_version"' /' \
132+
-e '/This is documentation for/ s/ built with GitHub PR [^.]*././' \
132133
-e 's;'"$mathjax_path_from"';'"$mathjax_path_to"';' \
133134
-e '\;<script type="application/vnd\.jupyter\.widget-state+json">;,\;</script>; d')
134135
# Create git repo from old doc
@@ -143,6 +144,8 @@ jobs:
143144
# Always non-incremental because of the concern that
144145
# incremental docbuild may introduce broken links (inter-file references) though build succeeds
145146
run: |
147+
export GITHUB_REF=${{ github.ref }}
148+
export GITHUB_SHA=${{ github.sha }}
146149
export MAKE="make -j5 --output-sync=recurse" SAGE_NUM_THREADS=5
147150
make doc-clean doc-uninstall
148151
export SAGE_USE_CDNS=yes

.github/workflows/doc-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
6262
NETLIFY_PRODUCTION: ${{ github.ref == 'refs/heads/develop' }}
6363
NETLIFY_MESSAGE: ${{ steps.source-run-info.outputs.pullRequestNumber }}
64-
NETLIFY_ALIAS: deploy-preview-${{ steps.source-run-info.outputs.pullRequestNumber }}
64+
NETLIFY_ALIAS: preview-${{ steps.source-run-info.outputs.pullRequestNumber }}
6565

6666
# Add deployment as status check, PR comment and annotation
6767
# we could use the nwtgck/actions-netlify action for that, except for that it is not (yet) working in workflow_run context: https://github.com/nwtgck/actions-netlify/issues/545
@@ -130,7 +130,7 @@ jobs:
130130
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
131131
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
132132
NETLIFY_MESSAGE: Deployed live doc
133-
NETLIFY_ALIAS: deploy-livedoc
133+
NETLIFY_ALIAS: livedoc
134134

135135
- name: Report deployment url
136136
run: |

src/sage_docbuild/conf.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import sys
2222
import os
23+
import re
2324
import importlib
2425
import dateutil.parser
2526
import sphinx
@@ -441,11 +442,24 @@ def linkcode_resolve(domain, info):
441442
}
442443

443444
if not version.split('.')[-1].isnumeric(): # develop version
444-
html_theme_options.update({
445-
"announcement": f'This is documentation for Sage development version {version}. '
446-
'The documentation for the latest stable version is available '
447-
'<a href="https://doc.sagemath.org/html/en/index.html">here</a>.'
448-
})
445+
ver = f'<a href="https://livedoc--sagemath.netlify.app/html/en/index.html">{version}</a>'
446+
github_ref = os.environ.get('GITHUB_REF', '')
447+
if github_ref:
448+
match = re.search(r'refs/pull/(\d+)/merge', github_ref)
449+
if match:
450+
# As this doc is built for a GitHub PR, we plant a link
451+
# to the PR in the announcement banner.
452+
pr_number = match.group(1)
453+
pr_url = f'https://github.com/sagemath/sage/pull/{pr_number}'
454+
pr_sha = os.environ.get('GITHUB_SHA', '')
455+
pr_commit = pr_url + f'/commits/{pr_sha}'
456+
ver += f' built with GitHub PR <a href="{pr_url}">#{pr_number}</a>' \
457+
f' on <a href="{pr_commit}">{pr_sha[:7]}</a>' \
458+
f' [<a href="/changes.html">changes</a>]'
459+
banner = f'This is documentation for Sage development version {ver}. ' \
460+
'Documentation for the latest stable version is ' \
461+
'<a href="https://doc.sagemath.org/html/en/index.html">here</a>.'
462+
html_theme_options.update({ "announcement": banner })
449463

450464
# The name of the Pygments (syntax highlighting) style to use. This
451465
# overrides a HTML theme's corresponding setting.

0 commit comments

Comments
 (0)