Skip to content
Open
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ The check also reads source, because some changes no example shows. A merge comm
$ scripts/visual-rc.sh --base v0.1.12 --version 0.1.13 --explain explanations.json 95 99 103
```

When the PRs have already merged, pass `--merged` and name each PR's commit on main, in merge order. The check starts from the previous tag and applies each commit in turn, so squash merges work too.

```bash
$ scripts/visual-rc.sh --merged --base v0.1.13 --version 0.1.14 --explain explanations.json 118=f4de878 119=491308f 120=5e843d9 121=ee1c1b8
```

The report is `visual/rc/<version>/report.md`.

1. Bump `version` in `package.json` in a pull request and merge it.
Expand Down
1 change: 1 addition & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const url = process.env.VISUAL_URL;

export default defineConfig({
testDir: "visual",
testIgnore: "**/visual/rc/**",
snapshotPathTemplate: `${process.env.VISUAL_SNAPSHOTS ?? "visual/baselines"}/{projectName}/{arg}{ext}`,
outputDir: "visual/results",
fullyParallel: true,
Expand Down
29 changes: 12 additions & 17 deletions scripts/visual-rc-report.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { existsSync, readFileSync, writeFileSync } from "node:fs";
import path from "node:path";

const [out, base, explainFile, compare, ...steps] = process.argv.slice(2);
const merged = Boolean(process.env.VISUAL_RC_MERGED);
const prRange = (pr, dots = "...") =>
merged
? `refs/visual-rc/pr-${pr}^1..refs/visual-rc/pr-${pr}`
: `origin/main${dots}refs/visual-rc/pr-${pr}`;
const explanations = explainFile ? JSON.parse(readFileSync(explainFile, "utf8")) : {};
const snapshots = (step) => path.join(out, "snapshots", step);
const diff = (from, to, label) =>
Expand Down Expand Up @@ -34,13 +39,9 @@ const stepLabel = (step) => (step === "1-main" ? "main" : step.replace(/^\d+-pr-
const baselineUpdates = (pr) => {
try {
return new Set(
execFileSync(
"git",
["diff", "--name-only", `origin/main...refs/visual-rc/pr-${pr}`, "--", "visual/baselines"],
{
encoding: "utf8"
}
)
execFileSync("git", ["diff", "--name-only", prRange(pr), "--", "visual/baselines"], {
encoding: "utf8"
})
.split("\n")
.filter(Boolean)
.map((file) => file.replace(/^visual\/baselines\//, ""))
Expand All @@ -60,7 +61,7 @@ const git = (args) => {
// so re-run each merge and flag every changed line outside a conflict region. Generated files are
// skipped: r/ is checked against src/ by `npm run check`, and versions move with every release.
const mergeEdits = (pr) =>
git(["rev-list", "--merges", `origin/main..refs/visual-rc/pr-${pr}`])
git(["rev-list", "--merges", prRange(pr, "..")])
.split("\n")
.filter(Boolean)
.flatMap((sha) => {
Expand Down Expand Up @@ -95,13 +96,7 @@ const unseenStyles = (pr, changes) => {
if (changes.some((change) => change.kind === "changed")) return [];
const files = new Set();
let file = null;
for (const line of git([
"diff",
"-U0",
`origin/main...refs/visual-rc/pr-${pr}`,
"--",
"src/**/*.css"
]).split("\n")) {
for (const line of git(["diff", "-U0", prRange(pr), "--", "src/**/*.css"]).split("\n")) {
if (line.startsWith("diff --git ")) file = line.split(" b/").pop();
else if (/^-(?!--)/.test(line)) files.add(file);
}
Expand Down Expand Up @@ -159,9 +154,9 @@ const img = (step, key, kind) => {
const lines = [
`# Release candidate visual check`,
"",
`Previous tag: \`${base}\`. Steps: main, then ${
`Previous tag: \`${base}\`. Steps: ${merged ? "" : "main, then "}${
steps
.slice(2)
.slice(merged ? 1 : 2)
.map((step) => `#${stepLabel(step)}`)
.join(", ") || "no PRs"
}.`,
Expand Down
26 changes: 20 additions & 6 deletions scripts/visual-rc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#
# Usage: scripts/visual-rc.sh --base v0.1.12 --version 0.1.13 [--explain file.json] [--compare v0.1.10] PR...
# A PR given as N=<ref> merges that ref instead of the PR's head, for a conflict resolved by hand.
# With --merged, every PR is already on main: give each as N=<sha of its commit on main>, in merge
# order. The candidate starts at the base tag instead of main, each step applies that commit, and a
# PR's baseline updates are read from the commit itself, so squash merges work.
# The explanations file maps a step ("main" or a PR number) to globs over snapshot names:
# { "113": { "card-band-actions--*": "Framed card actions keep their own display" } }
# Two source checks block too, explained by key: "merge:<sha7>" for a merge commit on the PR that
Expand All @@ -15,13 +18,14 @@
set -euo pipefail
cd "$(dirname "$0")/.."
root=$PWD
base="" version="" explain="" compare="" prs=()
base="" version="" explain="" compare="" merged="" prs=()
while [ $# -gt 0 ]; do
case "$1" in
--base) base=$2; shift 2 ;;
--version) version=$2; shift 2 ;;
--explain) explain=$(realpath "$2"); shift 2 ;;
--compare) compare=$2; shift 2 ;;
--merged) merged=1; shift ;;
*) prs+=("$1"); shift ;;
esac
done
Expand Down Expand Up @@ -61,7 +65,13 @@ render() {
VISUAL_SNAPSHOTS="$out/snapshots/$name" bash scripts/visual.sh --update-snapshots=all --reporter=dot >"$out/work/$name.log" 2>&1 || true
kill -- -$server 2>/dev/null || true
wait $server 2>/dev/null || true
echo "rendered $name: $(find "$out/snapshots/$name" -name '*.png' | wc -l) snapshots"
(cd "$dir" && for file in "${overlay[@]}"; do
if git ls-files --error-unmatch "$file" >/dev/null 2>&1; then git checkout -q -- "$file"; else rm -f "$file"; fi
done)
local count
count=$(find "$out/snapshots/$name" -name '*.png' 2>/dev/null | wc -l)
[ "$count" -gt 0 ] || { echo "rendered no snapshots for $name, see $out/work/$name.log" >&2; exit 1; }
echo "rendered $name: $count snapshots"
}

steps=()
Expand Down Expand Up @@ -89,9 +99,13 @@ render "$out/work/base" "0-base"
steps+=("0-base")

cand="$out/work/candidate"
add_worktree "$cand" origin/main
render "$cand" "1-main"
steps+=("1-main")
if [ -n "$merged" ]; then
add_worktree "$cand" "$base"
Comment thread
capy-ai[bot] marked this conversation as resolved.
Resolved
else
add_worktree "$cand" origin/main
render "$cand" "1-main"
steps+=("1-main")
fi

i=1
for spec in "${prs[@]}"; do
Expand All @@ -109,4 +123,4 @@ for spec in "${prs[@]}"; do
steps+=("$i-pr-$pr")
done

node scripts/visual-rc-report.mjs "$out" "$base" "$explain" "$compare" "${steps[@]}"
VISUAL_RC_MERGED=$merged node scripts/visual-rc-report.mjs "$out" "$base" "$explain" "$compare" "${steps[@]}"
Loading