-
Notifications
You must be signed in to change notification settings - Fork 96
291 lines (259 loc) · 8.99 KB
/
tests.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# This workflow will build and run the test suite
# on all opened and updated (and labeled) PRs where
# at least one file does not match paths-ignore.
name: Build & test
on:
# Build when a PR is opened, updated, labeled, or flagged as ready
pull_request:
types:
- opened
- synchronize
- labeled
- unlabeled
- ready_for_review
- auto_merge_enabled
# Build when PRs are merged into master/main
push:
branches:
- master
- main
# Manual run, no inputs necessary
workflow_dispatch:
env:
# Bring color into the GitHub terminal
FORCE_COLOR: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PLAYWRIGHT_REPORT_DIR: test-report
# https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/
ACTIONS_ALLOW_UNSECURE_COMMANDS: "true"
# GITHUB_CONTEXT: ${{ toJson(github) }}
jobs:
# Turn this on to debug an action
# debug:
# name: Debug
# runs-on: ubuntu-latest
# steps:
# - name: Debugging context variables
# run: echo "$GITHUB_CONTEXT"
lint:
name: Lint files
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Configures the node version used on GitHub-hosted runners
- name: Configure node version
uses: actions/setup-node@v4
with:
node-version: '20'
cache: npm
- name: Install dependencies
run: npm ci --prefer-offline
- name: Lint
id: lint
run: npm run lint
test:
name: Unit Tests (Web Test Runner)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Configures the node version used on GitHub-hosted runners
- name: Configure node version
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: npm
- name: Install dependencies
run: npm ci --prefer-offline
- name: install playwright
run: npx playwright install
- name: Run tests
run: npm test
- name: JUnit Report Action
uses: mikepenz/action-junit-report@v2.8.2
with:
report_paths: test-results/test-results.xml
fail_on_failure: true # fail the actions run if the tests failed
ssr:
name: SSR Tests (Playwright)
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/playwright:v1.46.1-jammy
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: npm
- run: npm ci --prefer-offline
- run: npm run build
- name: Run tests
run: npx playwright test -g ssr --update-snapshots
env:
HOME: /root
- uses: actions/upload-artifact@v4
if: always()
with:
name: ${{ env.PLAYWRIGHT_REPORT_DIR }}
path: ${{ env.PLAYWRIGHT_REPORT_DIR }}/
retention-days: 30
publish_report:
name: Publish Playwright Report
# using always() is not ideal here, because it would also run if the workflow was cancelled
if: "success() || needs.ssr.result == 'failure'"
needs:
- ssr
runs-on: ubuntu-latest
continue-on-error: true
env:
HTML_REPORT_URL_PATH: reports/${{ github.ref_name }}/${{ github.run_id }}/${{ github.run_attempt }}
steps:
- uses: actions/checkout@v4
- name: Download zipped HTML report
uses: actions/download-artifact@v4
with:
name: ${{ env.PLAYWRIGHT_REPORT_DIR }}
path: ${{ env.PLAYWRIGHT_REPORT_DIR }}/
- name: Upload to Github Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: ${{ env.PLAYWRIGHT_REPORT_DIR }}
target-folder: ${{ env.HTML_REPORT_URL_PATH }}
- name: Add comment to PR
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
number: ${{ github.event.inputs.issueNumber }}
append: true
header: "${{ github.sha }}"
hide: true
hide_details: true
message: |
**SSR Test Run for ${{ github.sha }}**: [Report](https://patternfly.github.io/patternfly-elements/${{ env.HTML_REPORT_URL_PATH }})
# Validate the build to main was successful; open an issue if not
build:
name: Compile project
runs-on: ubuntu-latest
strategy:
matrix:
node:
- '20'
- '21'
if: |
github.event_name == 'workflow_dispatch'
|| github.event_name == 'push'
|| ( github.event_name == 'pull_request'
&& github.event.action == 'labeled'
&& github.event.label.name == 'ready to merge'
)
|| ( github.event_name == 'pull_request'
&& github.event.action != 'labeled'
&& github.event.pull_request.draft == false
&& !contains(github.event.pull_request.labels.*.name, 'blocked')
&& !contains(github.event.pull_request.labels.*.name, 'skip ci')
&& !contains(github.event.pull_request.labels.*.name, 'work in progress')
&& !contains(github.event.pull_request.labels.*.name, 'on hold')
)
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
# Configures the node version used on GitHub-hosted runners
- name: Configure node version
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: npm
- name: Install dependencies
run: npm ci --prefer-offline
- name: Build
id: build
run: npm run build
- name: Release Dry Run
id: release-dry
run: npm run prepublishOnly -ws --if-present
validate:
name: Validate successful build on main
needs:
- lint
- test
- build
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- name: Capture pull request number from branch name
if: github.event_name == 'workflow_dispatch'
run: |
echo 'prnumber<<EOF' >> $GITHUB_ENV
curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{github.repository}}/pulls?head=${{github.repository_owner}}:${{github.ref}} | jq -r '.[] | .number' >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Add a label if tests have passed (PR)
if: |
github.event_name == 'pull_request'
&& needs.test.outcome != 'failure'
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: AT passed
- name: Add a label if tests have passed (dispatch)
if: |
github.event_name == 'workflow_dispatch'
&& needs.test.outcome != 'failure'
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: AT passed
number: ${{ env.prnumber }}
- name: Remove the label if tests failed
if: |
github.event_name == 'pull_request'
&& needs.test.outcome == 'failure'
uses: actions-ecosystem/action-remove-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: AT passed
- name: Open issue if build breaks
if: |
github.event_name == 'push'
&& needs.build.outcome == 'failure'
uses: imjohnbo/issue-bot@v3
with:
labels: "fix, priority: high"
pinned: true
project: 2 # The project-number from organization project
column: Prioritized
close-previous: true
title: "❌ Build is failing on main"
body: "It looks like the build is currently failing on the main branch. See failed [action results](https://github.com/patternfly/patternfly-elements/actions/runs/${{ github.run_id }}) for more details."
- name: Open issue if tests fail
if: |
github.event_name == 'push'
&& needs.test.outcome == 'failure'
uses: imjohnbo/issue-bot@v3
with:
labels: "fix, priority: medium"
pinned: true
project: 2 # The project-number from organization project
column: Prioritized
close-previous: true
title: "🧪 Tests are failing on main"
body: "It looks like the build is currently failing on the main branch. See failed [action results](https://github.com/patternfly/patternfly-elements/actions/runs/${{ github.run_id }}) for more details."
build-windows:
name: Verify that build runs on Windows
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Configures the node version used on GitHub-hosted runners
- name: Configure node version
uses: actions/setup-node@v3
with:
node-version: 20
cache: npm
- name: Install dependencies
run: npm ci --prefer-offline
- name: Build
id: build
run: npm run build