1+ name : Cypress
2+
3+ on :
4+ pull_request :
5+ push :
6+ branches :
7+ - main
8+ - master
9+ - stable*
10+
11+ env :
12+ # Adjust APP_NAME if your repository name is different
13+ APP_NAME : ${{ github.event.repository.name }}
14+
15+ # This represents the server branch to checkout.
16+ # Usually it's the base branch of the PR, but for pushes it's the branch itself.
17+ # e.g. 'main', 'stable27' or 'feature/my-feature
18+ # n.b. server will use head_ref, as we want to test the PR branch.
19+ BRANCH : ${{ github.base_ref || github.ref_name }}
20+
21+ jobs :
22+ init :
23+ runs-on : ubuntu-latest
24+ outputs :
25+ nodeVersion : ${{ steps.versions.outputs.nodeVersion }}
26+ npmVersion : ${{ steps.versions.outputs.npmVersion }}
27+
28+ steps :
29+ - name : Checkout app
30+ uses : actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
31+
32+ - name : Check composer.json
33+ id : check_composer
34+ uses : andstor/file-existence-action@20b4d2e596410855db8f9ca21e96fbe18e12930b # v2
35+ with :
36+ files : " composer.json"
37+
38+ - name : Install composer dependencies
39+ if : steps.check_composer.outputs.files_exists == 'true'
40+ run : composer install --no-dev
41+
42+ - name : Read package.json node and npm engines version
43+ uses : skjnldsv/read-package-engines-version-actions@8205673bab74a63eb9b8093402fd9e0e018663a1 # v2.2
44+ id : versions
45+ with :
46+ fallbackNode : " ^20"
47+ fallbackNpm : " ^9"
48+
49+ - name : Set up node ${{ steps.versions.outputs.nodeVersion }}
50+ uses : actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
51+ with :
52+ node-version : ${{ steps.versions.outputs.nodeVersion }}
53+
54+ - name : Set up npm ${{ steps.versions.outputs.npmVersion }}
55+ run : npm i -g npm@"${{ steps.versions.outputs.npmVersion }}"
56+
57+ - name : Install node dependencies & build app
58+ run : |
59+ npm ci
60+ TESTING=true npm run build --if-present
61+
62+ - name : Save context
63+ uses : buildjet/cache/save@e376f15c6ec6dc595375c78633174c7e5f92dc0e # v3
64+ with :
65+ key : cypress-context-${{ github.run_id }}
66+ path : ./
67+
68+ cypress :
69+ runs-on : ubuntu-latest
70+ needs : init
71+
72+ strategy :
73+ fail-fast : false
74+ matrix :
75+ # Run multiple copies of the current job in parallel
76+ # Please increase the number or runners as your tests suite grows
77+ containers : ["component", 1, 2, 3]
78+
79+ name : runner ${{ matrix.containers }}
80+
81+ steps :
82+ - name : Restore context
83+ uses : buildjet/cache/restore@e376f15c6ec6dc595375c78633174c7e5f92dc0e # v3
84+ with :
85+ fail-on-cache-miss : true
86+ key : cypress-context-${{ github.run_id }}
87+ path : ./
88+
89+ - name : Set up node ${{ needs.init.outputs.nodeVersion }}
90+ uses : actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
91+ with :
92+ node-version : ${{ needs.init.outputs.nodeVersion }}
93+
94+ - name : Set up npm ${{ needs.init.outputs.npmVersion }}
95+ run : npm i -g npm@"${{ needs.init.outputs.npmVersion }}"
96+
97+ - name : Run ${{ matrix.containers == 'component' && 'component' || 'E2E' }} cypress tests
98+ uses : cypress-io/github-action@7215fc1624803790752b15000c55f71354592d84 # v6.4.0
99+ with :
100+ record : true
101+ parallel : true
102+ # cypress run type
103+ component : ${{ matrix.containers == 'component' }}
104+ group : Run ${{ matrix.containers == 'component' && 'component' || 'E2E' }}
105+ # cypress env
106+ ci-build-id : ${{ github.sha }}-${{ github.run_number }}
107+ tag : ${{ github.event_name }}
108+ env :
109+ # Needs to be prefixed with CYPRESS_
110+ CYPRESS_BRANCH : ${{ env.BRANCH }}
111+ # https://github.com/cypress-io/github-action/issues/124
112+ COMMIT_INFO_MESSAGE : ${{ github.event.pull_request.title }}
113+ # Needed for some specific code workarounds
114+ TESTING : true
115+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
116+ CYPRESS_RECORD_KEY : ${{ secrets.CYPRESS_RECORD_KEY }}
117+
118+ - name : Upload snapshots
119+ uses : actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
120+ if : always()
121+ with :
122+ name : snapshots_${{ matrix.containers }}
123+ path : cypress/snapshots
124+
125+ - name : Extract NC logs
126+ if : failure() && matrix.containers != 'component'
127+ run : docker logs nextcloud-cypress-tests-${{ env.APP_NAME }} > nextcloud.log
128+
129+ - name : Upload NC logs
130+ uses : actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
131+ if : failure() && matrix.containers != 'component'
132+ with :
133+ name : nc_logs_${{ matrix.containers }}
134+ path : nextcloud.log
135+
136+ summary :
137+ runs-on : ubuntu-latest
138+ needs : [init, cypress]
139+
140+ if : always()
141+
142+ name : cypress-summary
143+
144+ steps :
145+ - name : Summary status
146+ run : if ${{ needs.init.result != 'success' || ( needs.cypress.result != 'success' && needs.cypress.result != 'skipped' ) }}; then exit 1; fi
0 commit comments