viewev 0.1.0-beta.2 → 0.1.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"report.js","sourceRoot":"","sources":["../../src/reporting/report.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAGvF,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAO7C,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,SAAiB,EAAE,IAAiB;IACxE,MAAM,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5C,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;IAC1D,MAAM,SAAS,CAAC,UAAU,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;IACpD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,kEAAkE;AAClE,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,SAAiB,EAAE,MAAiB;IACpE,MAAM,WAAW,GAAG,MAAM,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC9D,MAAM,UAAU,GAAG,MAAM,eAAe,CAAC,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3E,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;AACrC,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,IAAI,OAAO,K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I,WAAW,CAAC,uCAAuC,YAAY,EAAE,CAAC,CAAC;QAC/E,CAAC;QACD,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5D,MAAM,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACtC,CAAC;AACH,CAAC"}
@@ -31,6 +31,8 @@ export interface ResultsFile {
31
31
  /** Present when impact analysis chose the scenarios. */
32
32
  readonly selection?: SelectionInfo;
33
33
  }
34
+ /** Validates JSON before it is used to render HTML, especially when supplied by an untrusted PR. */
35
+ export declare function parseResultsFile(value: unknown): ResultsFile | undefined;
34
36
  /** The machine-readable result of a run; the HTML report is rendered from it. */
35
37
  export declare function toResultsFile(result: RunResult): ResultsFile;
36
38
  export declare function writeResultsFile(reportDir: string, result: RunResult): Promise<string>;
@@ -1,7 +1,173 @@
1
1
  import { mkdir, writeFile } from 'node:fs/promises';
2
2
  import path from 'node:path';
3
+ import { z } from 'zod';
3
4
  import { summarize } from '../core/result.js';
5
+ import { scenarioIdSchema } from '../scenarios/schema.js';
4
6
  export const RESULTS_FILE_NAME = 'results.json';
7
+ const nonNegativeInt = z.number().int().nonnegative();
8
+ const positiveInt = z.number().int().positive();
9
+ const sizeSchema = z.object({ width: positiveInt, height: positiveInt }).strict();
10
+ const statsSchema = z
11
+ .object({
12
+ diffPixels: nonNegativeInt,
13
+ totalPixels: nonNegativeInt,
14
+ diffRatio: z.number().min(0).max(1),
15
+ })
16
+ .strict();
17
+ const imagePathSchema = z
18
+ .string()
19
+ .regex(/^artifacts\/[A-Za-z0-9._@/-]+\.png$/)
20
+ .refine((value) => !value.split('/').some((part) => part === '.' || part === '..'));
21
+ const artifactsSchema = z
22
+ .object({
23
+ expected: imagePathSchema.optional(),
24
+ actual: imagePathSchema.optional(),
25
+ diff: imagePathSchema.optional(),
26
+ })
27
+ .strict();
28
+ const outcomeSchema = z.union([
29
+ z.object({ status: z.literal('passed'), stats: statsSchema }).strict(),
30
+ z
31
+ .object({
32
+ status: z.literal('regression'),
33
+ cause: z.literal('pixels'),
34
+ stats: statsSchema,
35
+ artifacts: artifactsSchema,
36
+ })
37
+ .strict(),
38
+ z
39
+ .object({
40
+ status: z.literal('regression'),
41
+ cause: z.literal('dimensions'),
42
+ expected: sizeSchema,
43
+ actual: sizeSchema,
44
+ artifacts: artifactsSchema,
45
+ })
46
+ .strict(),
47
+ z
48
+ .object({
49
+ status: z.literal('changed'),
50
+ change: z.literal('added'),
51
+ artifacts: artifactsSchema,
52
+ })
53
+ .strict(),
54
+ z
55
+ .object({
56
+ status: z.literal('changed'),
57
+ change: z.literal('modified'),
58
+ cause: z.literal('pixels'),
59
+ stats: statsSchema,
60
+ artifacts: artifactsSchema,
61
+ })
62
+ .strict(),
63
+ z
64
+ .object({
65
+ status: z.literal('changed'),
66
+ change: z.literal('modified'),
67
+ cause: z.literal('dimensions'),
68
+ expected: sizeSchema,
69
+ actual: sizeSchema,
70
+ artifacts: artifactsSchema,
71
+ })
72
+ .strict(),
73
+ z.object({ status: z.literal('missing-baseline'), artifacts: artifactsSchema }).strict(),
74
+ z
75
+ .object({
76
+ status: z.literal('error'),
77
+ error: z
78
+ .object({
79
+ phase: z.enum([
80
+ 'discover',
81
+ 'navigate',
82
+ 'ready',
83
+ 'stabilize',
84
+ 'screenshot',
85
+ 'compare',
86
+ 'baseline',
87
+ ]),
88
+ message: z.string(),
89
+ })
90
+ .strict(),
91
+ })
92
+ .strict(),
93
+ ]);
94
+ const environmentSchema = z
95
+ .object({
96
+ browser: z.object({ name: z.literal('chromium'), version: z.string() }).strict(),
97
+ automation: z.object({ name: z.string(), version: z.string() }).strict(),
98
+ os: z
99
+ .object({
100
+ platform: z.enum(['darwin', 'linux', 'win32']),
101
+ arch: z.string(),
102
+ release: z.string(),
103
+ })
104
+ .strict(),
105
+ container: z.boolean(),
106
+ })
107
+ .strict();
108
+ const resultsFileSchema = z
109
+ .object({
110
+ schemaVersion: z.literal(1),
111
+ startedAt: z.string(),
112
+ durationMs: nonNegativeInt,
113
+ environment: environmentSchema.optional(),
114
+ reference: z.object({ ref: z.string(), commit: z.string() }).strict().optional(),
115
+ summary: z
116
+ .object({
117
+ total: nonNegativeInt,
118
+ passed: nonNegativeInt,
119
+ regressions: nonNegativeInt,
120
+ changed: nonNegativeInt,
121
+ missingBaselines: nonNegativeInt,
122
+ errors: nonNegativeInt,
123
+ obsolete: nonNegativeInt,
124
+ removed: nonNegativeInt.optional(),
125
+ })
126
+ .strict(),
127
+ warnings: z.array(z.string()),
128
+ scenarios: z.array(z
129
+ .object({
130
+ id: scenarioIdSchema,
131
+ name: z.string(),
132
+ group: z.array(z.string()).optional(),
133
+ origin: z
134
+ .object({ provider: z.string(), ref: z.string(), source: z.string().optional() })
135
+ .strict(),
136
+ viewport: sizeSchema,
137
+ variant: z.record(z.string()).optional(),
138
+ tags: z.array(z.string()).optional(),
139
+ durationMs: nonNegativeInt,
140
+ clipped: z.boolean().optional(),
141
+ outcome: outcomeSchema,
142
+ })
143
+ .strict()),
144
+ obsolete: z.array(scenarioIdSchema),
145
+ removed: z.array(scenarioIdSchema).optional(),
146
+ selection: z
147
+ .object({
148
+ mode: z.enum(['all', 'impact']),
149
+ total: nonNegativeInt,
150
+ selected: nonNegativeInt,
151
+ baseRef: z.string().optional(),
152
+ changedFileCount: nonNegativeInt.optional(),
153
+ reason: z.string().optional(),
154
+ reasons: z.record(z.array(z.string())).optional(),
155
+ })
156
+ .strict()
157
+ .optional(),
158
+ })
159
+ .strict();
160
+ /** Validates JSON before it is used to render HTML, especially when supplied by an untrusted PR. */
161
+ export function parseResultsFile(value) {
162
+ const parsed = resultsFileSchema.safeParse(value);
163
+ if (!parsed.success)
164
+ return undefined;
165
+ return {
166
+ ...parsed.data,
167
+ summary: { ...parsed.data.summary, removed: parsed.data.summary.removed ?? 0 },
168
+ removed: parsed.data.removed ?? [],
169
+ };
170
+ }
5
171
  /** The machine-readable result of a run; the HTML report is rendered from it. */
6
172
  export function toResultsFile(result) {
7
173
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"results-json.js","sourceRoot":"","sources":["../../src/reporting/results-json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAW9C,MAAM,CAAC,MAAM,iBAAiB,GAAG,cAAc,CAAC;AA6BhD,iFAAiF;AACjF,MAAM,UAAU,aAAa,CAAC,MAAiB;IAC7C,OAAO;QACL,aAAa,EAAE,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,GAAG,CAAC,MAAM,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAChF,GAAG,CAAC,MAAM,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1E,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC;QAC1B,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,EAAE;QAC/B,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;YAC/E,EAAE,EAAE,QAAQ,CAAC,EAAE;YACf,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,GAAG,CAAC,QAAQ,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YA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I,CAAC,CAAC;IAC7E,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -131,6 +131,11 @@ CI security: tests run on `pull_request` with read-only permissions and no secre
131
131
  branch build runs in that same untrusted job, so it must not require secrets. `pull_request_target`
132
132
  is never combined with a checkout of PR code.
133
133
 
134
+ Optional GitHub Pages hosting stays in the consuming repository's workflow. Viewev emits a portable
135
+ static report; a trusted post-run job can validate `results.json`, rerender it, publish it under the
136
+ PR number, and remove that directory when the PR closes. The core CLI does not receive a GitHub
137
+ token or deploy reports itself.
138
+
134
139
  ## Variants
135
140
 
136
141
  A variant is another way of rendering every story, such as a theme or a narrow viewport. The
package/docs/ci.md CHANGED
@@ -81,6 +81,58 @@ scenarios when source mapping is incomplete or a changed file cannot be mapped.
81
81
  and GitHub job summary show the target ref, selected scenarios, regressions and
82
82
  expected/actual/diff images. New and removed stories are listed separately.
83
83
 
84
+ ## Host pull request reports on GitHub Pages
85
+
86
+ Viewev can publish a static report for each open pull request and remove it after the pull request
87
+ is merged or closed. Pages is configured in the consuming repository because each project owns its
88
+ report URLs and retention lifecycle.
89
+
90
+ 1. Keep the visual test workflow on `pull_request` with read-only permissions. Upload
91
+ `.viewev/report` as the `viewev-report` artifact.
92
+ 2. Copy [the Pages workflow example](examples/github-pages.yml) into `.github/workflows/` in the
93
+ consuming repository. Change `workflows: [Visual tests]` to match the visual workflow's `name`.
94
+ It publishes reports to `pr/<number>/`, updates a sticky pull request comment and `viewev/report`
95
+ commit status with a direct link to the hosted report, and removes both the directory and the
96
+ report link when the pull request is merged or closed.
97
+ 3. Merge the Pages workflow to the default branch, then run a PR visual test once. The publisher
98
+ creates the `gh-pages` branch even before Pages hosting is enabled.
99
+ 4. In **Settings → Pages → Build and deployment**, choose **Deploy from a branch**, then select
100
+ `gh-pages` and `/ (root)`.
101
+ 5. Optionally define repository variables `VIEWEV_REPORT_REF` (a Viewev tag or commit to use as the
102
+ trusted report renderer) and `VIEWEV_PAGES_URL` (the Pages site URL, without a trailing slash).
103
+
104
+ The publisher job needs `contents: write`, `pull-requests: write` and `statuses: write` for
105
+ `GITHUB_TOKEN` (and the cleanup job needs `contents: write` and `pull-requests: write`). Repository
106
+ or organization policy and branch protection must allow that token to update `gh-pages`. Note that
107
+ GitHub Pages sites for public repositories are publicly accessible; for private repositories, check
108
+ your GitHub plan's Pages visibility settings.
109
+
110
+ The publisher runs from the repository's default branch after the visual workflow completes. It
111
+ does not check out pull request code. It reads the artifact's `results.json`, validates it, copies
112
+ only referenced PNG files, renders fresh HTML with the trusted Viewev CLI, and posts the summary
113
+ and hosted URL back to the pull request. The workflow uses
114
+ `workflow_run` to gain narrowly scoped write access, so the Pages workflow must first be merged to
115
+ the default branch before it can publish reports for later pull request runs. It also writes
116
+ `.nojekyll` so GitHub serves the generated report files without processing PR supplied text as
117
+ Liquid templates. The separate `pull_request_target` cleanup job uses only the numeric PR number and
118
+ does not read PR code.
119
+ The first PR that adds the publisher cannot trigger it; GitHub loads `workflow_run` handlers from
120
+ the default branch, so use a later PR run to create the initial Pages branch.
121
+
122
+ For a local or custom deployment pipeline, render an artifact into another directory (and optionally
123
+ write a GitHub markdown summary with the hosted report URL) with:
124
+
125
+ ```sh
126
+ viewev report \
127
+ --from .viewev/report \
128
+ --to site/pr/123 \
129
+ --url https://example.github.io/repo/pr/123/ \
130
+ --github-summary comment.md
131
+ ```
132
+
133
+ The command validates the results file and copies only the screenshots referenced by it. Do not
134
+ publish the uploaded `index.html` directly from an untrusted pull request artifact.
135
+
84
136
  To select a different target manually, pass `viewev test --compare-ref <ref>`. The ref must be
85
137
  available in the checkout. You can run a full capture with `--filter` patterns, but impact
86
138
  analysis otherwise selects the affected scenarios before screenshots are taken.
@@ -0,0 +1,317 @@
1
+ name: Viewev report Pages
2
+
3
+ on:
4
+ workflow_run:
5
+ workflows: [Visual tests]
6
+ types: [completed]
7
+ pull_request_target:
8
+ types: [closed]
9
+
10
+ permissions:
11
+ contents: read
12
+
13
+ concurrency:
14
+ group: viewev-pages-${{ github.event.pull_request.number ||
15
+ github.event.workflow_run.pull_requests[0].number || github.run_id }}
16
+ cancel-in-progress: false
17
+
18
+ jobs:
19
+ publish-report:
20
+ if: github.event_name == 'workflow_run' && github.event.workflow_run.event ==
21
+ 'pull_request'
22
+ runs-on: ubuntu-latest
23
+ permissions:
24
+ actions: read
25
+ contents: write
26
+ pull-requests: write
27
+ statuses: write
28
+ steps:
29
+ - uses: actions/checkout@v4
30
+ with:
31
+ persist-credentials: true
32
+
33
+ - name: Find the pull request
34
+ id: pr
35
+ uses: actions/github-script@v7
36
+ with:
37
+ script: |
38
+ let pullRequest = context.payload.workflow_run.pull_requests?.[0];
39
+ if (!pullRequest) {
40
+ const associated = await github.rest.repos.listPullRequestsAssociatedWithCommit({
41
+ owner: context.repo.owner,
42
+ repo: context.repo.repo,
43
+ commit_sha: context.payload.workflow_run.head_sha,
44
+ });
45
+ pullRequest = associated.data.find((item) => item.state === 'open');
46
+ }
47
+ if (!pullRequest) {
48
+ core.notice('No open pull request is associated with this visual test run.');
49
+ core.setOutput('number', '');
50
+ return;
51
+ }
52
+ const current = await github.rest.pulls.get({
53
+ owner: context.repo.owner,
54
+ repo: context.repo.repo,
55
+ pull_number: pullRequest.number,
56
+ });
57
+ const testedHead = context.payload.workflow_run.head_sha || pullRequest.head?.sha;
58
+ if (current.data.state !== 'open' || (testedHead && testedHead !== current.data.head.sha)) {
59
+ core.notice('This report belongs to a closed or superseded pull request revision.');
60
+ core.setOutput('number', '');
61
+ return;
62
+ }
63
+ core.setOutput('number', String(pullRequest.number));
64
+ core.setOutput('head_sha', testedHead || current.data.head.sha);
65
+
66
+ - name: Download the report artifact
67
+ id: download
68
+ if: steps.pr.outputs.number != ''
69
+ continue-on-error: true
70
+ uses: actions/download-artifact@v4
71
+ with:
72
+ name: viewev-report
73
+ path: ${{ runner.temp }}/viewev-report
74
+ repository: ${{ github.repository }}
75
+ run-id: ${{ github.event.workflow_run.id }}
76
+ github-token: ${{ secrets.GITHUB_TOKEN }}
77
+
78
+ - name: Check out the trusted Viewev renderer
79
+ if: steps.download.outcome == 'success'
80
+ uses: actions/checkout@v4
81
+ with:
82
+ repository: viewev/viewev
83
+ ref: ${{ vars.VIEWEV_REPORT_REF || 'main' }}
84
+ path: .viewev-source
85
+ persist-credentials: false
86
+
87
+ - uses: actions/setup-node@v4
88
+ if: steps.download.outcome == 'success'
89
+ with:
90
+ node-version: 22
91
+
92
+ - name: Build the trusted report renderer
93
+ if: steps.download.outcome == 'success'
94
+ run: |
95
+ npm ci
96
+ npm run build
97
+ working-directory: .viewev-source
98
+
99
+ - name: Prepare the Pages worktree
100
+ if: steps.download.outcome == 'success'
101
+ env:
102
+ PAGES_DIR: ${{ runner.temp }}/viewev-pages
103
+ run: |
104
+ git fetch origin gh-pages || true
105
+ if git show-ref --verify --quiet refs/remotes/origin/gh-pages; then
106
+ git worktree add -b gh-pages "$PAGES_DIR" origin/gh-pages
107
+ else
108
+ git worktree add --detach "$PAGES_DIR" HEAD
109
+ git -C "$PAGES_DIR" switch --orphan gh-pages
110
+ git -C "$PAGES_DIR" rm -r -f . >/dev/null 2>&1 || true
111
+ git -C "$PAGES_DIR" clean -fdx
112
+ fi
113
+ git -C "$PAGES_DIR" config user.name "github-actions[bot]"
114
+ git -C "$PAGES_DIR" config user.email "41898282+github-actions[bot]@users.noreply.github.com"
115
+
116
+ - name: Render and publish the report
117
+ id: publish
118
+ if: steps.download.outcome == 'success'
119
+ env:
120
+ PR_NUMBER: ${{ steps.pr.outputs.number }}
121
+ PAGES_DIR: ${{ runner.temp }}/viewev-pages
122
+ REPORT_DIR: ${{ runner.temp }}/viewev-report
123
+ COMMENT_FILE: ${{ runner.temp }}/viewev-comment.md
124
+ PAGES_BASE_URL: ${{ vars.VIEWEV_PAGES_URL || format('https://{0}.github.io/{1}',
125
+ github.repository_owner, github.event.repository.name) }}
126
+ run: |
127
+ case "$PR_NUMBER" in ''|*[!0-9]*) echo "Invalid pull request number" >&2; exit 1 ;; esac
128
+ test -f "$REPORT_DIR/results.json"
129
+ PAGES_BASE_URL="${PAGES_BASE_URL%/}"
130
+ REPORT_URL="$PAGES_BASE_URL/pr/$PR_NUMBER/"
131
+ rm -rf -- "$PAGES_DIR/pr/$PR_NUMBER"
132
+ node "$GITHUB_WORKSPACE/.viewev-source/dist/cli/bin.js" report \
133
+ --from "$REPORT_DIR" \
134
+ --to "$PAGES_DIR/pr/$PR_NUMBER" \
135
+ --url "$REPORT_URL" \
136
+ --github-summary "$COMMENT_FILE"
137
+ touch "$PAGES_DIR/.nojekyll"
138
+ git -C "$PAGES_DIR" add -f -- .nojekyll "pr/$PR_NUMBER"
139
+ if ! git -C "$PAGES_DIR" diff --cached --quiet; then
140
+ git -C "$PAGES_DIR" commit -m "Update Viewev report for PR #$PR_NUMBER"
141
+ for attempt in 1 2 3 4 5; do
142
+ if git -C "$PAGES_DIR" push origin HEAD:gh-pages; then
143
+ break
144
+ fi
145
+ if [ "$attempt" -eq 5 ]; then exit 1; fi
146
+ git fetch origin gh-pages
147
+ git -C "$PAGES_DIR" merge --no-edit --allow-unrelated-histories origin/gh-pages
148
+ done
149
+ fi
150
+ cat "$COMMENT_FILE" >> "$GITHUB_STEP_SUMMARY"
151
+ echo "report_url=$REPORT_URL" >> "$GITHUB_OUTPUT"
152
+
153
+ - name: Comment on pull request
154
+ if: steps.publish.outcome == 'success'
155
+ uses: actions/github-script@v7
156
+ env:
157
+ COMMENT_FILE: ${{ runner.temp }}/viewev-comment.md
158
+ PR_NUMBER: ${{ steps.pr.outputs.number }}
159
+ with:
160
+ script: |
161
+ const fs = require('node:fs');
162
+ const marker = '<!-- viewev-report-comment -->';
163
+ const summary = fs.readFileSync(process.env.COMMENT_FILE, 'utf8');
164
+ const body = `${marker}\n${summary}`;
165
+ const issueNumber = Number(process.env.PR_NUMBER);
166
+ const comments = await github.paginate(github.rest.issues.listComments, {
167
+ owner: context.repo.owner,
168
+ repo: context.repo.repo,
169
+ issue_number: issueNumber,
170
+ per_page: 100,
171
+ });
172
+ const existing = comments.find(
173
+ (comment) =>
174
+ comment.user?.login === 'github-actions[bot]' &&
175
+ comment.body?.includes(marker),
176
+ );
177
+ if (existing) {
178
+ await github.rest.issues.updateComment({
179
+ owner: context.repo.owner,
180
+ repo: context.repo.repo,
181
+ comment_id: existing.id,
182
+ body,
183
+ });
184
+ } else {
185
+ await github.rest.issues.createComment({
186
+ owner: context.repo.owner,
187
+ repo: context.repo.repo,
188
+ issue_number: issueNumber,
189
+ body,
190
+ });
191
+ }
192
+
193
+ - name: Set commit status
194
+ if: steps.publish.outcome == 'success'
195
+ uses: actions/github-script@v7
196
+ env:
197
+ REPORT_DIR: ${{ runner.temp }}/viewev-report
198
+ REPORT_URL: ${{ steps.publish.outputs.report_url }}
199
+ HEAD_SHA: ${{ steps.pr.outputs.head_sha }}
200
+ with:
201
+ script: |
202
+ const fs = require('node:fs');
203
+ const path = require('node:path');
204
+ const results = JSON.parse(
205
+ fs.readFileSync(path.join(process.env.REPORT_DIR, 'results.json'), 'utf8'),
206
+ );
207
+ const { summary } = results;
208
+ const parts = [];
209
+ if (summary.regressions > 0) {
210
+ parts.push(`${summary.regressions} regression${summary.regressions === 1 ? '' : 's'}`);
211
+ }
212
+ if (summary.errors > 0) {
213
+ parts.push(`${summary.errors} error${summary.errors === 1 ? '' : 's'}`);
214
+ }
215
+ if (summary.missingBaselines > 0) {
216
+ parts.push(`${summary.missingBaselines} new`);
217
+ }
218
+ if (summary.obsolete > 0) {
219
+ parts.push(`${summary.obsolete} removed`);
220
+ }
221
+ let description;
222
+ if (parts.length > 0) {
223
+ description = `${parts.join(', ')} — open report`;
224
+ } else if (summary.changed > 0) {
225
+ description = `${summary.changed} visual change${summary.changed === 1 ? '' : 's'} need review`;
226
+ } else {
227
+ description = `No visual changes (${summary.total} scenarios)`;
228
+ }
229
+ await github.rest.repos.createCommitStatus({
230
+ owner: context.repo.owner,
231
+ repo: context.repo.repo,
232
+ sha: process.env.HEAD_SHA,
233
+ state: 'success',
234
+ context: 'viewev/report',
235
+ description: description.slice(0, 140),
236
+ target_url: process.env.REPORT_URL,
237
+ });
238
+
239
+ remove-report:
240
+ if: github.event_name == 'pull_request_target'
241
+ runs-on: ubuntu-latest
242
+ permissions:
243
+ contents: write
244
+ pull-requests: write
245
+ steps:
246
+ - uses: actions/checkout@v4
247
+ with:
248
+ persist-credentials: true
249
+
250
+ - name: Remove the closed pull request report
251
+ env:
252
+ PR_NUMBER: ${{ github.event.pull_request.number }}
253
+ PAGES_DIR: ${{ runner.temp }}/viewev-pages
254
+ run: |
255
+ case "$PR_NUMBER" in ''|*[!0-9]*) echo "Invalid pull request number" >&2; exit 1 ;; esac
256
+ if ! git ls-remote --exit-code --heads origin gh-pages >/dev/null 2>&1; then
257
+ echo "No Pages report branch exists yet."
258
+ exit 0
259
+ fi
260
+ git fetch origin gh-pages
261
+ git worktree add -b gh-pages "$PAGES_DIR" origin/gh-pages
262
+ git -C "$PAGES_DIR" config user.name "github-actions[bot]"
263
+ git -C "$PAGES_DIR" config user.email "41898282+github-actions[bot]@users.noreply.github.com"
264
+ if [ ! -d "$PAGES_DIR/pr/$PR_NUMBER" ]; then
265
+ echo "No report directory exists for PR #$PR_NUMBER."
266
+ exit 0
267
+ fi
268
+ rm -rf -- "$PAGES_DIR/pr/$PR_NUMBER"
269
+ git -C "$PAGES_DIR" add -A -- "pr/$PR_NUMBER"
270
+ if ! git -C "$PAGES_DIR" diff --cached --quiet; then
271
+ git -C "$PAGES_DIR" commit -m "Remove Viewev report for PR #$PR_NUMBER"
272
+ for attempt in 1 2 3 4 5; do
273
+ if git -C "$PAGES_DIR" push origin HEAD:gh-pages; then
274
+ break
275
+ fi
276
+ if [ "$attempt" -eq 5 ]; then exit 1; fi
277
+ git fetch origin gh-pages
278
+ git -C "$PAGES_DIR" merge --no-edit origin/gh-pages
279
+ done
280
+ fi
281
+
282
+ - name: Update pull request comment
283
+ continue-on-error: true
284
+ uses: actions/github-script@v7
285
+ env:
286
+ PR_NUMBER: ${{ github.event.pull_request.number }}
287
+ with:
288
+ script: |
289
+ const marker = '<!-- viewev-report-comment -->';
290
+ const issueNumber = Number(process.env.PR_NUMBER);
291
+ const comments = await github.paginate(github.rest.issues.listComments, {
292
+ owner: context.repo.owner,
293
+ repo: context.repo.repo,
294
+ issue_number: issueNumber,
295
+ per_page: 100,
296
+ });
297
+ const existing = comments.find(
298
+ (comment) =>
299
+ comment.user?.login === 'github-actions[bot]' &&
300
+ comment.body?.includes(marker),
301
+ );
302
+ if (!existing) return;
303
+ const retiredNote = '_Hosted report removed when this pull request closed._';
304
+ const updatedBody = existing.body
305
+ .replace(/\*\*\[Open visual report\]\([^)]+\)\*\*\n?/, `${retiredNote}\n`)
306
+ .replace(
307
+ /\[Open the visual report\]\([^)]+\) for expected, actual and difference images\./,
308
+ retiredNote,
309
+ );
310
+ if (updatedBody !== existing.body) {
311
+ await github.rest.issues.updateComment({
312
+ owner: context.repo.owner,
313
+ repo: context.repo.repo,
314
+ comment_id: existing.id,
315
+ body: updatedBody,
316
+ });
317
+ }
package/docs/impact.md CHANGED
@@ -10,6 +10,11 @@ import cannot be resolved, the project uses a dynamic import pattern that cannot
10
10
  a changed source/configuration file cannot be mapped. This protects coverage when Viewev cannot
11
11
  make a confident selection. `--filter` and `include`/`exclude` still apply after impact selection.
12
12
 
13
+ Package manifests, lockfiles, and Storybook or bundler configuration are treated as global inputs,
14
+ so changing one selects every scenario. For example, adding Viewev to `package.json` and `yarn.lock`
15
+ can make the initial setup PR run the full catalog. Component and story source changes are mapped
16
+ through imports and can select a smaller set on later PRs.
17
+
13
18
  For provider-specific logic, a project can still supply an analyzer module. `viewev test --changed`
14
19
  uses this extension for non-reference runs:
15
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viewev",
3
- "version": "0.1.0-beta.2",
3
+ "version": "0.1.0-beta.4",
4
4
  "description": "Visual evaluation for the web. Open-source visual regression testing for web interfaces.",
5
5
  "license": "MIT",
6
6
  "type": "module",