11# SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
22# SPDX-License-Identifier: MIT
3+
4+ # This workflow runs Playwright tests on pull requests to the master and stable branches.
5+ # It expects the following npm scripts to be defined in package.json:
6+ # - "playwright": runs the Playwright tests
7+ # - "playwright:install-ci": installs the Playwright browsers for CI (optional)
8+ #
9+ # If you only use the "Desktop Chrome" browser with "channel: chrome" in your Playwright config,
10+ # you can skip the "playwright:install-ci" script as the GitHub Actions runner already has Chrome Browser installed.
11+ #
12+ # For merging the reports, it expects a Playwright merge config file at tests/playwright/merge.config.ts.
13+ # You can adjust the path in the "Merge into HTML Report" step if you have a different location for the merge config file.
14+ # The default configuration would look like this:
15+ # ```js
16+ # export default {
17+ # testDir: 'tests/playwright/e2e', // path to your Playwright tests
18+ # reporter: [['html', { open: 'never' }]],
19+ # }
20+ # ```
21+
322name : Playwright Tests
423
524on :
625 pull_request :
7- branches : [master]
26+ branches :
27+ - master
28+ - stable35
29+ - stable34
30+ - stable33
831
932permissions :
1033 contents : read
1134
12- concurrency :
13- group : playwright-${{ github.head_ref || github.run_id }}
14- cancel-in-progress : true
15-
1635jobs :
17- test :
18- timeout-minutes : 60
36+ playwright-setup :
37+ timeout-minutes : 10
38+ name : Playwright setup
39+ runs-on : ubuntu-latest
40+ steps :
41+ - uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
42+ with :
43+ persist-credentials : false
44+ - name : Read package.json
45+ uses : nextcloud-libraries/parse-package-engines-action@122ae05d4257008180a514e1ddeb0c1b9d094bdd # v0.1.0
46+ id : versions
47+ - name : Set up node
48+ uses : actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
49+ with :
50+ node-version : ${{ steps.versions.outputs.node-version }}
51+ - name : Set up npm
52+ run : npm i -g 'npm@${{ steps.versions.outputs.package-manager-version }}'
53+ - name : Install dependencies and build
54+ run : |
55+ npm ci
56+ npm run build --if-present
57+ - name : Save context
58+ uses : actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
59+ with :
60+ key : playwright-context-${{ github.run_id }}
61+ path : ./
62+
63+ playwright-tests :
64+ needs : [playwright-setup]
65+ timeout-minutes : 30
66+ name : Playwright tests ${{ matrix.shardIndex }} / ${{ matrix.shardTotal }}
1967 runs-on : ubuntu-latest
68+ strategy :
69+ fail-fast : false
70+ matrix :
71+ shardIndex : [1, 2] # adjust to your needs
72+ shardTotal : [2]
73+ outputs :
74+ node-version : ${{ steps.versions.outputs.node-version }}
75+ package-manager-version : ${{ steps.versions.outputs.package-manager-version }}
76+
77+ steps :
78+ - name : Restore context
79+ id : cache
80+ uses : actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
81+ with :
82+ key : playwright-context-${{ github.run_id }}
83+ path : ./
84+
85+ - uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
86+ if : steps.cache.outputs.cache-hit != 'true'
87+ with :
88+ persist-credentials : false
89+
90+ - name : Read package.json
91+ uses : nextcloud-libraries/parse-package-engines-action@122ae05d4257008180a514e1ddeb0c1b9d094bdd # v0.1.0
92+ id : versions
93+
94+ - name : Set up node
95+ uses : actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
96+ with :
97+ node-version : ${{ steps.versions.outputs.node-version }}
98+
99+ - name : Set up npm
100+ run : npm i -g 'npm@${{ steps.versions.outputs.package-manager-version }}'
101+
102+ - name : Install dependencies and build
103+ if : steps.cache.outputs.cache-hit != 'true'
104+ run : |
105+ npm ci
106+ npm run build --if-present
107+
108+ - name : Install Playwright browsers
109+ run : npm run playwright:install-ci --if-present
110+
111+ - name : Run Playwright tests
112+ run : npm run playwright -- --shard='${{ matrix.shardIndex }}/${{ matrix.shardTotal }}'
113+
114+ - name : Upload blob report to GitHub Actions Artifacts
115+ if : ${{ !cancelled() }}
116+ uses : actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
117+ with :
118+ name : blob-report-${{ matrix.shardIndex }}
119+ path : blob-report
120+ retention-days : 1
121+
122+ merge-reports :
123+ # Merge reports after playwright-tests, even if some shards have failed
124+ if : ${{ !cancelled() }}
125+ needs : [playwright-tests]
126+
127+ runs-on : ubuntu-latest-low
128+ steps :
129+ - name : Restore context
130+ id : cache
131+ uses : actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
132+ with :
133+ key : playwright-context-${{ github.run_id }}
134+ path : ./
135+
136+ - uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
137+ if : steps.cache.outputs.cache-hit != 'true'
138+ with :
139+ persist-credentials : false
140+
141+ - uses : actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
142+ if : steps.cache.outputs.cache-hit != 'true'
143+ with :
144+ node-version : ${{ needs.playwright-tests.outputs.node-version }}
145+
146+ - name : Set up npm
147+ if : steps.cache.outputs.cache-hit != 'true'
148+ run : npm i -g 'npm@${{ needs.playwright-tests.outputs.package-manager-version }}'
149+
150+ - name : Install dependencies
151+ if : steps.cache.outputs.cache-hit != 'true'
152+ run : npm ci
153+
154+ - name : Download blob reports from GitHub Actions Artifacts
155+ uses : actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
156+ with :
157+ path : all-blob-reports
158+ pattern : blob-report-*
159+ merge-multiple : true
160+
161+ - name : Merge into HTML Report
162+ run : npx playwright merge-reports --config tests/playwright/merge.config.ts --reporter html,github ./all-blob-reports
163+
164+ - name : Upload HTML report
165+ uses : actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
166+ with :
167+ name : html-report--attempt-${{ github.run_attempt }}
168+ path : playwright-report
169+ retention-days : 7
170+
171+ - name : How to show the logs
172+ run : |
173+ echo 'To view the report:'
174+ echo ' 1. Extract the folder from the zip file'
175+ echo ' 2. run "npx playwright show-report name-of-my-extracted-playwright-report"'
176+
177+ summary :
178+ permissions :
179+ contents : none
180+ runs-on : ubuntu-latest-low
181+ needs : [playwright-tests]
182+
183+ if : always()
184+
185+ name : playwright-test-summary
186+
20187 steps :
21- - name : Checkout app
22- uses : actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
23- with :
24- persist-credentials : false
25-
26- - name : Check composer.json
27- id : check_composer
28- uses : andstor/file-existence-action@558493d6c74bf472d87c84eab196434afc2fa029 # v2
29- with :
30- files : ' composer.json'
31-
32- - name : Install composer dependencies
33- if : steps.check_composer.outputs.files_exists == 'true'
34- run : composer install --no-dev
35-
36- - name : Read package.json node and npm engines version
37- uses : skjnldsv/read-package-engines-version-actions@06d6baf7d8f41934ab630e97d9e6c0bc9c9ac5e4 # v3
38- id : versions
39- with :
40- fallbackNode : ' ^22'
41- fallbackNpm : ' ^10'
42-
43- - name : Set up node ${{ steps.versions.outputs.nodeVersion }}
44- uses : actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
45- with :
46- node-version : ${{ steps.versions.outputs.nodeVersion }}
47-
48- - name : Set up npm ${{ steps.versions.outputs.npmVersion }}
49- run : npm i -g npm@"${{ steps.versions.outputs.npmVersion }}"
50-
51- - name : Install node dependencies & build app
52- run : |
53- npm ci
54- npm run build --if-present
55-
56- - name : Install Playwright Browsers
57- run : npx playwright install chromium --only-shell
58-
59- - name : Run Playwright tests
60- run : npx playwright test
61-
62- - uses : actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
63- if : always()
64- with :
65- name : playwright-report
66- path : playwright-report/
67- retention-days : 30
188+ - name : Summary status
189+ run : if ${{ needs.playwright-tests.result != 'success' }}; then exit 1; fi
0 commit comments