Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions .github/workflows/publish-playwright-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,38 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Check S3 credentials
id: s3
env:
AWS_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
shell: bash
run: |
if [[ -n "${AWS_ACCESS_KEY_ID:-}" && -n "${AWS_SECRET_ACCESS_KEY:-}" ]]; then
echo "configured=true" >> "$GITHUB_OUTPUT"
else
echo "::notice::Skipping Playwright visual report publish; S3 credentials are not configured."
echo "configured=false" >> "$GITHUB_OUTPUT"
fi
# workflow_run has repository secrets. Always use trusted default-branch code here;
# never check out or execute the contributor's pull-request revision.
- uses: actions/checkout@v5
- if: steps.s3.outputs.configured == 'true'
uses: actions/checkout@v5
with:
ref: ${{ github.event.repository.default_branch }}
persist-credentials: false
lfs: true
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
- if: steps.s3.outputs.configured == 'true'
uses: pnpm/action-setup@v4
- if: steps.s3.outputs.configured == 'true'
uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
- if: steps.s3.outputs.configured == 'true'
run: pnpm install --frozen-lockfile
- name: Read Playwright job result
if: steps.s3.outputs.configured == 'true'
id: playwright
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -58,7 +76,7 @@ jobs:
if [[ "$result" == "timed_out" ]]; then result="failure"; fi
echo "result=$result" >> "$GITHUB_OUTPUT"
- name: Resolve pull request
if: github.event.workflow_run.event == 'pull_request'
if: steps.s3.outputs.configured == 'true' && github.event.workflow_run.event == 'pull_request'
id: pull_request
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -77,6 +95,7 @@ jobs:
fi
echo "number=$number" >> "$GITHUB_OUTPUT"
- name: Check for Playwright artifact
if: steps.s3.outputs.configured == 'true'
id: artifact
env:
ARTIFACT_NAME: playwright-artifacts-${{ github.event.workflow_run.id }}-${{ github.event.workflow_run.run_attempt }}
Expand All @@ -100,14 +119,15 @@ jobs:
exit 1
fi
- name: Download Playwright artifacts
if: steps.artifact.outputs.exists == 'true'
if: steps.s3.outputs.configured == 'true' && steps.artifact.outputs.exists == 'true'
uses: actions/download-artifact@v4
with:
name: playwright-artifacts-${{ github.event.workflow_run.id }}-${{ github.event.workflow_run.run_attempt }}
path: .
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
- name: Publish trusted Playwright screenshot gallery
if: steps.s3.outputs.configured == 'true'
id: publish
env:
AWS_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
Expand All @@ -131,6 +151,7 @@ jobs:
run: bash scripts/publish-playwright-report.sh
- name: Link screenshot gallery from pull request
if: >-
steps.s3.outputs.configured == 'true' &&
github.event.workflow_run.event == 'pull_request' &&
steps.pull_request.outputs.number != '' &&
steps.publish.outputs.latest_pr_run == 'true'
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pnpm dev
| `pnpm check` | TypeScript (`tsc`) across the monorepo. |
| `pnpm lint` | Biome lint and format check. |

CI runs `pnpm lint`, `pnpm check`, production builds (including Electron preload smoke), `pnpm test`, `pnpm test:integration`, and `pnpm test:e2e` on every PR.
CI runs `pnpm lint`, `pnpm check`, production builds (including Electron preload smoke), `pnpm test`, `pnpm test:integration`, and `pnpm test:e2e` on every PR. After those jobs on `main` or a PR, `publish Playwright report` uploads the screenshot gallery when `S3_ACCESS_KEY_ID` and `S3_SECRET_ACCESS_KEY` are set; otherwise that workflow skips and stays green.

## Secrets and configuration

Expand Down
42 changes: 42 additions & 0 deletions packages/testkit/src/publish-playwright-report.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { spawnSync } from "node:child_process";
import path from "node:path";
import { describe, expect, it } from "vitest";

const script = path.resolve("scripts/publish-playwright-report.sh");

function runPublish(env: NodeJS.ProcessEnv): {
status: number | null;
output: string;
} {
const result = spawnSync("bash", [script], {
encoding: "utf8",
env,
});
return {
status: result.status,
output: `${result.stdout}${result.stderr}`,
};
}

const isolatedEnv = {
PATH: process.env.PATH ?? "/usr/bin:/bin",
HOME: process.env.HOME ?? "/tmp",
} as const satisfies NodeJS.ProcessEnv;

describe("publish-playwright-report.sh", () => {
it("skips when S3 credentials are unset", () => {
const result = runPublish(isolatedEnv);
expect(result.status).toBe(0);
expect(result.output).toMatch(/Skipping Playwright visual report publish/);
});

it("fails when credentials exist but the S3 destination is incomplete", () => {
const result = runPublish({
...isolatedEnv,
AWS_ACCESS_KEY_ID: "test-access-key",
AWS_SECRET_ACCESS_KEY: "test-secret-key",
});
expect(result.status).not.toBe(0);
expect(result.output).toMatch(/S3_BUCKET is required/);
});
});
14 changes: 12 additions & 2 deletions scripts/publish-playwright-report.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
#!/usr/bin/env bash
set -euo pipefail

: "${AWS_ACCESS_KEY_ID:?AWS_ACCESS_KEY_ID is required}"
: "${AWS_SECRET_ACCESS_KEY:?AWS_SECRET_ACCESS_KEY is required}"
if [[ -z "${AWS_ACCESS_KEY_ID:-}" || -z "${AWS_SECRET_ACCESS_KEY:-}" ]]; then
echo "::notice::Skipping Playwright visual report publish; S3 credentials are not configured."
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
printf 'latest_pr_run=false\n' >> "$GITHUB_OUTPUT"
printf 'stable_screenshots_url=\n' >> "$GITHUB_OUTPUT"
fi
if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then
printf '%s\n' "Playwright visual report publish skipped because S3 credentials are not configured." >> "$GITHUB_STEP_SUMMARY"
fi
exit 0
fi

: "${S3_BUCKET:?S3_BUCKET is required}"
: "${S3_ENDPOINT:?S3_ENDPOINT is required}"
: "${PLAYWRIGHT_PUBLIC_BASE_URL:?PLAYWRIGHT_PUBLIC_BASE_URL is required}"
Expand Down
Loading