-
Notifications
You must be signed in to change notification settings - Fork 1
170 lines (158 loc) · 5.89 KB
/
e2e.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
name: 🤖 End-to-End Tests
on:
push:
branches: [main]
pull_request:
types:
- opened
- synchronize
- labeled
env:
NODE_ENV: testing
PR_NUMBER: ${{ github.event.pull_request.number }}
NETLIFY_MAIN_URL: 'https://spirit-design-system.netlify.app/'
NETLIFY_DEPLOY_PREVIEW_URL: 'https://deploy-preview-${{ github.event.pull_request.number }}--spirit-design-system.netlify.app/'
jobs:
has-label:
name: 🏷️ Analyzing Labels
runs-on: ubuntu-latest
outputs:
e2e: ${{ steps.has-label.outputs.labeled-run-visual-tests }}
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v4
- name: Labeled to e2e
id: has-label
uses: DanielTamkin/[email protected]
with:
contains: 'run-visual-tests'
test:
name: 🖥️ End-to-End Testing
needs: has-label
if: ${{ needs.has-label.outputs.e2e || (github.ref == 'refs/heads/main') }}
runs-on: ubuntu-24.04
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
- name: Setup Node and Install Dependencies
uses: ./.github/actions/setup-install
# Wait for the Netlify preview URL to be ready
- name: Wait for Netlify Deploy
uses: mmazzarolo/wait-for-netlify-action@8a7a8d8cf5b313c916d805b76cc498380062d268
id: get-netlify-preview-url
continue-on-error: true
with:
site_id: ${{ secrets.NETLIFY_SITE_SPIRIT_DESIGN_SYSTEM }}
max_timeout: 1
env:
NETLIFY_TOKEN: ${{ secrets.NETLIFY_TOKEN }}
# The Netlify preview URL is now available
# as `steps.get-netlify-preview-url.outputs.url`
- name: Get Site URL
id: get-site-url
env:
# fallback to main url if the main branch is deployed
NETLIFY_DEPLOYED_URL: ${{ env.PR_NUMBER && env.NETLIFY_DEPLOY_PREVIEW_URL || env.NETLIFY_MAIN_URL }}
run: echo "site_url=${{ env.NETLIFY_DEPLOYED_URL }}" >> "$GITHUB_OUTPUT"
- name: Run Playwright tests
uses: docker://mcr.microsoft.com/playwright:v1.49.0-jammy
with:
args: 'sh -c "corepack install && corepack enable && yarn test:e2e"'
env:
WEBSITE_URL: ${{ steps.get-netlify-preview-url.outcome == 'success' && steps.get-netlify-preview-url.outputs.url || steps.get-site-url.outputs.site_url }}
- uses: actions/upload-artifact@v4
if: failure()
id: artifact-upload-step
with:
name: playwright-report
path: playwright-report/
retention-days: 30
- name: Comment PR with artifact URL
if: failure()
uses: actions/github-script@v7
with:
script: |
const issue_number = context.issue.number;
const repo = context.repo.repo;
const owner = context.repo.owner;
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: `Here is the URL of the uploaded artifact: ${{ steps.artifact-upload-step.outputs.artifact-url }}`
});
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Notify Slack when failure
id: Slack
uses: slackapi/[email protected]
if: failure()
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }} # Slack channel-id of #spirit-design-system-notifications_en
payload: |
{
"attachments": [
{
"color": "#ff0000",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": ":boom: GitHub Action failed",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Pull request title:* `${{ github.event.pull_request.title }}`"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*E2E tests result:* `${{ job.status }}`"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": ":github: Open Pull request"
},
"url": "${{ github.event.pull_request.html_url }}"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": ":github: Open failed GitHub Action"
},
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": ":github: Download Report"
},
"url": "${{ steps.artifact-upload-step.outputs.artifact-url }}"
}
]
}
]
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_NOTIFICATIONS_TOKEN }} # Webhook from Slack Application
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK