Skip to content

Commit 4d0d07d

Browse files
authored
update github action scripts (#58)
1 parent 25de3f4 commit 4d0d07d

File tree

4 files changed

+140
-20
lines changed

4 files changed

+140
-20
lines changed

.github/actions/run-playwright/action.yml

+84
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,107 @@ inputs:
77
provider:
88
description: 'Which next deployment provider is used'
99
required: true
10+
githubToken:
11+
description: 'GitHub Token'
12+
required: true
13+
prNumber:
14+
description: 'Pull request ID (optional)'
15+
required: false
16+
outputs:
17+
conclusion:
18+
description: 'E2E result'
1019
runs:
1120
using: "composite"
1221
steps:
1322
- name: Run E2E Tests on Netlify URL
23+
id: playwright-e2e
1424
run: REMOTE_PROVIDER=${{ inputs.provider }} yarn e2e
1525
shell: bash
1626
env:
1727
PLAYWRIGHT_TEST_BASE_URL: ${{ inputs.provider-deployment-url }}
1828
- uses: actions/upload-artifact@v3
29+
id: playwright-report-artifact
1930
if: always()
2031
with:
2132
name: playwright-report-${{ inputs.provider }}
2233
path: playwright-report/
2334
retention-days: 10
2435
- uses: actions/upload-artifact@v3
36+
id: playwright-screenshots-artifact
2537
if: always()
2638
with:
2739
name: screenshots-${{inputs.provider}}
2840
path: tests/e2e/__screenshots__/${{inputs.provider}}
2941
retention-days: 10
42+
- uses: actions/github-script@v6
43+
if: always()
44+
with:
45+
github-token: ${{ inputs.githubToken }}
46+
script: |
47+
const conclusion = '${{ steps.playwright-e2e.outcome }}';
48+
const prNumber = '${{ inputs.prNumber }}';
49+
const provider = '${{ inputs.provider }}';
50+
const deploymentUrl = '${{ inputs.provider-deployment-url }}';
51+
52+
if (prNumber && conclusion) {
53+
core.setOutput('conclusion', conclusion);
54+
const owner = context.repo.owner;
55+
const repo = context.repo.repo;
56+
const jobName = context.job;
57+
const runId = context.runId;
58+
59+
const pullRequest = await github.rest.pulls.get({
60+
owner,
61+
repo,
62+
pull_number: prNumber,
63+
});
64+
const checksForPr = await github.rest.checks.listForRef({
65+
owner: owner,
66+
repo: repo,
67+
ref: pullRequest.data.head.ref,
68+
});
69+
70+
let checkRunId = null;
71+
for (const checkRun of checksForPr.data.check_runs) {
72+
if (checkRun.name === jobName) {
73+
checkRunId = checkRun.id;
74+
console.log(`Found Check Run ID: ${checkRunId}`);
75+
break;
76+
}
77+
}
78+
79+
if (checkRunId) {
80+
const checkInput = {
81+
owner,
82+
repo,
83+
check_run_id: checkRunId,
84+
pull_request: prNumber,
85+
status: 'completed',
86+
conclusion: conclusion,
87+
output: {
88+
title: `e2e ${provider}`,
89+
summary: `e2e ${provider}: ${conclusion}`,
90+
},
91+
};
92+
github.rest.checks.update(checkInput).catch((error) => {
93+
console.warn('Error updating check:', error, ' flow continues');
94+
});
95+
}
96+
// Create a comment with the artifact links on the pull request
97+
const artifactLinks = [
98+
`## ${conclusion === 'success' ? ':green_circle:' : ':red_circle:'} Playwright E2E for ${provider.toUpperCase()}`,
99+
`| Name | Info |`,
100+
`|------|---------|`,
101+
`| Summary | [Action Summary](https://github.com/${owner}/${repo}/actions/runs/${runId}/) |`,
102+
`| Site URL | [${deploymentUrl}](${deploymentUrl}) |`,
103+
];
104+
const comment = artifactLinks.join('\n');
105+
github.rest.issues.createComment({
106+
owner,
107+
repo,
108+
issue_number: pullRequest.data.number,
109+
body: comment
110+
}).catch((error) => {
111+
console.warn('Error creating comment:', error, ' flow continues');
112+
});
113+
}

.github/workflows/netlify-e2e.yml

+33-18
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,41 @@ name: Netlify E2E
22
on:
33
pull_request:
44
branches: [ main ]
5+
workflow_dispatch:
6+
inputs:
7+
deploymentUrl:
8+
description: 'The deployment URL to test with'
9+
required: true
10+
prNumber:
11+
description: 'Pull request number (optional)'
12+
required: false
513
jobs:
614
netlify-e2e:
715
timeout-minutes: 60
816
runs-on: ubuntu-latest
917
steps:
10-
- uses: actions/checkout@v3
11-
- uses: actions/setup-node@v3
12-
with:
13-
node-version: 16
14-
cache: 'yarn'
15-
- name: Install dependencies
16-
run: yarn
17-
- uses: ./.github/actions/setup-playwright
18-
- name: Waiting for 200 from the Netlify Preview
19-
uses: jakepartusch/wait-for-netlify-action@v1.4
20-
id: waitFor200
21-
with:
22-
site_name: "wix-cms-nextjs-template" # TODO: change to your site name
23-
max_timeout: 120 # 2 Minutes, depends on your build pipeline duration
24-
- uses: ./.github/actions/run-playwright
25-
with:
26-
provider: 'netlify'
27-
provider-deployment-url: ${{ steps.waitFor200.outputs.url }}
18+
- uses: actions/checkout@v3
19+
- uses: actions/setup-node@v3
20+
with:
21+
node-version: 16
22+
cache: 'yarn'
23+
- name: Install dependencies
24+
run: yarn
25+
- uses: ./.github/actions/setup-playwright
26+
- name: Waiting for 200 from the Netlify Preview
27+
if: ${{ !github.event.inputs.deploymentUrl }}
28+
uses: jakepartusch/wait-for-netlify-action@v1.4
29+
id: waitFor200
30+
with:
31+
site_name: "wix-cms-nextjs-template" # TODO: change to your site name
32+
max_timeout: 120 # 2 Minutes, depends on your build pipeline duration
33+
- name: Set Run with URL
34+
run: |
35+
echo "DEPLOYMENT_URL=${{ github.event.inputs.deploymentUrl || steps.waitFor200.outputs.url }}" >> $GITHUB_ENV
36+
- uses: ./.github/actions/run-playwright
37+
id: runPlaywright
38+
with:
39+
provider: 'netlify'
40+
githubToken: ${{ secrets.GITHUB_TOKEN }}
41+
prNumber: ${{ github.event.inputs.prNumber || github.event.pull_request.number }}
42+
provider-deployment-url: ${{ env.DEPLOYMENT_URL }}

.github/workflows/vercel-e2e.yml

+17-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@
44
name: Vercel E2E
55
on:
66
deployment_status:
7+
workflow_dispatch:
8+
inputs:
9+
deploymentUrl:
10+
description: 'The deployment URL to test with'
11+
required: true
12+
prNumber:
13+
description: 'Pull request number (optional)'
14+
required: false
715
jobs:
816
vercel-e2e:
9-
if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success' && contains(github.event.deployment_status.target_url, 'vercel-demo-wix-cms') # TODO: change to your site name
17+
if: github.event.inputs.deploymentUrl || (github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success' && contains(github.event.deployment_status.target_url, 'vercel-demo-wix-cms')) # TODO: change to your site name
1018
timeout-minutes: 60
1119
runs-on: ubuntu-latest
1220
steps:
@@ -18,7 +26,14 @@ jobs:
1826
- name: Install dependencies
1927
run: yarn
2028
- uses: ./.github/actions/setup-playwright
29+
- name: Set Run with URL
30+
run: |
31+
echo "setting DEPLOYMENT_URL=${{ github.event.inputs.deploymentUrl || github.event.deployment_status.target_url }}"
32+
echo "DEPLOYMENT_URL=${{ github.event.inputs.deploymentUrl || github.event.deployment_status.target_url }}" >> $GITHUB_ENV
2133
- uses: ./.github/actions/run-playwright
34+
id: runPlaywright
2235
with:
2336
provider: 'vercel'
24-
provider-deployment-url: ${{ github.event.deployment_status.target_url }}
37+
githubToken: ${{ secrets.GITHUB_TOKEN }}
38+
prNumber: ${{ github.event.inputs.prNumber }}
39+
provider-deployment-url: ${{ env.DEPLOYMENT_URL }}

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,9 @@ next-env.d.ts
4646
!.yarn/sdks
4747
!.yarn/versions
4848
.yarn/install-state.gz
49+
#IDEA
50+
.idea
51+
#Playwright
52+
/test-results/
53+
/playwright-report/
54+
/playwright/.cache/

0 commit comments

Comments
 (0)