-
Notifications
You must be signed in to change notification settings - Fork 40
209 lines (186 loc) · 7.12 KB
/
ci.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
name: Moodle Local CI
on: [push, pull_request, workflow_dispatch]
jobs:
collect:
name: Collect tests
runs-on: ubuntu-latest
outputs:
matrix: ${{steps.collect-tests.outputs.matrix }}
steps:
- name: Checking out moodle-local_ci
uses: actions/checkout@v4
with:
path: local_ci
- name: Collecting Bats tests
id: collect-tests
run: |
# Get all the test files without extension.
echo "matrix=$(cd local_ci/tests && find . -name '*.bats' -not -path '*/libs/*' -exec basename {} .bats ';' | \
jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
test:
name: Unit tests
needs: collect
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
test: ${{ fromJson(needs.collect.outputs.matrix) }}
steps:
- name: Checking out moodle-local_ci
uses: actions/checkout@v4
with:
path: local_ci
- name: Checking out moodle
uses: actions/checkout@v4
with:
repository: moodle/moodle
fetch-depth: 0 # We need a complete clone, because we use various commits / tags.
path: moodle
- name: Setting user in moodle clone
run: | # We need this set because local_ci does perform git write operations.
git config --global user.email "local_ci@moodle.com"
git config --global user.name "Local CI"
- name: Setting up DB mysql
uses: moodlehq/mysql-action@v1
with:
collation server: utf8mb4_bin
mysql version: 8.0
mysql root password: test
use tmpfs: true
tmpfs size: '1024M'
extra conf: --skip-log-bin
- name: Setting up PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
ini-values: max_input_vars=5000
tools: composer
coverage: none
- name: Configuring node & npm
uses: actions/setup-node@v4
with:
node-version-file: 'moodle/.nvmrc'
- name: Installing composer and node stuff
run: |
cd local_ci
composer install
npm install
- name: Setup Bats
uses: bats-core/bats-action@2.0.0
with:
bats-version: 1.11.0
# We need only support and assert libraries, and installed locally for caching to work.
# See https://github.com/brokenpip3/setup-bats-libs/issues/18
support-path: "${{ github.workspace }}/.bats/bats-support"
assert-path: "${{ github.workspace }}/.bats/bats-assert"
detik-install: false
file-install: false
- name: Run Tests
working-directory: local_ci # Tests have to start from here, because some use $PWD to detect the local_ci base.
env:
LOCAL_CI_TESTS_CACHEDIR: ${{ github.workspace }}/cachedir
LOCAL_CI_TESTS_GITDIR: ${{ github.workspace }}/moodle
LOCAL_CI_TESTS_PHPCS_DIR: ${{ github.workspace }}/local_ci/vendor/moodlehq/moodle-cs/moodle
LOCAL_CI_TESTS_DBLIBRARY: native
LOCAL_CI_TESTS_DBTYPE: mysqli
LOCAL_CI_TESTS_DBHOST: 127.0.0.1
LOCAL_CI_TESTS_DBUSER: root
LOCAL_CI_TESTS_DBPASS: test
# We need to specify where the libraries are, installed locally for caching to work.
# See https://github.com/brokenpip3/setup-bats-libs/issues/18
BATS_LIB_PATH: "${{ github.workspace }}/.bats"
run: |
mkdir -p ${LOCAL_CI_TESTS_CACHEDIR}
bats --timing tests/${{ matrix.test }}.bats
coverage:
if: github.repository == 'moodlehq/moodle-local_ci'
name: Code coverage
needs: collect
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
test: ${{ fromJson(needs.collect.outputs.matrix) }}
steps:
- name: Install required packages
run: |
sudo apt-get update
sudo apt-get install uuid kcov
- name: Checking out moodle-local_ci
uses: actions/checkout@v4
with:
path: local_ci
- name: Checking out moodle
uses: actions/checkout@v4
with:
repository: moodle/moodle
fetch-depth: 0 # We need a complete clone, because we use various commits / tags.
path: moodle
- name: Setting user in moodle clone
run: | # We need this set because local_ci does perform git write operations.
git config --global user.email "local_ci@moodle.com"
git config --global user.name "Local CI"
- name: Setting up DB mysql
uses: moodlehq/mysql-action@v1
with:
collation server: utf8mb4_bin
mysql version: 8.0
mysql root password: test
use tmpfs: true
tmpfs size: '1024M'
extra conf: --skip-log-bin
- name: Setting up PHP 8.3
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
ini-values: max_input_vars=5000
tools: composer
coverage: none
- name: Configuring node & npm
uses: actions/setup-node@v4
with:
node-version-file: 'moodle/.nvmrc'
- name: Installing composer and node stuff
run: |
cd local_ci
composer install
npm install
- name: Setup Bats
uses: bats-core/bats-action@2.0.0
with:
bats-version: 1.11.0
# We need only support and assert libraries, and installed locally for caching to work.
# See https://github.com/brokenpip3/setup-bats-libs/issues/18
support-path: "${{ github.workspace }}/.bats/bats-support"
assert-path: "${{ github.workspace }}/.bats/bats-assert"
detik-install: false
file-install: false
- name: Run Tests (capturing code coverage)
working-directory: local_ci # Tests have to start from here, because some use $PWD to detect the local_ci base.
env:
LOCAL_CI_TESTS_CACHEDIR: ${{ github.workspace }}/cachedir
LOCAL_CI_TESTS_GITDIR: ${{ github.workspace }}/moodle
LOCAL_CI_TESTS_PHPCS_DIR: ${{ github.workspace }}/local_ci/vendor/moodlehq/moodle-cs/moodle
LOCAL_CI_TESTS_DBLIBRARY: native
LOCAL_CI_TESTS_DBTYPE: mysqli
LOCAL_CI_TESTS_DBHOST: 127.0.0.1
LOCAL_CI_TESTS_DBUSER: root
LOCAL_CI_TESTS_DBPASS: test
# We need to specify where the libraries are, installed locally for caching to work.
# See https://github.com/brokenpip3/setup-bats-libs/issues/18
BATS_LIB_PATH: "${{ github.workspace }}/.bats"
run: |
mkdir -p ${LOCAL_CI_TESTS_CACHEDIR}
kcov \
--clean \
--include-path=. \
--exclude-path=".git,.github,remote_branch_checker/xslt,tests,vendor" \
--bash-parse-files-in-dir=. \
${{ github.workspace }}/coverage \
bats tests/${{ matrix.test }}.bats
- name: Upload code coverage (codecov)
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ${{ github.workspace }}/coverage
flags: ${{ matrix.test }}