Skip to content

Commit 4a3f25d

Browse files
committed
test(ci): Do not always run e2e tests
Signed-off-by: Louis Chmn <louis@chmn.me>
1 parent 6470514 commit 4a3f25d

2 files changed

Lines changed: 78 additions & 7 deletions

File tree

.github/workflows/cypress.yml

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@
88

99
name: Cypress
1010

11-
on: pull_request
11+
on:
12+
pull_request:
13+
types:
14+
- opened
15+
- synchronize
16+
- reopened
17+
- ready_for_review
18+
- labeled
1219

1320
concurrency:
1421
group: cypress-${{ github.head_ref || github.run_id }}
@@ -24,13 +31,42 @@ env:
2431
# n.b. server will use head_ref, as we want to test the PR branch.
2532
BRANCH: ${{ github.base_ref || github.ref_name }}
2633

27-
2834
permissions:
2935
contents: read
36+
pull-requests: read
3037

3138
jobs:
39+
gate:
40+
runs-on: ubuntu-latest-low
41+
steps:
42+
- name: Evaluate e2e tests execution conditions
43+
id: gate-e2e
44+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v8.0.0
45+
with:
46+
script: |
47+
const pr = context.payload.pull_request
48+
49+
const hasForceLabel = pr.labels.some((label) => label.name === 'force-e2e-tests')
50+
const hasToReviewLabel = pr.labels.some((label) => label.name === '3. to review')
51+
const hasToReleaseLabel = pr.labels.some((label) => label.name === '4. to release')
52+
53+
const files = await github.paginate(github.rest.pulls.listFiles, {
54+
owner: context.repo.owner,
55+
repo: context.repo.repo,
56+
pull_number: pr.number,
57+
per_page: 100,
58+
})
59+
const cypressTouched = files.some((file) => file.filename.startsWith('cypress'))
60+
61+
if (hasForceLabel || hasToReviewLabel || hasToReleaseLabel || cypressTouched) {
62+
return
63+
} else {
64+
core.setFailed('Skipping Cypress: draft state, missing labels or no cypress path changes.')
65+
}
66+
3267
init:
3368
runs-on: ubuntu-latest
69+
needs: gate
3470
outputs:
3571
nodeVersion: ${{ steps.versions.outputs.nodeVersion }}
3672
npmVersion: ${{ steps.versions.outputs.npmVersion }}
@@ -98,7 +134,7 @@ jobs:
98134

99135
cypress:
100136
runs-on: ubuntu-latest
101-
needs: init
137+
needs: [gate, init]
102138

103139
strategy:
104140
fail-fast: false

.github/workflows/playwright.yml

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,51 @@ name: Playwright Tests
55

66
on:
77
pull_request:
8-
branches: [ master ]
8+
branches: [master]
9+
types:
10+
- opened
11+
- synchronize
12+
- reopened
13+
- ready_for_review
14+
- labeled
915

1016
permissions:
1117
contents: read
1218

1319
jobs:
20+
gate:
21+
runs-on: ubuntu-latest-low
22+
steps:
23+
- name: Evaluate e2e tests execution conditions
24+
id: gate-e2e
25+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v8.0.0
26+
with:
27+
script: |
28+
const pr = context.payload.pull_request
29+
30+
const hasForceLabel = pr.labels.some((label) => label.name === 'force-e2e-tests')
31+
const hasToReviewLabel = pr.labels.some((label) => label.name === '3. to review')
32+
const hasToReleaseLabel = pr.labels.some((label) => label.name === '4. to release')
33+
34+
const files = await github.paginate(github.rest.pulls.listFiles, {
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
pull_number: pr.number,
38+
per_page: 100,
39+
})
40+
const playwrightTouched = files.some((file) => file.filename.startsWith('tests/playwright'))
41+
42+
if (hasForceLabel || hasToReviewLabel || hasToReleaseLabel || playwrightTouched) {
43+
return
44+
} else {
45+
core.setFailed('Skipping Playwright: draft state, missing labels or no playwright path changes.')
46+
}
47+
1448
playwright-setup:
1549
timeout-minutes: 15
1650
name: Playwright setup
1751
runs-on: ubuntu-latest
52+
needs: gate
1853
steps:
1954
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2055
with:
@@ -40,7 +75,7 @@ jobs:
4075
path: ./
4176

4277
playwright-tests:
43-
needs: [playwright-setup]
78+
needs: [gate, playwright-setup]
4479
timeout-minutes: 60
4580
name: Playwright tests ${{ matrix.shardIndex }} / ${{ matrix.shardTotal }}
4681
runs-on: ubuntu-latest
@@ -115,7 +150,7 @@ jobs:
115150
merge-reports:
116151
# Merge reports after playwright-tests, even if some shards have failed
117152
if: ${{ !cancelled() }}
118-
needs: [playwright-tests]
153+
needs: [gate, playwright-tests]
119154

120155
runs-on: ubuntu-latest-low
121156
steps:
@@ -171,7 +206,7 @@ jobs:
171206
permissions:
172207
contents: none
173208
runs-on: ubuntu-latest-low
174-
needs: [playwright-tests]
209+
needs: [gate, playwright-tests]
175210

176211
if: always()
177212

0 commit comments

Comments
 (0)