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