|
| 1 | +name: Playwright Snapshot Report |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + |
| 7 | +jobs: |
| 8 | + snapshot-report: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + |
| 11 | + if: ${{ github.actor != 'dependabot[bot]' }} |
| 12 | + |
| 13 | + permissions: |
| 14 | + contents: write |
| 15 | + pull-requests: write |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout repository |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up GitHub CLI |
| 22 | + uses: cli/cli-action@v2 |
| 23 | + |
| 24 | + - name: Ensure snapshot dirs are writable |
| 25 | + run: | |
| 26 | + mkdir -p e2e/tests/screenshot-test.spec.js-snapshots |
| 27 | + sudo chown -R 1000:1000 e2e/tests/screenshot-test.spec.js-snapshots |
| 28 | +
|
| 29 | + - name: Create Docker network |
| 30 | + run: docker network create sf-website-development || true |
| 31 | + |
| 32 | + - name: Run Playwright tests with snapshot update |
| 33 | + run: | |
| 34 | + docker compose -f docker-compose.yml -f docker-compose.e2e.yml run --name apostrophe-playwright-test --build \ |
| 35 | + --entrypoint "sh -c 'until wget -qO- http://apostrophe:3000/ > /dev/null; do echo Waiting for Apostrophe...; sleep 2; done && npm run test:e2e:update -c playwright.config.js'" \ |
| 36 | + playwright-test |
| 37 | + continue-on-error: false |
| 38 | + |
| 39 | + - name: Copy snapshots from Docker volume |
| 40 | + run: | |
| 41 | + mkdir -p website/e2e/pr-snapshots/screenshot-test.spec.js-snapshots |
| 42 | + docker cp $(docker ps -aqf "name=apostrophe-playwright-test"):/e2e/tests/screenshot-test.spec.js-snapshots ./website/e2e/pr-snapshots/screenshot-test.spec.js-snapshots |
| 43 | +
|
| 44 | + - name: Upload snapshots as artifact |
| 45 | + uses: actions/upload-artifact@v4 |
| 46 | + with: |
| 47 | + name: playwright-snapshots-pr |
| 48 | + path: website/e2e/pr-snapshots/screenshot-test.spec.js-snapshots |
| 49 | + overwrite: true |
| 50 | + retention-days: 20 |
| 51 | + |
| 52 | + - name: Generate comment body with links |
| 53 | + id: comment |
| 54 | + run: | |
| 55 | + ARTIFACT_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 56 | + COMMENT_BODY="🧪 **Playwright Snapshot Report** |
| 57 | +
|
| 58 | + 🖼️ Screenshots have been updated and attached as an artifact. |
| 59 | +
|
| 60 | + 🔗 [View Artifacts & Download Snapshots]($ARTIFACT_URL) |
| 61 | +
|
| 62 | + _This comment updates automatically with each commit._" |
| 63 | +
|
| 64 | + echo "body<<EOF" >> $GITHUB_OUTPUT |
| 65 | + echo "$COMMENT_BODY" >> $GITHUB_OUTPUT |
| 66 | + echo "EOF" >> $GITHUB_OUTPUT |
| 67 | +
|
| 68 | + - name: Post or update comment on PR |
| 69 | + env: |
| 70 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + run: | |
| 72 | + PR_NUMBER=${{ github.event.pull_request.number }} |
| 73 | + COMMENT_BODY="${{ steps.comment.outputs.body }}" |
| 74 | +
|
| 75 | + COMMENT_ID=$(gh pr view $PR_NUMBER --json comments \ |
| 76 | + --jq '.comments[] | select(.body | contains("🧪 **Playwright Snapshot Report**")) | .id') |
| 77 | +
|
| 78 | + if [ -n "$COMMENT_ID" ]; then |
| 79 | + echo "Updating existing comment ID: $COMMENT_ID" |
| 80 | + gh pr comment $PR_NUMBER --edit "$COMMENT_ID" --body "$COMMENT_BODY" |
| 81 | + else |
| 82 | + echo "Creating new comment" |
| 83 | + gh pr comment $PR_NUMBER --body "$COMMENT_BODY" |
| 84 | + fi |
| 85 | +
|
| 86 | + - name: Cleanup Docker |
| 87 | + run: | |
| 88 | + docker compose -f docker-compose.yml -f docker-compose.e2e.yml down --volumes --remove-orphans |
| 89 | + docker network rm sf-website-development || true |
0 commit comments