diff --git a/.github/workflows/update-snapshots.yml b/.github/workflows/update-snapshots.yml new file mode 100644 index 00000000..6aafc55d --- /dev/null +++ b/.github/workflows/update-snapshots.yml @@ -0,0 +1,93 @@ +name: Update visual snapshots + +# Run by hand from the Actions tab when a dependency change (for example a +# Playwright/Chromium bump) shifts rendering and the baselines need refreshing. +# It regenerates the screenshots on the same runner image as the Visual +# workflow, commits them to the chosen branch, and then re-runs Visual there so +# the required "Visual snapshot tests" check reports on the new commit. + +on: + workflow_dispatch: + inputs: + branch: + description: Branch to update (not master) + required: true + type: string + +permissions: + contents: write + actions: write + +concurrency: + group: update-snapshots-${{ inputs.branch }} + cancel-in-progress: false + +jobs: + update: + name: Update visual snapshots + runs-on: ubuntu-24.04 + env: + BRANCH: ${{ inputs.branch }} + steps: + - name: Refuse the default branch + if: inputs.branch == github.event.repository.default_branch + run: | + echo "::error::Update snapshots on a feature branch, not $BRANCH." + exit 1 + + - name: Checkout + uses: actions/checkout@v7 + with: + ref: ${{ inputs.branch }} + + - name: Setup Node + uses: actions/setup-node@v7 + with: + node-version-file: .nvmrc + cache: npm + + - name: Install dependencies + run: npm ci + + - name: Install Playwright Chromium + run: npx playwright install --with-deps chromium + + - name: Build site + run: npm run build + + - name: Regenerate snapshots + run: npm run test:visual:update + + - name: Commit changed snapshots + id: commit + run: | + git add -- tests/ + if git diff --cached --quiet; then + echo "No snapshot changes." + echo "changed=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + git diff --cached --stat + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git commit -m "test(visual): update snapshots" + git push origin "HEAD:refs/heads/$BRANCH" + echo "changed=true" >> "$GITHUB_OUTPUT" + + # Pushes made with GITHUB_TOKEN don't start new workflow runs, so start + # Visual explicitly to get the required check on the new commit. + - name: Re-run Visual on the branch + if: steps.commit.outputs.changed == 'true' + env: + GH_TOKEN: ${{ github.token }} + run: gh workflow run visual.yml --ref "$BRANCH" + + - name: Upload test results + if: always() + uses: actions/upload-artifact@v7 + with: + name: snapshot-update-results + path: | + test-results/ + playwright-report/ + if-no-files-found: ignore diff --git a/.github/workflows/visual.yml b/.github/workflows/visual.yml index 9d127597..10dccfb6 100644 --- a/.github/workflows/visual.yml +++ b/.github/workflows/visual.yml @@ -5,6 +5,8 @@ on: branches: - master pull_request: + # Lets the snapshot update workflow re-run this check after it pushes. + workflow_dispatch: jobs: visual: diff --git a/README.md b/README.md index 567dcbe0..0e2ffb74 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,16 @@ This builds the site, serves the production build with `astro preview`, and fail ### Update snapshots -Prefer refreshing baselines from CI so they match Linux rendering: +Prefer refreshing baselines from CI so they match Linux rendering. + +The quickest way is the **Update visual snapshots** workflow: + +1. Open **Actions** > **Update visual snapshots** > **Run workflow**. +2. Enter the branch to update (not `master`) and run it. +3. The workflow commits any changed PNGs to that branch and re-runs **Visual snapshot tests** on it. +4. Review the updated images in the PR diff before you merge. + +To do it by hand instead: 1. Download the `visual-test-results` artifact from the failed job. 2. Copy each `*-actual.png` from `test-results/` over the matching file in `tests/visual.spec.ts-snapshots/`.