03 - Update Snapshots #1406
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.event.pull_request.number || github.ref }}' | |
| cancel-in-progress: true | |
| jobs: | |
| update-snapshots: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - name: components-unit | |
| command: pnpm --filter @public-ui/components test:update:unit | |
| type: unit | |
| - name: hydrate-server-unit | |
| command: pnpm --filter @public-ui/hydrate-server test:update:unit | |
| type: unit | |
| - name: hydrate-unit | |
| command: pnpm --filter @public-ui/hydrate test:update:unit | |
| type: unit | |
| - name: theme-default-e2e | |
| command: pnpm --filter @public-ui/theme-default test:update:e2e | |
| type: e2e | |
| - name: theme-kern-e2e | |
| command: pnpm --filter @public-ui/theme-kern test:update:e2e | |
| type: e2e | |
| - name: test-tag-name-transformer-e2e | |
| command: pnpm --filter @public-ui/test-tag-name-transformer test:update:e2e | |
| 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 packages -name '*.png' -path '*/snapshots/*' | grep -v 'node_modules' | xargs --no-run-if-empty rm -f | |
| else | |
| find packages \( -path '*/node_modules' -prune \) -o -path '*/__snapshots__/*' -type f -print | xargs --no-run-if-empty rm -f | |
| fi | |
| - name: Run snapshot update | |
| run: ${{ matrix.command }} | |
| - name: Package snapshot changes | |
| run: | | |
| { | |
| git diff --name-only --diff-filter=d HEAD | |
| git ls-files --others --exclude-standard | |
| } | grep -E '(__snapshots__|snapshots)/' | tar cf snapshots.tar -T - 2>/dev/null || tar cf snapshots.tar --files-from /dev/null | |
| - 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-snapshots | |
| 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 | |
| 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 | |
| - name: Display git status | |
| run: git status | |
| - name: Stage snapshot changes | |
| run: find packages \( -path '*/node_modules' -prune \) -o \( -path '*/__snapshots__/*' -o -path '*/snapshots/*' \) -print | xargs --no-run-if-empty git add -- | |
| - name: Commit and push changes | |
| uses: stefanzweifel/git-auto-commit-action@v7 | |
| with: | |
| commit_message: Update all snapshots | |
| 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' |