Both Playwright-on-Vercel workflows fail at the very first action
(`patrickedqvist/wait-for-vercel-preview@v1.3.2`) with 403 "Resource
not accessible by integration". The cause is the repo-default workflow
token being read-only-by-default with no scopes declared by the workflow.
Add minimal scoped permission blocks per the GitHub Actions least-privilege
guidance:
preview-smoke.yml:
contents: read
deployments: read # wait-for-vercel-preview queries GitHub Deployments
pull-requests: read # correlate deployment with this PR
statuses: read # some Vercel deployments use commit statuses
visual-diff.yml:
contents: read
deployments: read
pull-requests: write # final step posts "Visual Diff" comment via Issues API
statuses: read
Verified against the failure on PR #15:
- Playwright smoke: "Resource not accessible by integration" on
wait-for-vercel-preview → fixed by deployments+statuses+pull-requests:read
- Screenshot diff: 403 from POST /repos/.../issues/15/comments with
`x-accepted-github-permissions: issues=write; pull_requests=write`
in the response → fixed by pull-requests:write (covers Issues API
for PR comments; issues:write would also work but pull-requests:write
is the idiomatic scope)
Unblocks visual-regression signal on every future PR. No code changes,
no test changes — workflow YAML only.
Co-authored-by: Cursor <cursoragent@cursor.com>
98 lines
3.1 KiB
YAML
98 lines
3.1 KiB
YAML
name: Visual diff
|
|
|
|
# Same as preview-smoke — waits for Vercel's Preview deployment, then captures
|
|
# Playwright screenshots against it. UI-paths-only trigger to keep cost down.
|
|
# Paths are tcg-vault-specific (pages router, JS).
|
|
|
|
on:
|
|
pull_request:
|
|
branches: [main]
|
|
paths:
|
|
- 'pages/**'
|
|
- 'components/**'
|
|
- 'styles/**'
|
|
- 'tailwind.config.js'
|
|
- 'postcss.config.js'
|
|
|
|
concurrency:
|
|
group: visual-diff-${{ github.event.pull_request.number }}
|
|
cancel-in-progress: true
|
|
|
|
# `deployments: read` + `statuses: read` are required by wait-for-vercel-preview
|
|
# (see preview-smoke.yml for context). `pull-requests: write` is required by the
|
|
# final github-script step that posts the "Visual Diff" comment back to the PR;
|
|
# without it the API returns 403 even though the screenshots upload fine.
|
|
permissions:
|
|
contents: read
|
|
deployments: read
|
|
pull-requests: write
|
|
statuses: read
|
|
|
|
jobs:
|
|
gate:
|
|
name: Should run?
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
should_run: ${{ steps.check.outputs.should_run }}
|
|
steps:
|
|
- id: check
|
|
run: |
|
|
if echo "${{ github.event.pull_request.body }}" | grep -qE 'pipeline:.*skip.*\bvisual\b'; then
|
|
echo "should_run=false" >> $GITHUB_OUTPUT
|
|
echo "::notice::Visual diff skipped via pipeline directive"
|
|
else
|
|
echo "should_run=true" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
visual:
|
|
name: Screenshot diff
|
|
needs: gate
|
|
if: needs.gate.outputs.should_run == 'true'
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 20
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Wait for Vercel Preview deployment
|
|
id: vercel
|
|
uses: patrickedqvist/wait-for-vercel-preview@v1.3.2
|
|
with:
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
max_timeout: 600
|
|
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20'
|
|
cache: npm
|
|
|
|
- run: npm ci
|
|
- run: npx playwright install --with-deps chromium
|
|
|
|
- name: Capture screenshots (PR)
|
|
run: npx playwright test --project=visual --update-snapshots=none
|
|
env:
|
|
BASE_URL: ${{ steps.vercel.outputs.url }}
|
|
continue-on-error: true
|
|
|
|
- name: Upload screenshots + diffs
|
|
if: always()
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: visual-diff
|
|
path: |
|
|
tests/visual/__screenshots__/
|
|
test-results/
|
|
retention-days: 7
|
|
|
|
- name: Comment on PR with diff link
|
|
if: always()
|
|
uses: actions/github-script@v7
|
|
with:
|
|
script: |
|
|
const run = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
|
|
github.rest.issues.createComment({
|
|
issue_number: context.issue.number,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
body: `## Visual Diff\n\nScreenshots and diffs uploaded as artifacts: [view run](${run})\n\nIf intentional changes: update snapshots locally with \`npx playwright test --project=visual --update-snapshots\` and commit.`
|
|
});
|