Skip to content

Commit 8bc4499

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

2 files changed

Lines changed: 220 additions & 143 deletions

File tree

.github/workflows/cypress.yml

Lines changed: 52 additions & 13 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,45 @@ 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+
outputs:
42+
should_run: ${{ steps.evaluate.outputs.should_run }}
43+
reason: ${{ steps.evaluate.outputs.reason }}
44+
steps:
45+
- name: Evaluate e2e tests execution conditions
46+
id: evaluate
47+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v8.0.0
48+
with:
49+
script: |
50+
const pr = context.payload.pull_request
51+
52+
const hasForceLabel = pr.labels.some((label) => label.name === 'force-e2e-tests')
53+
const hasToReviewLabel = pr.labels.some((label) => label.name === '3. to review')
54+
const hasToReleaseLabel = pr.labels.some((label) => label.name === '4. to release')
55+
56+
const files = await github.paginate(github.rest.pulls.listFiles, {
57+
owner: context.repo.owner,
58+
repo: context.repo.repo,
59+
pull_number: pr.number,
60+
per_page: 100,
61+
})
62+
const cypressTouched = files.some((file) => file.filename.startsWith('cypress'))
63+
64+
if (hasForceLabel || hasToReviewLabel || hasToReleaseLabel || cypressTouched) {
65+
return
66+
} else {
67+
core.setFailed('Skipping Cypress: draft state, missing labels or no cypress path changes.')
68+
}
69+
3270
init:
3371
runs-on: ubuntu-latest
72+
needs: gate
3473
outputs:
3574
nodeVersion: ${{ steps.versions.outputs.nodeVersion }}
3675
npmVersion: ${{ steps.versions.outputs.npmVersion }}
@@ -52,7 +91,7 @@ jobs:
5291
id: check_composer
5392
uses: andstor/file-existence-action@558493d6c74bf472d87c84eab196434afc2fa029 # v3.1.0
5493
with:
55-
files: 'composer.json'
94+
files: "composer.json"
5695

5796
- name: Install composer dependencies
5897
if: steps.check_composer.outputs.files_exists == 'true'
@@ -62,8 +101,8 @@ jobs:
62101
uses: skjnldsv/read-package-engines-version-actions@06d6baf7d8f41934ab630e97d9e6c0bc9c9ac5e4 # v3
63102
id: versions
64103
with:
65-
fallbackNode: '^24'
66-
fallbackNpm: '^11.3'
104+
fallbackNode: "^24"
105+
fallbackNpm: "^11.3"
67106

68107
- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
69108
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
@@ -98,14 +137,14 @@ jobs:
98137

99138
cypress:
100139
runs-on: ubuntu-latest
101-
needs: init
140+
needs: [gate, init]
102141

103142
strategy:
104143
fail-fast: false
105144
matrix:
106145
# Run multiple copies of the current job in parallel
107146
# Please increase the number or runners as your tests suite grows (0 based index for e2e tests)
108-
containers: ['setup', '0', '1', '2', '3', '4', '5', '6']
147+
containers: ["setup", "0", "1", "2", "3", "4", "5", "6"]
109148
# Hack as strategy.job-total includes the "setup" and GitHub does not allow math expressions
110149
# Always align this number with the total of e2e runners (max. index + 1)
111150
total-containers: [7]
@@ -115,7 +154,7 @@ jobs:
115154
# Only start mysql if we are running the setup tests
116155
image: ${{matrix.containers == 'setup' && 'ghcr.io/nextcloud/continuous-integration-mysql-8.4:latest' || ''}} # zizmor: ignore[unpinned-images]
117156
ports:
118-
- '3306/tcp'
157+
- "3306/tcp"
119158
env:
120159
MYSQL_ROOT_PASSWORD: rootpassword
121160
MYSQL_USER: oc_autotest
@@ -127,7 +166,7 @@ jobs:
127166
# Only start mariadb if we are running the setup tests
128167
image: ${{matrix.containers == 'setup' && 'mariadb:11.4' || ''}} # zizmor: ignore[unpinned-images]
129168
ports:
130-
- '3306/tcp'
169+
- "3306/tcp"
131170
env:
132171
MYSQL_ROOT_PASSWORD: rootpassword
133172
MYSQL_USER: oc_autotest
@@ -139,7 +178,7 @@ jobs:
139178
# Only start postgres if we are running the setup tests
140179
image: ${{matrix.containers == 'setup' && 'ghcr.io/nextcloud/continuous-integration-postgres-17:latest' || ''}} # zizmor: ignore[unpinned-images]
141180
ports:
142-
- '5432/tcp'
181+
- "5432/tcp"
143182
env:
144183
POSTGRES_USER: root
145184
POSTGRES_PASSWORD: rootpassword
@@ -150,10 +189,10 @@ jobs:
150189
# Only start oracle if we are running the setup tests
151190
image: ${{matrix.containers == 'setup' && 'ghcr.io/gvenzl/oracle-free:23' || ''}} # zizmor: ignore[unpinned-images]
152191
ports:
153-
- '1521'
192+
- "1521"
154193
env:
155194
ORACLE_PASSWORD: oracle
156-
options: --health-cmd healthcheck.sh --health-interval 20s --health-timeout 10s --health-retries 10
195+
options: --health-cmd healthcheck.sh --health-interval 20s --health-timeout 10s --health-retries 10
157196

158197
name: runner ${{ matrix.containers }}
159198

@@ -178,7 +217,7 @@ jobs:
178217
if: steps.cache.outputs.cache-hit != 'true'
179218
uses: andstor/file-existence-action@558493d6c74bf472d87c84eab196434afc2fa029 # v3.1.0
180219
with:
181-
files: 'composer.json'
220+
files: "composer.json"
182221

183222
- name: Install composer dependencies
184223
if: steps.check_composer.outputs.files_exists == 'true' && steps.cache.outputs.cache-hit != 'true'

0 commit comments

Comments
 (0)