03 - Update Snapshots #1416
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 03 - Update Snapshots | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| delete_snapshots: | |
| description: 'Delete existing snapshots before update?' | |
| required: false | |
| default: false | |
| type: boolean | |
| concurrency: | |
| group: 'workflow-${{ github.workflow }}-${{ github.ref }}' | |
| cancel-in-progress: true | |
| jobs: | |
| update: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - name: components | |
| path: packages/components | |
| type: unit | |
| - name: hydrate-server | |
| path: packages/tools/hydrate-server | |
| type: unit | |
| - name: hydrate | |
| path: packages/adapters/hydrate | |
| type: unit | |
| - name: theme-default | |
| path: packages/themes/default | |
| type: e2e | |
| - name: theme-kern | |
| path: packages/themes/kern | |
| type: e2e | |
| steps: | |
| - name: Checkout branch | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ github.ref_name }} | |
| persist-credentials: false | |
| - uses: ./.github/actions/pnpm-setup | |
| - name: Install Playwright browsers | |
| if: matrix.type == 'e2e' | |
| run: npx playwright install --with-deps firefox | |
| - name: Build | |
| run: pnpm --filter @public-ui/sample-react^... build | |
| - name: Purge existing snapshots | |
| if: inputs.delete_snapshots == true | |
| run: | | |
| if [ "${{ matrix.type }}" = "e2e" ]; then | |
| find ${{ matrix.path }} -name '*.png' -path '*/snapshots/*' | grep -v 'node_modules' | xargs --no-run-if-empty rm -f | |
| else | |
| find ${{ matrix.path }} \( -path '*/node_modules' -prune \) -o -path '*/__snapshots__/*' -type f -print | xargs --no-run-if-empty rm -f | |
| fi | |
| - name: Run snapshot update | |
| run: pnpm --filter @public-ui/${{ matrix.name }} test:update:${{ matrix.type }} | |
| - name: Git status after generating snapshots | |
| run: git status | |
| - name: Package snapshot changes | |
| run: | | |
| if [ "${{ inputs.delete_snapshots }}" = "true" ]; then | |
| # All snapshots were purged and regenerated from scratch – capture every file on disk, | |
| # including those whose content is identical to HEAD (git diff would miss those). | |
| find ${{ matrix.path }} \( -path '*/node_modules' -prune \) -o \( -path '*/__snapshots__/*' -o -path '*/snapshots/*' \) -type f -print \ | |
| | tar cf snapshots.tar -T - 2>/dev/null || tar cf snapshots.tar --files-from /dev/null | |
| else | |
| # Only capture files that actually changed (efficient for normal updates). | |
| { | |
| git diff --name-only --diff-filter=d HEAD -- ${{ matrix.path }} | |
| git ls-files --others --exclude-standard -- ${{ matrix.path }} | |
| } | grep -E '(__snapshots__|snapshots)/' | tar cf snapshots.tar -T - 2>/dev/null || tar cf snapshots.tar --files-from /dev/null | |
| fi | |
| - name: Upload snapshot artifacts | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: snapshots-${{ matrix.name }} | |
| path: snapshots.tar | |
| if-no-files-found: ignore | |
| retention-days: 1 | |
| push: | |
| needs: update | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/create-github-app-token@v3 | |
| id: app-token | |
| with: | |
| app-id: ${{ secrets.APP_ID }} | |
| private-key: ${{ secrets.PRIVATE_KEY }} | |
| - name: Get GitHub App User ID | |
| id: get-user-id | |
| run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT" | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| - name: Checkout branch | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ github.ref_name }} | |
| token: ${{ steps.app-token.outputs.token }} | |
| - name: Purge existing snapshots (optional) | |
| if: inputs.delete_snapshots == true | |
| run: | | |
| find packages -name '*.png' -path '*/snapshots/*' | grep -v 'node_modules' | xargs --no-run-if-empty rm -f | |
| find packages \( -path '*/node_modules' -prune \) -o -path '*/__snapshots__/*' -type f -print | xargs --no-run-if-empty rm -f | |
| - name: Download snapshot artifacts | |
| uses: actions/download-artifact@v8 | |
| with: | |
| pattern: snapshots-* | |
| path: snapshot-artifacts | |
| - name: Apply snapshot updates | |
| run: | | |
| for dir in snapshot-artifacts/snapshots-*/; do | |
| if [ -f "${dir}snapshots.tar" ]; then | |
| tar xf "${dir}snapshots.tar" | |
| fi | |
| done | |
| rm -rf snapshot-artifacts | |
| - name: Stage snapshot changes | |
| run: | | |
| # Stage updated/new snapshot files (skip gitignored paths) | |
| find packages \( -path '*/node_modules' -prune \) -o \( -path '*/__snapshots__/*' -o -path '*/snapshots/*' \) -type f -print \ | |
| | (git check-ignore --stdin --non-matching --verbose || test $? = 1) \ | |
| | { grep '^::' || true; } | cut -f2 \ | |
| | xargs --no-run-if-empty git add -- | |
| # Also stage deletions (e.g. snapshots for removed tests) | |
| { git diff --name-only --diff-filter=D HEAD || true; } | grep -E '(__snapshots__|snapshots)/' | xargs --no-run-if-empty git add -- | |
| - name: Git status after staging | |
| run: git status | |
| - name: Commit and push changes | |
| uses: stefanzweifel/git-auto-commit-action@v7 | |
| with: | |
| commit_message: Update all snapshots | |
| # Disable internal git add so that only the files staged above are committed. | |
| file_pattern: '' | |
| commit_user_name: '${{ steps.app-token.outputs.app-slug }}[bot]' | |
| commit_user_email: '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com' |