Skip to content

Commit 790acc9

Browse files
committed
Set commit status on Playwright failure
1 parent 09d708e commit 790acc9

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

.github/workflows/playwright.yml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,40 @@ on:
33
issue_comment:
44
types: [created, edited]
55
permissions:
6-
contents: read
6+
contents: write
7+
issues: write
8+
pull-requests: write
9+
statuses: write
710
jobs:
811
playwright:
912
runs-on: ubuntu-latest
1013
if: contains(github.event.comment.html_url, '/pull/') && github.event.comment.user.login == 'netlify[bot]' && contains(github.event.comment.body, 'ready!')
1114
steps:
15+
- name: Mark pending status
16+
uses: actions/github-script@v7
17+
if: always()
18+
id: pending_status
19+
with:
20+
script: |
21+
// Get the most recent commit on the PR
22+
const commits = await github.rest.pulls.listCommits({
23+
owner: context.issue.owner,
24+
repo: context.issue.repo,
25+
pull_number: context.issue.number,
26+
per_page: 1
27+
});
28+
const headCommit = commits.data[0].sha;
29+
const commitStatus = {
30+
owner: context.repo.owner,
31+
repo: context.repo.repo,
32+
sha: headCommit,
33+
state: 'pending',
34+
target_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
35+
context: 'Playwright'
36+
};
37+
await github.rest.repos.createCommitStatus(commitStatus);
38+
return commitStatus;
39+
1240
- run: git config --global core.autocrlf input
1341
- uses: actions/checkout@v4
1442
with:
@@ -27,6 +55,22 @@ jobs:
2755
run: yarn playwright install --with-deps
2856

2957
- name: Run tests
58+
id: playwright_test
3059
env:
3160
PLAYWRIGHT_TEST_BASE_URL: https://deploy-preview-${{ github.event.issue.number }}--cambria-project.netlify.app
61+
continue-on-error: true
3262
run: yarn playwright test
63+
64+
- name: Update commit status
65+
uses: actions/github-script@v7
66+
if: always()
67+
env:
68+
COMMIT_STATUS: ${{ steps.pending_status.outputs.result }}
69+
TEST_STATUS: ${{ steps.playwright_test.outcome == 'success' && 'success' || 'failure' }}
70+
with:
71+
script: |
72+
// Get the most recent commit on the PR
73+
const commitStatus = JSON.parse(process.env.COMMIT_STATUS);
74+
commitStatus.state = process.env.TEST_STATUS;
75+
commitStatus.target_url = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
76+
await github.rest.repos.createCommitStatus(commitStatus);

0 commit comments

Comments
 (0)