Skip to content

Commit 50cab97

Browse files
authored
Add job to update golden images (#61)
* Add job to update golden images Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com> * Review Feedabck Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com> --------- Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
1 parent 5cb2bcc commit 50cab97

1 file changed

Lines changed: 126 additions & 0 deletions

File tree

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
#
3+
# Regenerate PDF visual regression golden baselines on a CI runner
4+
# and open a PR with the updated PNGs.
5+
#
6+
# Workflow:
7+
# 1. Code change causes golden drift → pr-validate CI fails
8+
# 2. Developer triggers this workflow (optionally targeting a branch)
9+
# 3. Goldens are regenerated on the same runner/fonts as CI
10+
# 4. A PR is opened with the visual diff for review
11+
#
12+
# Usage:
13+
# gh workflow run update-golden.yml -f branch=my-feature-branch
14+
15+
name: Update Golden Baselines
16+
17+
on:
18+
workflow_dispatch:
19+
inputs:
20+
branch:
21+
description: "Branch to regenerate goldens on (default: main)"
22+
required: false
23+
default: "main"
24+
type: string
25+
26+
permissions:
27+
contents: write
28+
pull-requests: write
29+
30+
concurrency:
31+
group: update-golden-${{ inputs.branch }}
32+
cancel-in-progress: true
33+
34+
jobs:
35+
update-goldens:
36+
name: Regenerate PDF Goldens
37+
runs-on:
38+
[
39+
self-hosted,
40+
Linux,
41+
X64,
42+
"1ES.Pool=hld-kvm-amd",
43+
"JobId=update-golden-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}",
44+
]
45+
steps:
46+
- uses: actions/checkout@v6
47+
with:
48+
ref: ${{ inputs.branch }}
49+
# Full history not needed, but we need push access
50+
token: ${{ secrets.GITHUB_TOKEN }}
51+
52+
- uses: actions/setup-node@v6
53+
with:
54+
node-version: "22"
55+
56+
- uses: hyperlight-dev/ci-setup-workflow@v1.9.0
57+
with:
58+
rust-toolchain: "1.89"
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
62+
- name: Install PDF test dependencies
63+
run: |
64+
sudo apt-get update -qq
65+
sudo apt-get install -y -qq poppler-utils qpdf fonts-dejavu-core
66+
67+
- name: Setup
68+
run: just setup
69+
70+
- name: Regenerate golden baselines
71+
run: UPDATE_GOLDEN=1 npx vitest run tests/pdf-visual.test.ts
72+
73+
- name: Check for changes
74+
id: diff
75+
run: |
76+
if git diff --quiet tests/golden/; then
77+
echo "changed=false" >> "$GITHUB_OUTPUT"
78+
echo "✅ No golden changes detected — baselines already match."
79+
else
80+
echo "changed=true" >> "$GITHUB_OUTPUT"
81+
echo "📸 Golden baselines updated:"
82+
git diff --stat tests/golden/
83+
fi
84+
85+
- name: Create golden update PR
86+
if: steps.diff.outputs.changed == 'true'
87+
env:
88+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
run: |
90+
BRANCH="update-golden/${{ inputs.branch }}"
91+
92+
# Configure git for the commit
93+
git config user.name "github-actions[bot]"
94+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
95+
96+
# Stage ONLY golden files — nothing else (e.g. package-lock.json from setup)
97+
git add tests/golden/
98+
99+
# Create or update the golden update branch
100+
git checkout -B "$BRANCH"
101+
git commit -m "test: update PDF golden baselines from CI"
102+
git push --force-with-lease origin "$BRANCH"
103+
104+
# Create PR if one doesn't already exist for this branch
105+
if ! gh pr view "$BRANCH" --json state -q '.state' 2>/dev/null | grep -q OPEN; then
106+
gh pr create \
107+
--base "${{ inputs.branch }}" \
108+
--head "$BRANCH" \
109+
--title "test: update PDF golden baselines" \
110+
--body "$(cat <<'EOF'
111+
🖼️ **Automated golden baseline update**
112+
113+
Regenerated PDF visual regression baselines on the CI runner
114+
(`hld-kvm-amd` pool with `fonts-dejavu-core`).
115+
116+
**Source branch**: `${{ inputs.branch }}`
117+
**Triggered by**: @${{ github.actor }}
118+
119+
Review the PNG diffs below to verify the visual changes are expected.
120+
EOF
121+
)" \
122+
--label "test" \
123+
--label "automated"
124+
else
125+
echo "ℹ️ PR already exists for $BRANCH — pushed updated goldens."
126+
fi

0 commit comments

Comments
 (0)