From 60dc33cd8fa85b97aa7b78e47fda67f2bdfe7115 Mon Sep 17 00:00:00 2001 From: Simon Davies Date: Mon, 20 Apr 2026 11:35:55 +0100 Subject: [PATCH 1/2] Add job to update golden images Signed-off-by: Simon Davies --- .github/workflows/update-golden.yml | 101 ++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 .github/workflows/update-golden.yml diff --git a/.github/workflows/update-golden.yml b/.github/workflows/update-golden.yml new file mode 100644 index 0000000..236ccbd --- /dev/null +++ b/.github/workflows/update-golden.yml @@ -0,0 +1,101 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json +# +# Regenerate PDF visual regression golden baselines on a CI runner +# and open a PR with the updated PNGs. +# +# Workflow: +# 1. Code change causes golden drift → pr-validate CI fails +# 2. Developer triggers this workflow (optionally targeting a branch) +# 3. Goldens are regenerated on the same runner/fonts as CI +# 4. A PR is opened with the visual diff for review +# +# Usage: +# gh workflow run update-golden.yml -f branch=my-feature-branch + +name: Update Golden Baselines + +on: + workflow_dispatch: + inputs: + branch: + description: "Branch to regenerate goldens on (default: main)" + required: false + default: "main" + type: string + +permissions: + contents: write + pull-requests: write + +jobs: + update-goldens: + name: Regenerate PDF Goldens + runs-on: + [ + self-hosted, + Linux, + X64, + "1ES.Pool=hld-kvm-amd", + "JobId=update-golden-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}", + ] + steps: + - uses: actions/checkout@v6 + with: + ref: ${{ inputs.branch }} + # Full history not needed, but we need push access + token: ${{ secrets.GITHUB_TOKEN }} + + - uses: actions/setup-node@v6 + with: + node-version: "22" + + - uses: hyperlight-dev/ci-setup-workflow@v1.9.0 + with: + rust-toolchain: "1.89" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Install PDF test dependencies + run: | + sudo apt-get update -qq + sudo apt-get install -y -qq poppler-utils qpdf fonts-dejavu-core + + - name: Setup + run: just setup + + - name: Regenerate golden baselines + run: UPDATE_GOLDEN=1 npx vitest run tests/pdf-visual.test.ts + + - name: Check for changes + id: diff + run: | + if git diff --quiet tests/golden/; then + echo "changed=false" >> "$GITHUB_OUTPUT" + echo "✅ No golden changes detected — baselines already match." + else + echo "changed=true" >> "$GITHUB_OUTPUT" + echo "📸 Golden baselines updated:" + git diff --stat tests/golden/ + fi + + - name: Create Pull Request + if: steps.diff.outputs.changed == 'true' + uses: peter-evans/create-pull-request@v7 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: "test: update PDF golden baselines from CI" + branch: update-golden/${{ inputs.branch }} + base: ${{ inputs.branch }} + title: "test: update PDF golden baselines" + body: | + đŸ–ŧī¸ **Automated golden baseline update** + + Regenerated PDF visual regression baselines on the CI runner + (`hld-kvm-amd` pool with `fonts-dejavu-core`). + + **Source branch**: `${{ inputs.branch }}` + **Triggered by**: @${{ github.actor }} + + Review the PNG diffs below to verify the visual changes are expected. + labels: test,automated + delete-branch: true From a1e5294fc90f5bbc681770d4b6abaea80b953f8b Mon Sep 17 00:00:00 2001 From: Simon Davies Date: Mon, 20 Apr 2026 13:26:10 +0100 Subject: [PATCH 2/2] Review Feedabck Signed-off-by: Simon Davies --- .github/workflows/update-golden.yml | 65 ++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/.github/workflows/update-golden.yml b/.github/workflows/update-golden.yml index 236ccbd..bf1126b 100644 --- a/.github/workflows/update-golden.yml +++ b/.github/workflows/update-golden.yml @@ -27,6 +27,10 @@ permissions: contents: write pull-requests: write +concurrency: + group: update-golden-${{ inputs.branch }} + cancel-in-progress: true + jobs: update-goldens: name: Regenerate PDF Goldens @@ -78,24 +82,45 @@ jobs: git diff --stat tests/golden/ fi - - name: Create Pull Request + - name: Create golden update PR if: steps.diff.outputs.changed == 'true' - uses: peter-evans/create-pull-request@v7 - with: - token: ${{ secrets.GITHUB_TOKEN }} - commit-message: "test: update PDF golden baselines from CI" - branch: update-golden/${{ inputs.branch }} - base: ${{ inputs.branch }} - title: "test: update PDF golden baselines" - body: | - đŸ–ŧī¸ **Automated golden baseline update** - - Regenerated PDF visual regression baselines on the CI runner - (`hld-kvm-amd` pool with `fonts-dejavu-core`). - - **Source branch**: `${{ inputs.branch }}` - **Triggered by**: @${{ github.actor }} - - Review the PNG diffs below to verify the visual changes are expected. - labels: test,automated - delete-branch: true + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + BRANCH="update-golden/${{ inputs.branch }}" + + # Configure git for the commit + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + # Stage ONLY golden files — nothing else (e.g. package-lock.json from setup) + git add tests/golden/ + + # Create or update the golden update branch + git checkout -B "$BRANCH" + git commit -m "test: update PDF golden baselines from CI" + git push --force-with-lease origin "$BRANCH" + + # Create PR if one doesn't already exist for this branch + if ! gh pr view "$BRANCH" --json state -q '.state' 2>/dev/null | grep -q OPEN; then + gh pr create \ + --base "${{ inputs.branch }}" \ + --head "$BRANCH" \ + --title "test: update PDF golden baselines" \ + --body "$(cat <<'EOF' + đŸ–ŧī¸ **Automated golden baseline update** + + Regenerated PDF visual regression baselines on the CI runner + (`hld-kvm-amd` pool with `fonts-dejavu-core`). + + **Source branch**: `${{ inputs.branch }}` + **Triggered by**: @${{ github.actor }} + + Review the PNG diffs below to verify the visual changes are expected. + EOF + )" \ + --label "test" \ + --label "automated" + else + echo "â„šī¸ PR already exists for $BRANCH — pushed updated goldens." + fi