A local-first personal finance app
Refactor VRT workflow to parallelize browser and desktop tests (#7641)
Matiss Janis Aboltins3104503a8a33
diff --git a/.github/workflows/vrt-update-apply.yml b/.github/workflows/vrt-update-apply.ymlindex 2cddd69ab1..d6358fb3fe 100644--- a/.github/workflows/vrt-update-apply.yml+++ b/.github/workflows/vrt-update-apply.yml@@ -75,9 +75,12 @@ jobs:echo "Found patch file: $PATCH_FILE"- # Validate patch only contains PNG files+ # Validate patch only contains PNG files. `git format-patch` emits a+ # `GIT binary patch` block for PNGs (no +++/--- lines), so check+ # `diff --git` headers — those are present for both text and binary.echo "Validating patch contains only PNG files..."- if grep -E '^(\+\+\+|---) [ab]/' "$PATCH_FILE" | grep -v '\.png$'; then+ if grep -E '^diff --git ' "$PATCH_FILE" \+ | grep -vE '^diff --git a/[^[:space:]]+\.png b/[^[:space:]]+\.png$'; thenecho "ERROR: Patch contains non-PNG files! Rejecting for security."echo "applied=false" >> "$GITHUB_OUTPUT"echo "error=Patch validation failed: contains non-PNG files" >> "$GITHUB_OUTPUT"@@ -85,7 +88,7 @@ jobs:fi# Extract file list for verification- FILES_CHANGED=$(grep -E '^\+\+\+ b/' "$PATCH_FILE" | sed 's/^+++ b\///' | wc -l)+ FILES_CHANGED=$(grep -cE '^diff --git ' "$PATCH_FILE")echo "Patch modifies $FILES_CHANGED PNG file(s)"# Configure gitdiff --git a/.github/workflows/vrt-update-generate.yml b/.github/workflows/vrt-update-generate.ymlindex 8fb2f165da..dbf9cf27c3 100644--- a/.github/workflows/vrt-update-generate.yml+++ b/.github/workflows/vrt-update-generate.yml@@ -36,15 +36,16 @@ jobs:content: 'eyes'});- generate-vrt-updates:- name: Generate VRT Updates+ get-pr:+ name: Resolve PR detailsruns-on: ubuntu-latest- # Only run on PR comments containing /update-vrtif: >github.event.issue.pull_request &&startsWith(github.event.comment.body, '/update-vrt')- container:- image: mcr.microsoft.com/playwright:v1.59.1-jammy+ outputs:+ head_sha: ${{ steps.pr.outputs.head_sha }}+ head_ref: ${{ steps.pr.outputs.head_ref }}+ head_repo: ${{ steps.pr.outputs.head_repo }}steps:- name: Get PR detailsid: pr@@ -60,9 +61,125 @@ jobs:core.setOutput('head_ref', pr.head.ref);core.setOutput('head_repo', pr.head.repo.full_name);+ build-web:+ name: Build web bundle+ runs-on: ubuntu-latest+ needs: get-pr+ container:+ image: mcr.microsoft.com/playwright:v1.59.1-jammy+ steps:+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2+ with:+ ref: ${{ needs.get-pr.outputs.head_sha }}+ persist-credentials: false++ - name: Trust workspace directory+ run: git config --global --add safe.directory "$GITHUB_WORKSPACE"+ shell: bash++ - name: Set up environment+ uses: ./.github/actions/setup+ with:+ download-translations: 'false'+ - name: Build browser bundle+ # REACT_APP_NETLIFY=true keeps the "Create test file" button in the+ # production bundle — every VRT test's beforeEach relies on it via+ # ConfigurationPage.createTestFile().+ env:+ REACT_APP_NETLIFY: 'true'+ run: |+ yarn workspace plugins-service build+ yarn workspace @actual-app/crdt build+ yarn workspace @actual-app/core build:browser+ yarn workspace @actual-app/web build:browser+ - name: Upload build artifact+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1+ with:+ name: desktop-client-build+ path: packages/desktop-client/build/+ retention-days: 1+ overwrite: true++ browser-vrt:+ name: Browser VRT (shard ${{ matrix.shard }}/3)+ runs-on: ubuntu-latest+ needs: [get-pr, build-web]+ strategy:+ fail-fast: false+ matrix:+ shard: [1, 2, 3]+ container:+ image: mcr.microsoft.com/playwright:v1.59.1-jammy+ env:+ E2E_USE_BUILD: '1'+ steps:+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2+ with:+ ref: ${{ needs.get-pr.outputs.head_sha }}+ persist-credentials: false++ - name: Trust workspace directory+ run: git config --global --add safe.directory "$GITHUB_WORKSPACE"+ shell: bash++ - name: Set up environment+ uses: ./.github/actions/setup+ with:+ download-translations: 'false'+ - name: Download web build+ uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1+ with:+ name: desktop-client-build+ path: packages/desktop-client/build/+ - name: Run VRT Tests+ continue-on-error: true+ run: yarn vrt --update-snapshots --shard=${{ matrix.shard }}/3+ - name: Create shard patch with PNG changes only+ id: create-patch+ run: |+ git config --global user.name "github-actions[bot]"+ git config --global user.email "github-actions[bot]@users.noreply.github.com"++ git add "**/*.png"++ if git diff --staged --quiet; then+ echo "has_changes=false" >> "$GITHUB_OUTPUT"+ echo "No VRT changes in this shard"+ exit 0+ fi++ echo "has_changes=true" >> "$GITHUB_OUTPUT"++ git commit -m "Update VRT screenshots (browser shard ${{ matrix.shard }})"+ git format-patch -1 HEAD --stdout > vrt-shard.patch++ # Validate patch only contains PNG files. `git format-patch` emits a+ # `GIT binary patch` block for PNGs (no +++/--- lines), so check+ # `diff --git` headers — those are present for both text and binary.+ if grep -E '^diff --git ' vrt-shard.patch \+ | grep -vE '^diff --git a/[^[:space:]]+\.png b/[^[:space:]]+\.png$'; then+ echo "ERROR: Shard patch contains non-PNG files!"+ exit 1+ fi+ - name: Upload shard patch+ if: steps.create-patch.outputs.has_changes == 'true'+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1+ with:+ name: vrt-shard-browser-${{ matrix.shard }}+ path: vrt-shard.patch+ retention-days: 1+ overwrite: true++ desktop-vrt:+ name: Desktop VRT+ runs-on: ubuntu-latest+ needs: get-pr+ container:+ image: mcr.microsoft.com/playwright:v1.59.1-jammy+ steps:- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2with:- ref: ${{ steps.pr.outputs.head_sha }}+ ref: ${{ needs.get-pr.outputs.head_sha }}persist-credentials: false- name: Trust workspace directory@@ -78,45 +195,120 @@ jobs:- name: Install build toolsrun: apt-get update && apt-get install -y build-essential python3- - name: Run VRT Tests on Desktop app+ - name: Run Desktop VRT Testscontinue-on-error: truerun: |yarn rebuild-electronxvfb-run --auto-servernum --server-args="-screen 0 1920x1080x24" -- yarn e2e:desktop --update-snapshots- - name: Run VRT Tests- continue-on-error: true- run: yarn vrt --update-snapshots-- - name: Create patch with PNG changes only+ - name: Create shard patch with PNG changes onlyid: create-patchrun: |git config --global user.name "github-actions[bot]"git config --global user.email "github-actions[bot]@users.noreply.github.com"- # Stage only PNG filesgit add "**/*.png"- # Check if there are any changesif git diff --staged --quiet; thenecho "has_changes=false" >> "$GITHUB_OUTPUT"- echo "No VRT changes to commit"+ echo "No VRT changes in desktop shard"+ exit 0+ fi++ echo "has_changes=true" >> "$GITHUB_OUTPUT"++ git commit -m "Update VRT screenshots (desktop)"+ git format-patch -1 HEAD --stdout > vrt-shard.patch++ # See validation note in browser-vrt above.+ if grep -E '^diff --git ' vrt-shard.patch \+ | grep -vE '^diff --git a/[^[:space:]]+\.png b/[^[:space:]]+\.png$'; then+ echo "ERROR: Desktop shard patch contains non-PNG files!"+ exit 1+ fi++ - name: Upload shard patch+ if: steps.create-patch.outputs.has_changes == 'true'+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1+ with:+ name: vrt-shard-desktop+ path: vrt-shard.patch+ retention-days: 1+ overwrite: true++ merge-patch:+ name: Merge VRT Patches+ runs-on: ubuntu-latest+ needs: [get-pr, browser-vrt, desktop-vrt]+ if: ${{ !cancelled() && needs.get-pr.result == 'success' }}+ container:+ image: mcr.microsoft.com/playwright:v1.59.1-jammy+ steps:+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2+ with:+ ref: ${{ needs.get-pr.outputs.head_sha }}+ persist-credentials: false++ - name: Download all shard patches+ uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1+ with:+ path: /tmp/shard-patches+ pattern: vrt-shard-*++ - name: Merge shard patches+ id: create-patch+ run: |+ git config --global --add safe.directory "$GITHUB_WORKSPACE"+ git config --global user.name "github-actions[bot]"+ git config --global user.email "github-actions[bot]@users.noreply.github.com"++ shopt -s nullglob+ patches=(/tmp/shard-patches/*/vrt-shard.patch)++ if [ ${#patches[@]} -eq 0 ]; then+ echo "has_changes=false" >> "$GITHUB_OUTPUT"+ echo "No shard patches to merge"+ exit 0+ fi++ # Defense in depth: re-validate every shard patch before applying.+ # See validation note in browser-vrt above for why we match+ # `diff --git` headers instead of +++/--- lines.+ for patch in "${patches[@]}"; do+ echo "Validating $patch"+ if grep -E '^diff --git ' "$patch" \+ | grep -vE '^diff --git a/[^[:space:]]+\.png b/[^[:space:]]+\.png$'; then+ echo "ERROR: $patch contains non-PNG files!"+ exit 1+ fi+ done++ # Apply each shard patch. Shards touch disjoint PNG files so+ # order does not matter. --index stages the applied changes.+ for patch in "${patches[@]}"; do+ echo "Applying $patch"+ git apply --index "$patch"+ done++ if git diff --staged --quiet; then+ echo "has_changes=false" >> "$GITHUB_OUTPUT"+ echo "No VRT changes after merge"exit 0fiecho "has_changes=true" >> "$GITHUB_OUTPUT"- # Create commit and patchgit commit -m "Update VRT screenshots"git format-patch -1 HEAD --stdout > vrt-update.patch- # Validate patch only contains PNG files- if grep -E '^(\+\+\+|---) [ab]/' vrt-update.patch | grep -v '\.png$'; then- echo "ERROR: Patch contains non-PNG files!"+ # Final guard on the combined patch.+ if grep -E '^diff --git ' vrt-update.patch \+ | grep -vE '^diff --git a/[^[:space:]]+\.png b/[^[:space:]]+\.png$'; then+ echo "ERROR: Merged patch contains non-PNG files!"exit 1fi- echo "Patch created successfully with PNG changes only"+ echo "Merged patch created successfully with PNG changes only"- name: Upload patch artifactif: steps.create-patch.outputs.has_changes == 'true'@@ -131,11 +323,11 @@ jobs:run: |mkdir -p pr-metadataecho "${{ github.event.issue.number }}" > pr-metadata/pr-number.txt- echo "${STEPS_PR_OUTPUTS_HEAD_REF}" > pr-metadata/head-ref.txt- echo "${STEPS_PR_OUTPUTS_HEAD_REPO}" > pr-metadata/head-repo.txt+ echo "${NEEDS_GET_PR_OUTPUTS_HEAD_REF}" > pr-metadata/head-ref.txt+ echo "${NEEDS_GET_PR_OUTPUTS_HEAD_REPO}" > pr-metadata/head-repo.txtenv:- STEPS_PR_OUTPUTS_HEAD_REF: ${{ steps.pr.outputs.head_ref }}- STEPS_PR_OUTPUTS_HEAD_REPO: ${{ steps.pr.outputs.head_repo }}+ NEEDS_GET_PR_OUTPUTS_HEAD_REF: ${{ needs.get-pr.outputs.head_ref }}+ NEEDS_GET_PR_OUTPUTS_HEAD_REPO: ${{ needs.get-pr.outputs.head_repo }}- name: Upload PR metadataif: steps.create-patch.outputs.has_changes == 'true'diff --git a/upcoming-release-notes/7641.md b/upcoming-release-notes/7641.mdnew file mode 100644index 0000000000..9db6f25c6e--- /dev/null+++ b/upcoming-release-notes/7641.md@@ -0,0 +1,6 @@+---+category: Maintenance+authors: [MatissJanis]+---++Refactor VRT workflow to enable parallel execution of browser and desktop tests.