-
Notifications
You must be signed in to change notification settings - Fork 13
735 lines (705 loc) · 28.5 KB
/
ci.yml
File metadata and controls
735 lines (705 loc) · 28.5 KB
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
# .github/workflows/ci.yml
name: ci
on:
workflow_call:
inputs:
internal_workflow_branch:
type: string
description: 'Sets the branch the reusable workflow calls reusable workflow actions with'
default: 'main'
codechecker_max_warnings:
type: string
description: 'Sets the value for --max-warnings on the moodle-plugin-ci codechecker step. Defaults to -1 which means no limit.'
default: '-1'
extra_php_extensions:
type: string
extra_plugin_runners:
type: string
disable_behat:
type: boolean
disable_mustache:
type: boolean
disable_phplint:
type: boolean
disable_phpdoc:
type: boolean
description: 'If true, this will skip testing phpdocs'
default: false
disable_phpcs:
type: boolean
description: 'If true, this will skip testing php code standards'
default: false
disable_phpunit:
type: boolean
disable_grunt:
type: boolean
disable_master:
description: 'If true, this will skip testing against moodle/main branch'
type: boolean
disable_release:
description: 'If true, this will skip the release job'
type: boolean
default: false
enable_phpmd:
type: boolean
default: false
disable_ci_validate:
type: boolean
default: false
disable_version_bump_check:
description: 'If true, this will skip enforcing version bump checks on pull requests'
type: boolean
default: false
release_branches:
description: 'Required if the branch that should process releases is in a non-standard format (e.g. main or MOODLE_XX_STABLE)'
type: string
moodle_branches:
description: 'Specify the MOODLE_XX_STABLE branch you want to test against'
type: string
min_php:
description: 'Specify the minimum version of PHP to test against. Will exclude workflows using older versions of PHP.'
type: string
default: '7.4'
ignore_paths:
description: 'Specify custom paths for CI to ignore. Third party libraries are ignored by default.'
type: string
default: ''
concurrent_skipping:
description: 'Skip a workflow run if the same workflow is already running. See: https://github.com/fkirc/skip-duplicate-actions?tab=readme-ov-file#concurrent_skipping'
type: string
default: 'same_content_newer'
secrets:
moodle_org_token:
required: false
jobs:
pre_job:
name: check if job needs to run
runs-on: ubuntu-latest
# Map a step output to a job output
outputs:
should_skip: ${{ steps.eligibility.outputs.should_skip }}
steps:
- id: eligibility
name: Check branch/event eligibility
env:
EVENT_NAME: ${{ github.event_name }}
REF_PROTECTED: ${{ github.ref_protected }}
run: |
should_skip=true
if [[ "${EVENT_NAME}" == "pull_request" || ( "${EVENT_NAME}" == "push" && "${REF_PROTECTED}" == "true" ) ]]; then
should_skip=false
fi
echo "should_skip=${should_skip}" >> "${GITHUB_OUTPUT}"
prepare_matrix:
needs: pre_job
if: needs.pre_job.outputs.should_skip != 'true'
name: prepare test matrix
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.moodle_branches }}-${{ inputs.extra_plugin_runners }}
cancel-in-progress: true
runs-on: 'ubuntu-latest'
outputs:
matrix: ${{ steps.parse-version.outputs.matrix }}
behat_matrix: ${{ steps.parse-version.outputs.behat_matrix }}
phpunit_matrix: ${{ steps.parse-version.outputs.phpunit_matrix }}
component: ${{ steps.parse-version.outputs.component }}
highest_moodle_branch: ${{ steps.parse-version.outputs.highest_moodle_branch }}
latest_container: ${{ steps.parse-version.outputs.latest_container }}
latest_pgsql_ver: ${{ steps.parse-version.outputs.latest_pgsql_ver }}
highest_php: ${{ steps.parse-version.outputs.highest_php }}
highest_node: ${{ steps.parse-version.outputs.highest_node }}
lowest_php: ${{ steps.parse-version.outputs.lowest_php }}
release_required: ${{ (
contains(github.event_name, 'push') &&
steps.check-version.outputs.any_changed == 'true' &&
steps.check-branch.outputs.publishable == 'true'
) }}
steps:
- name: Check if currently on a publishable branch
id: check-branch
run: |
publishable=${{ github.event.repository.fork == false &&
inputs.disable_release == false && (
(startsWith(github.ref, 'refs/heads/MOODLE_') &&
endsWith(github.ref, '_STABLE')) ||
github.ref == 'refs/heads/main' || (
inputs.release_branches != '' &&
endsWith(github.ref, inputs.release_branches)
)
) }}
echo "::set-output name=publishable::$publishable"
- uses: actions/checkout@v3
- name: Check out CI code
uses: actions/checkout@v3
with:
path: ci
repository: catalyst/catalyst-moodle-workflows
ref: ${{ inputs.internal_workflow_branch }}
token: ${{ github.token }}
- name: Check out plugin code
uses: actions/checkout@v3
with:
# Needed for 'changed-files' actions (alternatively could be a fixed
# large number but may cause issues if limited).
fetch-depth: 20
path: plugin
submodules: true
- name: Check if release is required (version.php changes)
if: contains(github.event_name, 'push') && steps.check-branch.outputs.publishable == 'true'
uses: tj-actions/changed-files@2f7c5bfce28377bc069a65ba478de0a74aa0ca32 # v46.0.1
id: check-version
with:
path: plugin
files: |
version.php
since_last_remote_commit: "true"
- name: Install PHP
uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0
with:
php-version: '8.1'
coverage: none
# extensions: yaml # FYI: makes the workflow very slow
- name: Determine test requirements and plugin info
id: parse-version
run: |
chmod +x "${GITHUB_WORKSPACE}/ci/.github/actions/parse-version/script.sh"
"${GITHUB_WORKSPACE}/ci/.github/actions/parse-version/script.sh"
env:
disable_master: ${{ inputs.disable_master }}
disable_behat: ${{ inputs.disable_behat }}
disable_phpunit: ${{ inputs.disable_phpunit }}
filter: ${{ inputs.moodle_branches }}
min_php: ${{ inputs.min_php }}
version_bump_check:
name: Enforce version bump on PRs
needs: pre_job
if: |
needs.pre_job.outputs.should_skip != 'true' &&
github.event_name == 'pull_request' &&
inputs.disable_version_bump_check != true &&
startsWith(github.base_ref, 'MOODLE_') && endsWith(github.base_ref, '_STABLE')
runs-on: ubuntu-latest
steps:
- name: Check out plugin code
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Fetch PR base and head commits
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -euo pipefail
git fetch --no-tags --depth=1 origin "${BASE_SHA}"
git fetch --no-tags --depth=1 origin "${HEAD_SHA}"
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
coverage: none
- name: Validate plugin version bump
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -euo pipefail
php <<'PHP'
<?php
$baseSha = getenv('BASE_SHA');
$headSha = getenv('HEAD_SHA');
if (!$baseSha || !$headSha) {
fwrite(STDERR, "Missing BASE_SHA or HEAD_SHA.\n");
exit(1);
}
function load_version_from_sha(string $sha, bool $allowFloat): string {
$target = escapeshellarg($sha . ':version.php');
$outputLines = [];
$exitCode = 0;
exec("git show {$target} 2>&1", $outputLines, $exitCode);
if ($exitCode !== 0) {
$outputText = trim(implode("\n", $outputLines));
fwrite(STDERR, "Failed to read version.php for commit {$sha} (git show exit code {$exitCode}).\n");
if ($outputText !== '') {
fwrite(STDERR, "git show output:\n{$outputText}\n");
}
exit(1);
}
$content = implode("\n", $outputLines);
$pattern = $allowFloat
? '/\\$plugin->version\\s*=\\s*([0-9]+(?:\\.[0-9]+)?)\\s*;/'
: '/\\$plugin->version\\s*=\\s*([0-9]+)\\s*;/';
if (!preg_match($pattern, $content, $matches)) {
$expectedType = $allowFloat ? 'numeric (int or float)' : 'integer';
fwrite(STDERR, "Could not find {$expectedType} \\$plugin->version in version.php at commit {$sha}.\n");
exit(1);
}
return $matches[1];
}
$baseVersion = load_version_from_sha($baseSha, true);
$headVersion = load_version_from_sha($headSha, false);
echo "Base branch version: {$baseVersion}\n";
echo "Feature branch version: {$headVersion}\n";
$baseVersionFloat = (float)$baseVersion;
$headVersionFloat = (float)$headVersion;
$bump = $headVersionFloat - $baseVersionFloat;
if ($bump <= 0.0) {
echo "::error file=version.php::version.php must include a version bump in pull requests.\n";
exit(1);
}
if ($bump > 1.0) {
echo sprintf("::error file=version.php::version bump must be <= 1 (computed bump was %.10f).\n", $bump);
exit(1);
}
echo sprintf("Computed bump: %.10f\n", $bump);
PHP
echo "Version bump check passed."
shell: bash
codechecker:
if: needs.pre_job.outputs.should_skip != 'true'
runs-on: ubuntu-latest
needs: prepare_matrix
steps:
- name: Check out CI code
uses: actions/checkout@v3
with:
path: ci
repository: catalyst/catalyst-moodle-workflows
ref: ${{ inputs.internal_workflow_branch }}
token: ${{ github.token }}
- name: Run plugin setup (canonical)
uses: ./ci/.github/plugin/setup
with:
extra_php_extensions: ${{ inputs.extra_php_extensions }}
extra_plugin_runners: ${{ inputs.extra_plugin_runners }}
moodle_branch: ${{ needs.prepare_matrix.outputs.highest_moodle_branch }}
- name: Run codechecker
if: ${{ inputs.disable_phpcs != true }}
run: moodle-plugin-ci codechecker --max-warnings=${{ inputs.codechecker_max_warnings }} ./plugin
shell: bash
- name: Install PHPCompatibility
if: ${{ always() && inputs.disable_phpcs != true }}
run: |
mkdir -p /tmp/phpcompat
printf '{"name":"tmp/phpcompat","minimum-stability":"dev","prefer-stable":true,"config":{"allow-plugins":{"dealerdirect/phpcodesniffer-composer-installer":true}}}' \
> /tmp/phpcompat/composer.json
composer --working-dir=/tmp/phpcompat require \
phpcompatibility/php-compatibility:"dev-develop as 10.0.0" \
dealerdirect/phpcodesniffer-composer-installer
- name: Run PHP Compatibility check
if: ${{ always() && inputs.disable_phpcs != true }}
run: |
ignore="vendor,node_modules"
if [ -n "${{ inputs.ignore_paths }}" ]; then
ignore="$ignore,${{ inputs.ignore_paths }}"
fi
/tmp/phpcompat/vendor/bin/phpcs --standard=PHPCompatibility --runtime-set testVersion ${{ needs.prepare_matrix.outputs.lowest_php || inputs.min_php }} --ignore=$ignore ./plugin
shell: bash
phplint:
if: needs.pre_job.outputs.should_skip != 'true'
runs-on: ubuntu-latest
needs: prepare_matrix
steps:
- name: Check out CI code
uses: actions/checkout@v3
with:
path: ci
repository: catalyst/catalyst-moodle-workflows
ref: ${{ inputs.internal_workflow_branch }}
token: ${{ github.token }}
- name: Run plugin setup (canonical)
uses: ./ci/.github/plugin/setup
with:
extra_php_extensions: ${{ inputs.extra_php_extensions }}
extra_plugin_runners: ${{ inputs.extra_plugin_runners }}
moodle_branch: ${{ needs.prepare_matrix.outputs.highest_moodle_branch }}
- name: Run phplint
if: ${{ inputs.disable_phplint != true }}
run: moodle-plugin-ci phplint ./plugin
shell: bash
validate:
if: needs.pre_job.outputs.should_skip != 'true'
runs-on: ubuntu-latest
needs: prepare_matrix
steps:
- name: Check out CI code
uses: actions/checkout@v3
with:
path: ci
repository: catalyst/catalyst-moodle-workflows
ref: ${{ inputs.internal_workflow_branch }}
token: ${{ github.token }}
- name: Run plugin setup (canonical)
uses: ./ci/.github/plugin/setup
with:
php: ${{ needs.prepare_matrix.outputs.highest_php }}
node: ${{ needs.prepare_matrix.outputs.highest_node }}
extra_php_extensions: ${{ inputs.extra_php_extensions }}
extra_plugin_runners: ${{ inputs.extra_plugin_runners }}
moodle_branch: ${{ needs.prepare_matrix.outputs.highest_moodle_branch }}
- name: Run validate
if: ${{ inputs.disable_ci_validate != true }}
run: moodle-plugin-ci validate
shell: bash
savepoints:
name: Savepoints
if: needs.pre_job.outputs.should_skip != 'true'
runs-on: ubuntu-latest
needs: prepare_matrix
steps:
- name: Check out CI code
uses: actions/checkout@v3
with:
path: ci
repository: catalyst/catalyst-moodle-workflows
ref: ${{ inputs.internal_workflow_branch }}
token: ${{ github.token }}
- name: Run plugin setup (canonical)
uses: ./ci/.github/plugin/setup
with:
php: ${{ needs.prepare_matrix.outputs.highest_php }}
node: ${{ needs.prepare_matrix.outputs.highest_node }}
extra_php_extensions: ${{ inputs.extra_php_extensions }}
extra_plugin_runners: ${{ inputs.extra_plugin_runners }}
moodle_branch: ${{ needs.prepare_matrix.outputs.highest_moodle_branch }}
- name: Run savepoints
run: moodle-plugin-ci savepoints ./plugin
shell: bash
mustache:
if: needs.pre_job.outputs.should_skip != 'true'
runs-on: ubuntu-latest
needs: prepare_matrix
steps:
- name: Check out CI code
uses: actions/checkout@v3
with:
path: ci
repository: catalyst/catalyst-moodle-workflows
ref: ${{ inputs.internal_workflow_branch }}
token: ${{ github.token }}
- name: Run plugin setup (canonical)
uses: ./ci/.github/plugin/setup
with:
extra_php_extensions: ${{ inputs.extra_php_extensions }}
extra_plugin_runners: ${{ inputs.extra_plugin_runners }}
moodle_branch: ${{ needs.prepare_matrix.outputs.highest_moodle_branch }}
php: ${{ needs.prepare_matrix.outputs.highest_php }}
node: ${{ needs.prepare_matrix.outputs.highest_node }}
- name: Run mustache
if: ${{ inputs.disable_mustache != true }}
run: moodle-plugin-ci mustache
shell: bash
grunt:
if: needs.pre_job.outputs.should_skip != 'true'
runs-on: ubuntu-latest
needs: prepare_matrix
steps:
- name: Check out CI code
uses: actions/checkout@v3
with:
path: ci
repository: catalyst/catalyst-moodle-workflows
ref: ${{ inputs.internal_workflow_branch }}
token: ${{ github.token }}
- name: Run plugin setup (canonical)
uses: ./ci/.github/plugin/setup
with:
php: ${{ needs.prepare_matrix.outputs.highest_php }}
node: ${{ needs.prepare_matrix.outputs.highest_node }}
extra_php_extensions: ${{ inputs.extra_php_extensions }}
extra_plugin_runners: ${{ inputs.extra_plugin_runners }}
moodle_branch: ${{ needs.prepare_matrix.outputs.highest_moodle_branch }}
- name: Install Moodle node dependencies
run: npm install --prefix $MOODLE_DIR
shell: bash
- name: Run grunt
if: ${{ inputs.disable_grunt != true }}
run: |
moodle-plugin-ci grunt
shell: bash
phpmd:
if: needs.pre_job.outputs.should_skip != 'true'
runs-on: ubuntu-latest
needs: prepare_matrix
steps:
- name: Check out CI code
uses: actions/checkout@v3
with:
path: ci
repository: catalyst/catalyst-moodle-workflows
ref: ${{ inputs.internal_workflow_branch }}
token: ${{ github.token }}
- name: Run plugin setup (canonical)
uses: ./ci/.github/plugin/setup
with:
php: ${{ needs.prepare_matrix.outputs.highest_php }}
node: ${{ needs.prepare_matrix.outputs.highest_node }}
extra_php_extensions: ${{ inputs.extra_php_extensions }}
extra_plugin_runners: ${{ inputs.extra_plugin_runners }}
moodle_branch: ${{ needs.prepare_matrix.outputs.highest_moodle_branch }}
- name: Run phpmd
if: ${{ inputs.enable_phpmd == true }}
run: moodle-plugin-ci phpmd ./plugin
shell: bash
phpdoc:
if: needs.pre_job.outputs.should_skip != 'true'
runs-on: ubuntu-latest
needs: prepare_matrix
steps:
- name: Check out CI code
uses: actions/checkout@v3
with:
path: ci
repository: catalyst/catalyst-moodle-workflows
ref: ${{ inputs.internal_workflow_branch }}
token: ${{ github.token }}
- name: Run plugin setup (canonical)
uses: ./ci/.github/plugin/setup
with:
php: ${{ needs.prepare_matrix.outputs.highest_php }}
node: ${{ needs.prepare_matrix.outputs.highest_node }}
extra_php_extensions: ${{ inputs.extra_php_extensions }}
extra_plugin_runners: ${{ inputs.extra_plugin_runners }}
moodle_branch: ${{ needs.prepare_matrix.outputs.highest_moodle_branch }}
- name: Run phpdoc
if: ${{ inputs.disable_phpdoc != true }}
run: |
set +e
output=`GITHUB_PATH=$GITHUB_PATH moodle-plugin-ci phpdoc ./plugin`
haserrors=$?
if [[ $haserrors -eq 0 ]]; then
echo "phpdoc checks - OK"
exit 0
fi
output=`echo "$output" | grep -v 'Class ( is not documented' | grep -v 'Could not connect to debugging client.'`
output=`echo "$output" | grep -B1 'Line'`
currentdir=$(pwd)
if [[ "$output" ]]; then
echo "$output" | sed -e "s,$currentdir/,,g" | sed -e "s,^moodle/,,g" | tee $GITHUB_STEP_SUMMARY
exit 1
fi
echo "phpdoc checks - OK"
shell: bash
phpunit:
name: ${{ matrix.moodle-branch-short }} - phpunit - php${{ matrix.php }} - ${{ matrix.database }}
needs: prepare_matrix
if: needs.pre_job.outputs.should_skip != 'true' && fromJson(needs.prepare_matrix.outputs.phpunit_matrix).include[0] != null
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare_matrix.outputs.phpunit_matrix) }}
env:
IGNORE_PATHS: tests/fixtures
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.moodle-branch }}-${{ matrix.database }}-${{ matrix.php }}-${{ needs.prepare_matrix.outputs.component }}-phpunit
cancel-in-progress: true
runs-on: 'ubuntu-latest'
services:
postgres:
image: ${{ matrix.pgsql-ver && format('postgres:{0}', matrix.pgsql-ver) || '' }}
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 3
ports:
- 5432:5432
mariadb:
image: ${{ matrix.mariadb-ver && format('mariadb:{0}', matrix.mariadb-ver) || '' }}
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
MYSQL_CHARACTER_SET_SERVER: "utf8mb4"
MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci"
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval 10s
--health-timeout 5s
--health-retries 3
steps:
- name: Check out CI code
uses: actions/checkout@v3
with:
path: ci
repository: catalyst/catalyst-moodle-workflows
ref: ${{ inputs.internal_workflow_branch }}
token: ${{ github.token }}
- name: Tune PostgreSQL for CI speed
if: matrix.database == 'pgsql'
run: |
psql -h 127.0.0.1 -U postgres -c "ALTER SYSTEM SET fsync = off"
psql -h 127.0.0.1 -U postgres -c "ALTER SYSTEM SET synchronous_commit = off"
psql -h 127.0.0.1 -U postgres -c "ALTER SYSTEM SET full_page_writes = off"
psql -h 127.0.0.1 -U postgres -c "ALTER SYSTEM SET checkpoint_completion_target = 0.9"
psql -h 127.0.0.1 -U postgres -c "ALTER SYSTEM SET max_wal_size = '1GB'"
psql -h 127.0.0.1 -U postgres -c "SELECT pg_reload_conf()"
- name: Run plugin setup
uses: ./ci/.github/plugin/setup
with:
php: ${{ matrix.php }}
extra_php_extensions: ${{ inputs.extra_php_extensions }}
extra_plugin_runners: ${{ inputs.extra_plugin_runners }}
moodle_branch: ${{ matrix.moodle-branch }}
database: ${{ matrix.database }}
- name: Create database and restore PHPUnit snapshot
run: |
START_TS=$(date +%s)
# Extract phpunit snapshot zip from the image — fail if missing.
CID=$(docker create "$SNAPSHOT_IMAGE")
docker cp "$CID:/phpunit-snapshot.zip" ./phpunit-snapshot.zip
docker rm "$CID"
# Create the Moodle database.
if [ "${{ matrix.database }}" = "pgsql" ]; then
psql -h 127.0.0.1 -U postgres -d postgres -c "DROP DATABASE IF EXISTS moodle;"
psql -h 127.0.0.1 -U postgres -d postgres -c "CREATE DATABASE moodle;"
else
mysql -h 127.0.0.1 -u root -e "DROP DATABASE IF EXISTS moodle; CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
fi
# phpunit_dataroot is always $GITHUB_WORKSPACE/moodledata/phpunit per the config template.
PHPUNIT_DATAROOT="$GITHUB_WORKSPACE/moodledata/phpunit"
mkdir -p "$PHPUNIT_DATAROOT"
cp "$GITHUB_WORKSPACE/phpunit-snapshot.zip" "$PHPUNIT_DATAROOT/ci-phpunit.zip"
# Detect phpunit util location (differs between classic and public/ layouts).
if [ -f "$GITHUB_WORKSPACE/moodle/public/admin/tool/phpunit/cli/util.php" ]; then
PHPUNIT_UTIL="$GITHUB_WORKSPACE/moodle/public/admin/tool/phpunit/cli/util.php"
elif [ -f "$GITHUB_WORKSPACE/moodle/admin/tool/phpunit/cli/util.php" ]; then
PHPUNIT_UTIL="$GITHUB_WORKSPACE/moodle/admin/tool/phpunit/cli/util.php"
else
echo "Could not locate phpunit util.php"
exit 1
fi
php "$PHPUNIT_UTIL" --restore=ci-phpunit
php "$PHPUNIT_UTIL" --upgrade
php "$PHPUNIT_UTIL" --buildconfig
END_TS=$(date +%s)
echo "Create database and restore PHPUnit snapshot took $((END_TS - START_TS))s"
shell: bash
- name: Run phpunit
working-directory: moodle
run: |
echo "::group::Plugin unit tests"
vendor/bin/phpunit --fail-on-risky --disallow-test-output --testsuite ${{ needs.prepare_matrix.outputs.component }}_testsuite
echo "::endgroup::"
echo "::group::Privacy unit tests"
vendor/bin/phpunit --fail-on-risky --disallow-test-output --testsuite core_privacy_testsuite --filter thirdparty_providers_compliant
echo "::endgroup::"
shell: bash
behat:
name: ${{ matrix.moodle-branch-short }} - behat - php${{ matrix.php }} - ${{ matrix.database }}
needs: prepare_matrix
if: needs.pre_job.outputs.should_skip != 'true' && fromJson(needs.prepare_matrix.outputs.behat_matrix).include[0] != null
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare_matrix.outputs.behat_matrix) }}
env:
IGNORE_PATHS: tests/fixtures
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.moodle-branch }}-${{ matrix.database }}-${{ matrix.php }}-${{ needs.prepare_matrix.outputs.component }}-behat
cancel-in-progress: true
runs-on: 'ubuntu-latest'
services:
postgres:
image: ${{ matrix.pgsql-ver && format('postgres:{0}', matrix.pgsql-ver) || '' }}
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 3
ports:
- 5432:5432
mariadb:
image: ${{ matrix.mariadb-ver && format('mariadb:{0}', matrix.mariadb-ver) || '' }}
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
MYSQL_CHARACTER_SET_SERVER: "utf8mb4"
MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci"
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval 10s
--health-timeout 5s
--health-retries 3
steps:
- name: Check out CI code
uses: actions/checkout@v3
with:
path: ci
repository: catalyst/catalyst-moodle-workflows
ref: ${{ inputs.internal_workflow_branch }}
token: ${{ github.token }}
- name: Run plugin setup
uses: ./ci/.github/plugin/setup
with:
php: ${{ matrix.php }}
node: ${{ matrix.node }}
extra_php_extensions: ${{ inputs.extra_php_extensions }}
extra_plugin_runners: ${{ inputs.extra_plugin_runners }}
moodle_branch: ${{ matrix.moodle-branch }}
database: ${{ matrix.database }}
- name: Run behat
run: moodle-plugin-ci behat --profile chrome
shell: bash
release:
name: Release to the Moodle plugin directory
needs:
- pre_job
- prepare_matrix
- phpunit
- behat
- codechecker
- phplint
- validate
- savepoints
- mustache
- grunt
- phpmd
- phpdoc
# If it matches a standard branch naming convention, it should permit a
# release to happen, otherwise this step should be skipped.
# Patterns allowed:
# - MOODLE_XX_STABLE
# - MOODLE_XXX_STABLE
# - main
#
# We use always() + explicit failure/cancelled checks instead of the
# default success() because success() returns false when any dependency
# is 'skipped'. When behat or phpunit are disabled their matrix is empty
# and those jobs are skipped, which would otherwise prevent release from
# running even though all real checks passed.
if: |
always() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled') &&
needs.pre_job.outputs.should_skip != 'true' &&
needs.prepare_matrix.outputs.release_required == 'true'
runs-on: 'ubuntu-latest'
outputs:
has-secrets: ${{ steps.check-secrets.outputs.has-secrets }}
steps:
- name: Check if MOODLE_ORG_TOKEN has been supplied
id: check-secrets
env:
SECRET_TO_CHECK: '${{ secrets.moodle_org_token }}'
if: ${{ env.SECRET_TO_CHECK != '' }}
run: echo "::set-output name=has-secrets::true"
- name: Check out CI code
uses: actions/checkout@v3
with:
path: ci
repository: catalyst/catalyst-moodle-workflows
ref: ${{ inputs.internal_workflow_branch }}
token: ${{ github.token }}
- name: Run plugin release
if: steps.check-secrets.outputs.has-secrets != ''
uses: ./ci/.github/plugin/release
with:
plugin_name: ${{ needs.prepare_matrix.outputs.component }}
moodle_org_token: ${{ secrets.moodle_org_token }}