From 30ff8818b13e5683ad241fbf05c30d6857a97bbf Mon Sep 17 00:00:00 2001 From: Lundy Bernard Date: Sat, 25 Oct 2025 09:29:22 -0700 Subject: [PATCH 1/6] add github workflow to publish branch previews --- .github/workflows/publish-preview.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/publish-preview.yml b/.github/workflows/publish-preview.yml index 5635d7f..bfe7346 100644 --- a/.github/workflows/publish-preview.yml +++ b/.github/workflows/publish-preview.yml @@ -26,23 +26,23 @@ jobs: run: | jupyter-book build content/ - - name: Get PR number - id: pr-info - run: | - echo "number=pr-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT - - name: Deploy with ghp-import run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" + + # Fetch gh-pages branch to preserve existing content + git fetch origin gh-pages:gh-pages + ghp-import \ --no-jekyll \ + --no-history \ --push \ --force \ - --message "Deploy preview for ${{ steps.pr-info.outputs.number}}" \ + --message "Deploy preview for ${{github.event.pull_request.number}}" \ --branch gh-pages \ --remote origin \ - --prefix=preview/pr-${{ steps.pr-info.outputs.number}} \ + --prefix=preview/pr-${{github.event.pull_request.number}} \ content/_build/html - name: Comment PR with preview link @@ -53,5 +53,5 @@ jobs: issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - body: 'Preview deployed to: https://${{ github.repository_owner }}.github.io/learn.scientific-python.org/preview/${{ steps.pr-info.outputs.number }}/' + body: 'Preview deployed to: https://${{ github.repository_owner }}.github.io/learn.scientific-python.org/preview/pr-${{github.event.pull_request.number}}/' }) From b650426d4e0fdcf52c55417124f041cd5873ca2d Mon Sep 17 00:00:00 2001 From: Lundy Bernard Date: Thu, 30 Oct 2025 09:55:40 -0700 Subject: [PATCH 2/6] add preview link to PR description --- .github/scripts/update_pr_description.py | 32 ++++++++++++++++++++++++ .github/workflows/publish-preview.yml | 22 ++++++++-------- 2 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 .github/scripts/update_pr_description.py diff --git a/.github/scripts/update_pr_description.py b/.github/scripts/update_pr_description.py new file mode 100644 index 0000000..d6f8f91 --- /dev/null +++ b/.github/scripts/update_pr_description.py @@ -0,0 +1,32 @@ +from os import environ +from re import sub + +from github import Github + +token = environ['GITHUB_TOKEN'] +repo_name = environ['GITHUB_REPOSITORY'] +pr_number = int(environ['PR_NUMBER']) +preview_url = environ['PREVIEW_URL'] + +gh = Github(token) +repo = gh.get_repo(repo_name) +pr = repo.get_pull(pr_number) + +preview_label = '📚 Documentation preview 📚: ' +preview_text = f'{preview_label} {preview_url}' +current_body = pr.body or '' + +if preview_label in current_body: + new_body = sub( + f'{preview_label}.*', + preview_text, + preview_text, + ) +else: + new_body = ( + f'{current_body}' + '\n\n---\n\n' + f'{preview_text}' + ) + +pr.edit(body=new_body) diff --git a/.github/workflows/publish-preview.yml b/.github/workflows/publish-preview.yml index bfe7346..65ffd8b 100644 --- a/.github/workflows/publish-preview.yml +++ b/.github/workflows/publish-preview.yml @@ -14,13 +14,14 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: '3.14' + python-version: '3.13' - name: Install dependencies run: | pip install \ jupyter-book \ - ghp-import + ghp-import \ + PyGithub - name: Build the book run: | @@ -45,13 +46,10 @@ jobs: --prefix=preview/pr-${{github.event.pull_request.number}} \ content/_build/html - - name: Comment PR with preview link - uses: actions/github-script@v7 - with: - script: | - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: 'Preview deployed to: https://${{ github.repository_owner }}.github.io/learn.scientific-python.org/preview/pr-${{github.event.pull_request.number}}/' - }) + - name: Add preview link to PR + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_REPOSITORY: ${{ github.repository }} + PR_NUMBER: ${{ github.event.pull_request.number }} + PREVIEW_URL: https://${{ github.repository_owner }}.github.io/learn.scientific-python.org/preview/pr-${{ github.event.pull_request.number }}/ + run: python .github/scripts/update_pr_description.py From d44a406117a0272cfb8e3705c3d6f3fbbe03f23c Mon Sep 17 00:00:00 2001 From: Lundy Bernard Date: Thu, 30 Oct 2025 11:12:04 -0700 Subject: [PATCH 3/6] fixup: preserve gh-pages history --- .github/workflows/publish-preview.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/publish-preview.yml b/.github/workflows/publish-preview.yml index 65ffd8b..7100e60 100644 --- a/.github/workflows/publish-preview.yml +++ b/.github/workflows/publish-preview.yml @@ -37,7 +37,6 @@ jobs: ghp-import \ --no-jekyll \ - --no-history \ --push \ --force \ --message "Deploy preview for ${{github.event.pull_request.number}}" \ From d6aa74f557366f579c043b160206395d69bb56b7 Mon Sep 17 00:00:00 2001 From: Lundy Bernard Date: Thu, 30 Oct 2025 11:18:11 -0700 Subject: [PATCH 4/6] lint --- .github/workflows/publish-preview.yml | 2 +- .github/workflows/publish.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-preview.yml b/.github/workflows/publish-preview.yml index 7100e60..1677c6a 100644 --- a/.github/workflows/publish-preview.yml +++ b/.github/workflows/publish-preview.yml @@ -14,7 +14,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: '3.13' + python-version: "3.13" - name: Install dependencies run: | diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b342058..ccd0637 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -19,7 +19,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: '3.14' + python-version: "3.14" - name: Install dependencies run: pip install jupyter-book ghp-import From c13da1a1c079b44a58793bc8f30fa1d0ad515153 Mon Sep 17 00:00:00 2001 From: Lundy Bernard Date: Thu, 30 Oct 2025 11:21:05 -0700 Subject: [PATCH 5/6] lint --- .github/workflows/publish-preview.yml | 10 +++++----- .github/workflows/publish.yml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-preview.yml b/.github/workflows/publish-preview.yml index 1677c6a..8575aa6 100644 --- a/.github/workflows/publish-preview.yml +++ b/.github/workflows/publish-preview.yml @@ -10,23 +10,23 @@ jobs: steps: - name: Checkout PR branch uses: actions/checkout@v4 - + - name: Set up Python uses: actions/setup-python@v4 with: python-version: "3.13" - + - name: Install dependencies run: | pip install \ jupyter-book \ ghp-import \ PyGithub - + - name: Build the book run: | jupyter-book build content/ - + - name: Deploy with ghp-import run: | git config user.name "github-actions[bot]" @@ -34,7 +34,7 @@ jobs: # Fetch gh-pages branch to preserve existing content git fetch origin gh-pages:gh-pages - + ghp-import \ --no-jekyll \ --push \ diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ccd0637..a9e3db6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -34,7 +34,7 @@ jobs: # Fetch gh-pages branch to avoid conflicts git fetch origin gh-pages:gh-pages - + ghp-import \ --no-jekyll \ --push \ From cf72001bfc862c31a5cd2c5fa9406cb6f62502af Mon Sep 17 00:00:00 2001 From: Lundy Bernard Date: Thu, 30 Oct 2025 11:27:48 -0700 Subject: [PATCH 6/6] fixup --- .github/scripts/update_pr_description.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/update_pr_description.py b/.github/scripts/update_pr_description.py index d6f8f91..e929c68 100644 --- a/.github/scripts/update_pr_description.py +++ b/.github/scripts/update_pr_description.py @@ -20,7 +20,7 @@ new_body = sub( f'{preview_label}.*', preview_text, - preview_text, + current_body, ) else: new_body = (