|
| 1 | +name: Update Snapshots on a PR |
| 2 | +description: | |
| 3 | + Runs previously failed snapshot tests, and commits the changes. |
| 4 | +
|
| 5 | + Your PR will receive a commit with the changes so you can manually verify before merging. |
| 6 | +
|
| 7 | +on: |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + pr_number: |
| 11 | + description: 'Pull Request Number (Warning: This action will push a commit to the referenced PR)' |
| 12 | + required: true |
| 13 | + type: number |
| 14 | + |
| 15 | +permissions: |
| 16 | + pull-requests: write |
| 17 | + contents: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + update-pr-with-snapshots: |
| 21 | + name: Update PR With Snapshots |
| 22 | + runs-on: macos-14 |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + - name: Checkout PR ${{ github.event.inputs.pr_number }} |
| 26 | + if: github.event_name == 'workflow_dispatch' |
| 27 | + run: gh pr checkout ${{ github.event.inputs.pr_number }} |
| 28 | + env: |
| 29 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + |
| 31 | + - name: Use Node.js |
| 32 | + uses: actions/setup-node@v4 |
| 33 | + with: |
| 34 | + node-version-file: '.nvmrc' |
| 35 | + - uses: actions/cache@v4 |
| 36 | + with: |
| 37 | + path: | |
| 38 | + ~/.npm |
| 39 | + ~/.cache/ms-playwright |
| 40 | + key: ${{ runner.os }}-node-playwright-${{ hashFiles('**/package-lock.json') }} |
| 41 | + restore-keys: | |
| 42 | + ${{ runner.os }}-node-playwright- |
| 43 | + ${{ runner.os }}-node- |
| 44 | +
|
| 45 | + - name: Install dependencies |
| 46 | + run: npm ci |
| 47 | + |
| 48 | + - name: Build all |
| 49 | + run: npm run build |
| 50 | + |
| 51 | + - name: Install Playwright Browsers |
| 52 | + run: npx playwright install --with-deps |
| 53 | + |
| 54 | + - name: Run Screenshot tests |
| 55 | + id: screenshot_tests |
| 56 | + run: npm run test-int-snapshots |
| 57 | + |
| 58 | + - if: ${{ steps.screenshot_tests.conclusion == 'success' }} |
| 59 | + run: | |
| 60 | + echo "nothing to update - tests all passed" |
| 61 | +
|
| 62 | + - name: Re-Running Playwright to update snapshots |
| 63 | + id: screenshot_tests_update |
| 64 | + if: ${{ failure() && steps.screenshot_tests.conclusion == 'failure' }} |
| 65 | + run: npm run test-int-snapshots-update |
| 66 | + |
| 67 | + - name: Commit the updated files to the PR branch |
| 68 | + if: ${{ failure() && steps.screenshot_tests_update.conclusion == 'success' }} |
| 69 | + env: |
| 70 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + run: | |
| 72 | + # Configure Git with a bot's username and email for committing changes |
| 73 | + # This makes it easy to identify in the PR |
| 74 | + git config user.name "github-actions[bot]" |
| 75 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 76 | +
|
| 77 | + # Stage all updated PNG files for commit |
| 78 | + git add "*.png" |
| 79 | +
|
| 80 | + # Commit the changes with a descriptive message |
| 81 | + git commit -m "Updated snapshots via workflow" |
| 82 | +
|
| 83 | + # Push the changes to the current branch in the PR |
| 84 | + git push origin HEAD |
0 commit comments