diff --git a/README.md b/README.md index 1fd126c..04c8f75 100644 --- a/README.md +++ b/README.md @@ -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//report.md`. 1. Bump `version` in `package.json` in a pull request and merge it. diff --git a/playwright.config.ts b/playwright.config.ts index 92d04b7..4f4e56d 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -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, diff --git a/scripts/visual-rc-report.mjs b/scripts/visual-rc-report.mjs index 2b759d4..148fd51 100644 --- a/scripts/visual-rc-report.mjs +++ b/scripts/visual-rc-report.mjs @@ -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) => @@ -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\//, "")) @@ -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) => { @@ -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); } @@ -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" }.`, diff --git a/scripts/visual-rc.sh b/scripts/visual-rc.sh index 92e07bd..e3a4953 100755 --- a/scripts/visual-rc.sh +++ b/scripts/visual-rc.sh @@ -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= 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=, 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:" for a merge commit on the PR that @@ -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 @@ -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=() @@ -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" +else + add_worktree "$cand" origin/main + render "$cand" "1-main" + steps+=("1-main") +fi i=1 for spec in "${prs[@]}"; do @@ -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[@]}"