Skip to content

refactor: move LHS sidebar in-flow + RHS TOC overflow handling (#387) #99

refactor: move LHS sidebar in-flow + RHS TOC overflow handling (#387)

refactor: move LHS sidebar in-flow + RHS TOC overflow handling (#387) #99

name: Update Visual Snapshots
on:
issue_comment:
types: [created]
# Snapshots are generated against quantecon-book-theme-fixtures at this
# pinned SHA. Keep FIXTURES_SHA in sync with .github/workflows/ci.yml.
env:
FIXTURES_REPO: QuantEcon/quantecon-book-theme-fixtures
FIXTURES_SHA: d8ffc17c753ecf45fa25c6062827e1aa9de201b3
jobs:
# /update-new-snapshots — only creates MISSING snapshots (safe for adding new tests)
update-new-snapshots:
if: |
github.event.issue.pull_request &&
contains(github.event.comment.body, '/update-new-snapshots')
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Get PR branch
id: pr
uses: actions/github-script@v9
with:
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
core.setOutput('ref', pr.data.head.ref);
core.setOutput('sha', pr.data.head.sha);
- name: Checkout PR branch
uses: actions/checkout@v6
with:
ref: ${{ steps.pr.outputs.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout fixtures
uses: actions/checkout@v6
with:
repository: ${{ env.FIXTURES_REPO }}
ref: ${{ env.FIXTURES_SHA }}
path: fixtures
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: "3.13"
cache: "pip"
- name: Install fixtures build deps + this PR's theme
run: |
pip install -r fixtures/requirements.txt
pip install .
- name: Build fixtures site
working-directory: fixtures
run: jb build . --warningiserror
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '20'
cache: 'npm'
- name: Install Playwright
run: |
npm ci
npx playwright install --with-deps chromium
- name: Update Snapshots (missing only)
continue-on-error: true
run: npx playwright test --update-snapshots=missing
env:
SITE_PATH: fixtures/_build/html
- name: Commit and Push Updated Snapshots
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add tests/visual/__snapshots__/
if git diff --staged --quiet; then
echo "No snapshot changes to commit"
else
git commit -m "UPDATE: Visual regression snapshots (new)"
git push
fi
- name: Add reaction to comment
uses: actions/github-script@v9
with:
script: |
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: 'rocket'
});
- name: Comment on PR
uses: actions/github-script@v9
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: '✅ Missing visual snapshots have been added and committed to this PR.'
});
# /update-snapshots — regenerates ALL snapshots (use when styling changes legitimately)
update-all-snapshots:
if: |
github.event.issue.pull_request &&
contains(github.event.comment.body, '/update-snapshots') &&
!contains(github.event.comment.body, '/update-new-snapshots')
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Get PR branch
id: pr
uses: actions/github-script@v9
with:
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
core.setOutput('ref', pr.data.head.ref);
core.setOutput('sha', pr.data.head.sha);
- name: Checkout PR branch
uses: actions/checkout@v6
with:
ref: ${{ steps.pr.outputs.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout fixtures
uses: actions/checkout@v6
with:
repository: ${{ env.FIXTURES_REPO }}
ref: ${{ env.FIXTURES_SHA }}
path: fixtures
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: "3.13"
cache: "pip"
- name: Install fixtures build deps + this PR's theme
run: |
pip install -r fixtures/requirements.txt
pip install .
- name: Build fixtures site
working-directory: fixtures
run: jb build . --warningiserror
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '20'
cache: 'npm'
- name: Install Playwright
run: |
npm ci
npx playwright install --with-deps chromium
- name: Regenerate All Snapshots
continue-on-error: true
run: npx playwright test --update-snapshots
env:
SITE_PATH: fixtures/_build/html
- name: Upload Old vs New Diff
uses: actions/upload-artifact@v7
if: always()
with:
name: snapshot-update-diff
path: test-results/
retention-days: 30
- name: Commit and Push Updated Snapshots
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add tests/visual/__snapshots__/
if git diff --staged --quiet; then
echo "No snapshot changes to commit"
else
CHANGED=$(git diff --staged --name-only | wc -l)
git commit -m "UPDATE: Regenerate all visual snapshots ($CHANGED files)"
git push
fi
- name: Add reaction to comment
uses: actions/github-script@v9
with:
script: |
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: 'rocket'
});
- name: Comment on PR with summary
uses: actions/github-script@v9
with:
script: |
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: '✅ All visual snapshots have been regenerated and committed to this PR.\n\n' +
`📦 [Download snapshot-update-diff artifact](${runUrl}#artifacts) to review before/after images.`
});