Skip to content

Commit 4d9d78a

Browse files
committed
Set commit status on Playwright failure
1 parent 09d708e commit 4d9d78a

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

.github/workflows/playwright.yml

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

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

0 commit comments

Comments
 (0)