forked from moodlehq/moodleapp
-
Notifications
You must be signed in to change notification settings - Fork 0
308 lines (256 loc) · 8.93 KB
/
coverage.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
name: Coverage
on:
workflow_dispatch:
inputs:
behat_tags:
description: 'Behat tags to execute'
moodle_branch:
description: 'Moodle branch'
required: true
default: 'main'
moodle_repository:
description: 'Moodle repository'
required: true
default: 'https://github.com/moodle/moodle.git'
concurrency:
group: coverage-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
build:
runs-on: ubuntu-latest
outputs:
tags: ${{ steps.set-tags.outputs.tags }}
steps:
- uses: actions/checkout@v4
with:
path: app
- uses: actions/setup-node@v4
with:
node-version-file: 'app/.nvmrc'
- name: Install npm dependencies
working-directory: app
run: npm ci --no-audit
- name: Build app
working-directory: app
run: npm run build:test
env:
MOODLE_APP_COVERAGE: true
- name: Generate SSL certificates
working-directory: app
run: |
mkdir ./ssl
openssl req -x509 -nodes \
-days 365 \
-newkey rsa:2048 \
-keyout ./ssl/certificate.key \
-out ./ssl/certificate.crt \
-subj="/O=Moodle"
- name: Build Behat plugin
working-directory: app
run: ./scripts/build-behat-plugin.js ../plugin
- name: Prepare Behat tags
id: set-tags
working-directory: app
run: |
if [ -z $BEHAT_TAGS ]; then
tags_json=`.github/scripts/print_behat_tags_json.sh`
echo "tags=$tags_json" >> $GITHUB_OUTPUT;
else
echo "tags=[\"$BEHAT_TAGS\"]" >> $GITHUB_OUTPUT;
fi
env:
BEHAT_TAGS: ${{ github.event.inputs.behat_tags }}
# We need to upload an artifact so that the download-artifact action
# in the "complete" job does not fail if no other artifacts were uploaded.
- name: Create build logs
run: touch logs.txt
- name: Upload build logs
uses: actions/upload-artifact@v4
with:
name: build
path: logs.txt
- uses: actions/cache/save@v4
with:
key: build-${{ github.sha }}
path: |
app/ssl/**/*
app/node_modules/**/*
app/www/**/*
plugin/**/*
jest:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
with:
path: app
- uses: actions/setup-node@v4
with:
node-version-file: 'app/.nvmrc'
- uses: actions/cache/restore@v4
with:
key: build-${{ github.sha }}
path: |
app/ssl/**/*
app/node_modules/**/*
app/www/**/*
plugin/**/*
- name: Run Jest tests
working-directory: app
run: |
NODE_ENV=testing npx gulp
npx jest --coverage --coverageReporters=json
mkdir ../coverage-jsons
mv coverage/coverage-final.json ../coverage-jsons/jest.json
- uses: actions/upload-artifact@v4
with:
name: coverage-jsons-jest
path: coverage-jsons
behat:
runs-on: ubuntu-latest
needs: build
continue-on-error: true
strategy:
matrix:
tags: ${{ fromJSON(needs.build.outputs.tags) }}
services:
postgres:
image: postgres:13
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
steps:
- uses: actions/checkout@v4
with:
path: app
- uses: actions/setup-node@v4
with:
node-version-file: 'app/.nvmrc'
- uses: shivammathur/setup-php@v2
with:
php-version: 8.1
ini-values: max_input_vars=5000
coverage: none
- uses: actions/cache/restore@v4
with:
key: build-${{ github.sha }}
path: |
app/ssl/**/*
app/node_modules/**/*
app/www/**/*
plugin/**/*
- name: Launch Docker images
working-directory: app
run: |
docker run -d --rm \
-p 8001:443 \
--name moodleapp \
-v ./www:/usr/share/nginx/html \
-v ./nginx.conf:/etc/nginx/conf.d/default.conf \
-v ./ssl/certificate.crt:/etc/ssl/certificate.crt \
-v ./ssl/certificate.key:/etc/ssl/certificate.key \
nginx:alpine
docker run -d --rm -p 8002:80 --name bigbluebutton moodlehq/bigbluebutton_mock:latest
- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4.4
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
# Install nvm v0.39.7 as a temporary workaround for issue:
# https://github.com/moodlehq/moodle-plugin-ci/issues/309
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
- name: Install Behat Snapshots plugin
run: moodle-plugin-ci add-plugin moodlemobile/moodle-local_behatsnapshots
- name: Install moodle-plugin-ci
run: moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
env:
DB: pgsql
MOODLE_BRANCH: ${{ github.event.inputs.moodle_branch || 'main' }}
MOODLE_REPO: ${{ github.event.inputs.moodle_repository || 'https://github.com/moodle/moodle.git' }}
MOODLE_BEHAT_IONIC_WWWROOT: https://localhost:8001
MOODLE_BEHAT_DEFAULT_BROWSER: chrome
MOODLE_BEHAT_CHROME_CAPABILITIES: "['extra_capabilities' => ['chromeOptions' => ['args' => ['--ignore-certificate-errors', '--allow-running-insecure-content']]]]"
- name: Update config
run: |
moodle-plugin-ci add-config "\$CFG->behat_extraallowedsettings = ['forced_plugin_settings'];"
moodle-plugin-ci add-config "\$CFG->forced_plugin_settings = ['local_moodleappbehat' => ['coverage_path' => '$GITHUB_WORKSPACE/moodle/coverage/']];"
moodle-plugin-ci add-config 'define("TEST_MOD_BIGBLUEBUTTONBN_MOCK_SERVER", "http://localhost:8002/hash" . sha1($CFG->wwwroot));'
- name: Run Behat tests
run: moodle-plugin-ci behat --auto-rerun 3 --profile chrome --tags="@app&&~@local&&$BEHAT_TAGS"
env:
BEHAT_TAGS: ${{ matrix.tags }}
MOODLE_BEHAT_SELENIUM_IMAGE: selenium/standalone-chrome:120.0
- name: Merge Coverage jsons
working-directory: app
run: |
mkdir ../coverage-jsons
mkdir -p ../moodle/coverage/
echo "{}" > ../moodle/coverage/base.json
npx nyc merge ../moodle/coverage/ ../coverage-jsons/$BEHAT_TAGS.json
env:
BEHAT_TAGS: ${{ matrix.tags }}
- name: Upload Coverage JSONs
uses: actions/upload-artifact@v4
with:
name: coverage-jsons-${{ matrix.tags }}
path: coverage-jsons
- name: Upload Snapshot failures
uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: snapshot_failures-${{ matrix.tags }}
path: moodle/local/moodleappbehat/tests/behat/snapshots/failures/*
- name: Upload Behat failures
uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: behat_failures-${{ matrix.tags }}
path: moodledata/behat_dump/*
complete:
runs-on: ubuntu-latest
needs: [behat, jest]
steps:
- uses: actions/checkout@v4
with:
path: app
- uses: actions/setup-node@v4
with:
node-version-file: 'app/.nvmrc'
- uses: actions/cache/restore@v4
with:
key: build-${{ github.sha }}
path: |
app/ssl/**/*
app/node_modules/**/*
app/www/**/*
plugin/**/*
- uses: actions/download-artifact@v4
with:
path: artifacts
- name: Prepare coverage jsons
run: |
mkdir ./app/coverage-jsons
mv ./artifacts/coverage-jsons-*/* ./app/coverage-jsons
rm ./artifacts/coverage-jsons* -r
- name: Check failure artifacts
run: |
rm ./artifacts/build -rf
if [ -n "$(ls -A ./artifacts)" ]; then
echo "There were some failures in the previous jobs"
exit 1
fi
- name: Generate Coverage report
working-directory: app
run: |
npx nyc merge ./coverage-jsons/ .nyc_output/out.json
npx nyc report --reporter=html-spa
cp .nyc_output/out.json coverage/coverage-final.json
- name: Upload Coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-html
path: app/coverage/*