|
55 | 55 | echo "No file changes after update-snapshots." |
56 | 56 | fi |
57 | 57 |
|
| 58 | + - name: Create snapshot patch |
| 59 | + if: steps.detect_changes.outputs.changed == 'true' |
| 60 | + shell: bash |
| 61 | + run: | |
| 62 | + git add -A |
| 63 | + git diff --cached --binary > playwright-snapshots.patch |
| 64 | +
|
| 65 | + - name: Upload snapshot patch |
| 66 | + if: steps.detect_changes.outputs.changed == 'true' |
| 67 | + uses: actions/upload-artifact@v4 |
| 68 | + with: |
| 69 | + name: playwright-snapshot-patch |
| 70 | + path: playwright-snapshots.patch |
| 71 | + retention-days: 14 |
| 72 | + |
58 | 73 | - name: Upload Playwright report |
59 | 74 | if: always() |
60 | 75 | uses: actions/upload-artifact@v4 |
|
75 | 90 | needs: visual-check |
76 | 91 | if: needs.visual-check.outputs.snapshots_changed == 'true' |
77 | 92 | runs-on: ubuntu-latest |
| 93 | + permissions: |
| 94 | + contents: write |
78 | 95 | environment: |
79 | 96 | name: playwright-snapshot-approval |
80 | 97 | steps: |
81 | | - - name: Approved snapshot updates |
82 | | - run: echo "Snapshot updates approved." |
| 98 | + - name: Resolve target branch |
| 99 | + id: resolve_branch |
| 100 | + shell: bash |
| 101 | + run: | |
| 102 | + branch_name="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}" |
| 103 | +
|
| 104 | + if [[ -z "$branch_name" ]]; then |
| 105 | + echo "Unable to determine target branch." |
| 106 | + exit 1 |
| 107 | + fi |
| 108 | +
|
| 109 | + if [[ "$branch_name" == "main" ]]; then |
| 110 | + echo "Snapshot updates cannot be auto-committed to main." |
| 111 | + exit 1 |
| 112 | + fi |
| 113 | +
|
| 114 | + echo "branch_name=$branch_name" >> "$GITHUB_OUTPUT" |
| 115 | + echo "Snapshot updates approved for branch: $branch_name" |
| 116 | +
|
| 117 | + - name: Checkout target branch |
| 118 | + uses: actions/checkout@v4 |
| 119 | + with: |
| 120 | + ref: ${{ steps.resolve_branch.outputs.branch_name }} |
| 121 | + |
| 122 | + - name: Download snapshot patch |
| 123 | + uses: actions/download-artifact@v4 |
| 124 | + with: |
| 125 | + name: playwright-snapshot-patch |
| 126 | + path: ${{ runner.temp }}/playwright-snapshot-patch |
| 127 | + |
| 128 | + - name: Apply snapshot patch |
| 129 | + shell: bash |
| 130 | + run: git apply --index --reject --whitespace=nowarn "$RUNNER_TEMP/playwright-snapshot-patch/playwright-snapshots.patch" |
| 131 | + |
| 132 | + - name: Commit snapshot updates |
| 133 | + id: commit_snapshot_updates |
| 134 | + shell: bash |
| 135 | + run: | |
| 136 | + if [[ -z "$(git status --porcelain)" ]]; then |
| 137 | + echo "No snapshot changes to commit after approval." |
| 138 | + echo "committed=false" >> "$GITHUB_OUTPUT" |
| 139 | + exit 0 |
| 140 | + fi |
| 141 | +
|
| 142 | + git config user.name "github-actions[bot]" |
| 143 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 144 | + git add -A |
| 145 | + git commit -m "test: update Playwright snapshots" |
| 146 | + git push origin "HEAD:${{ steps.resolve_branch.outputs.branch_name }}" |
| 147 | + echo "committed=true" >> "$GITHUB_OUTPUT" |
| 148 | + echo "commit_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" |
0 commit comments