Skip to content

Commit 901981f

Browse files
author
Release Manager
committed
gh-38127: Add links to the PR in doc preview <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes #12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes #12345". --> solves some items of wishlist in #37759 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #38127 Reported by: Kwankyu Lee Reviewer(s): Matthias Köppe
2 parents 7f4fb99 + f11b6cc commit 901981f

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
@@ -133,6 +133,7 @@ jobs:
133133
# Wipe out chronic diffs between old doc and new doc
134134
(cd docs && \
135135
find . -name "*.html" | xargs sed -i -e '/class="sidebar-brand-text"/ s/Sage [0-9a-z.]* /Sage '"$new_version"' /' \
136+
-e '/This is documentation for/ s/ built with GitHub PR [^.]*././' \
136137
-e 's;'"$mathjax_path_from"';'"$mathjax_path_to"';' \
137138
-e '\;<script type="application/vnd\.jupyter\.widget-state+json">;,\;</script>; d')
138139
# Create git repo from old doc
@@ -148,6 +149,8 @@ jobs:
148149
# Always non-incremental because of the concern that
149150
# incremental docbuild may introduce broken links (inter-file references) though build succeeds
150151
run: |
152+
export GITHUB_REF=${{ github.ref }}
153+
export PR_SHA=${{ github.event.pull_request.head.sha }}
151154
export MAKE="make -j5 --output-sync=recurse" SAGE_NUM_THREADS=5
152155
make doc-clean doc-uninstall
153156
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 links
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('PR_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)