-
Notifications
You must be signed in to change notification settings - Fork 4
/
action.yml
361 lines (350 loc) · 12.5 KB
/
action.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
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
name: Run tests
description: Run tests for a single matrix entry
inputs:
phpunit:
type: boolean
default: false
phpunit_suite:
type: string
required: false
default: ''
phpunit_fail_on_warning:
type: boolean
default: false
endtoend:
type: boolean
default: false
endtoend_suite:
type: string
required: false
default: ''
endtoend_config:
type: string
required: false
default: ''
endtoend_tags:
type: string
required: false
default: ''
js:
type: boolean
default: false
phpcoverage:
type: boolean
default: false
phplinting:
type: boolean
default: false
doclinting:
type: boolean
default: false
runs:
using: composite
steps:
- name: Validate inputs
shell: bash
env:
PHPUNIT_SUITE: ${{ inputs.phpunit_suite }}
ENDTOEND_SUITE: ${{ inputs.endtoend_suite }}
ENDTOEND_CONFIG: ${{ inputs.endtoend_config }}
ENDTOEND_TAGS: ${{ inputs.endtoend_tags }}
run: |
if ! [[ "$PHPUNIT_SUITE" =~ ^[a-zA-Z0-9_\-]*$ ]]; then
echo "Invalid input for phpunit_suite"
exit 1
fi
if ! [[ "$ENDTOEND_SUITE" =~ ^[a-zA-Z0-9_\-]*$ ]]; then
echo "Invalid input for endtoend_suite"
exit 1
fi
if ! [[ "$ENDTOEND_CONFIG" =~ ^[a-zA-Z0-9_\./\-]*$ ]]; then
echo "Invalid input for endtoend_config"
exit 1
fi
if ! [[ "$ENDTOEND_TAGS" =~ ^[a-zA-Z0-9,]*$ ]]; then
echo "Invalid input for endtoend_tags"
exit 1
fi
- name: Run PHPUnit
# input booleans are converted to strings
if: ${{ inputs.phpunit == 'true' }}
shell: bash
env:
PHPUNIT_SUITE: ${{ inputs.phpunit_suite }}
run: |
PHPUNIT_OPTIONS="--colors=always"
[[ $(vendor/bin/phpunit --version) =~ ([0-9]+)\.([0-9]+)\.([0-9]+) ]]
MAJOR=${BASH_REMATCH[1]}
MINOR=${BASH_REMATCH[2]}
PATCH=${BASH_REMATCH[3]}
INT_VERSION=$(( $MAJOR * 10000 + $MINOR * 100 + $PATCH ))
if (( "$INT_VERSION" < 100000 )); then
# --verbose option removed in PHPUnit 10, as it's now always verbose
PHPUNIT_OPTIONS="$PHPUNIT_OPTIONS --verbose"
fi
# --display-phpunit-deprecations option added in PHPUnit 11.3.3
# deprecations will display by default in PHPUnit <= 11.3.2
if (( "$INT_VERSION" >= 110303 )); then
PHPUNIT_OPTIONS="$PHPUNIT_OPTIONS --display-phpunit-deprecations"
fi
if [[ "$PHPUNIT_SUITE" != "all" ]] && [[ "$PHPUNIT_SUITE" != "" ]]; then
PHPUNIT_OPTIONS="$PHPUNIT_OPTIONS --testsuite "$PHPUNIT_SUITE""
fi
if [[ "${{ inputs.phpunit_fail_on_warning }}" == "true" ]]; then
PHPUNIT_OPTIONS="$PHPUNIT_OPTIONS --fail-on-warning"
fi
# --exclude-filter added in PHPUnit 11
if (( "$INT_VERSION" >= 110300 )); then
# Special filtering for silverstripe/framework testsuites
if [[ "$PHPUNIT_SUITE" == "framework-orm" ]]; then
PHPUNIT_OPTIONS="$PHPUNIT_OPTIONS --filter /ORM/"
fi
if [[ "$PHPUNIT_SUITE" == "framework-core" ]]; then
PHPUNIT_OPTIONS="$PHPUNIT_OPTIONS --exclude-filter /ORM/"
fi
fi
echo "PHPUNIT_OPTIONS is $PHPUNIT_OPTIONS"
vendor/bin/phpunit $PHPUNIT_OPTIONS
echo "Passed"
- name: Setup chrome and chromedriver
if: ${{ inputs.endtoend == 'true' }}
shell: bash
run: |
echo "Default versions of google-chrome and chromedriver"
GCVR=$(google-chrome --version)
CDVR=$(chromedriver --version)
echo "$GCVR"
echo "$CDVR"
# Example version number is 101.0.4951.64
[[ "$GCVR" =~ ([0-9]+\.[0-9]+\.[0-9]+)\.[0-9]+ ]]
GCV="${BASH_REMATCH[1]}"
[[ "$CDVR" =~ ([0-9]+\.[0-9]+\.[0-9]+)\.[0-9]+ ]]
CDV="${BASH_REMATCH[1]}"
# Reinstall if a.b.c versions do not match, though allow a different .d version
if [[ "$GCV" != "$CDV" ]]; then
WGC=$(which google-chrome)
echo "google-chrome and chromedriver versions do not match, reinstalling"
sudo apt remove -y --purge google-chrome-stable
# Note that on ubuntu 20.04 and later, these will be installed via a snap. When trying to install
# chromium (or any other snaps), we get a permission error, but it doesn't seem to cause problem. The error looks like this:
# mkdir: cannot create directory '/run/user/1001': Permission denied
sudo apt install -y chromium-browser chromium-chromedriver
echo "Updated versions of chromium-browser and chromedriver"
sudo ln -s $(which chromium-browser) "$WGC"
google-chrome --version
chromedriver --version
else
echo "Default versions match, continuing"
fi
- name: Run end-to-end tests
if: ${{ inputs.endtoend == 'true' }}
shell: bash
env:
ENDTOEND_SUITE: ${{ inputs.endtoend_suite }}
ENDTOEND_CONFIG: ${{ inputs.endtoend_config }}
ENDTOEND_TAGS: ${{ inputs.endtoend_tags }}
run: |
echo "Running behat"
BEHAT_CONFIG="behat.yml"
if [[ "$ENDTOEND_CONFIG" != "" ]]; then
BEHAT_CONFIG="$ENDTOEND_CONFIG"
fi
if ! [[ -f "$BEHAT_CONFIG" ]]; then
echo "$BEHAT_CONFIG config file missing"
exit 1
fi
# Remove any sneaky attempts to put __behat* files into pull-requests
if [[ -f __behat.yml ]]; then
rm __behat.yml
fi
if [[ -f __behat.php ]]; then
rm __behat.php
fi
if [[ -f __behat_headless.yml ]]; then
rm __behat_headless.yml
fi
# Copy files from the action to temporary locations to generate the new headless behat config
cp "$BEHAT_CONFIG" __behat.yml
cp ${{ github.action_path }}/behat.php __behat.php
cp ${{ github.action_path }}/behat_headless.yml __behat_headless.yml
php __behat.php
rm __behat.php
rm __behat_headless.yml
# start chromedriver as a background process
nohup sh -c "chromedriver" > /dev/null 2>&1 &
if [[ "$ENDTOEND_SUITE" != "root" ]]; then
if [[ $ENDTOEND_TAGS != "" ]]; then
vendor/bin/behat --colors --strict --config __behat.yml "$ENDTOEND_SUITE" --tags="$ENDTOEND_TAGS"
else
vendor/bin/behat --colors --strict --config __behat.yml "$ENDTOEND_SUITE"
fi
else
if [[ $ENDTOEND_TAGS != "" ]]; then
vendor/bin/behat --colors --strict --config __behat.yml --tags="$ENDTOEND_TAGS"
else
vendor/bin/behat --colors --strict --config __behat.yml
fi
fi
echo "Passed"
- name: Run JS tests
if: ${{ inputs.js == 'true' }}
shell: bash
run: |
echo "Running JS tests"
if [[ ! -f package.json ]]; then
echo "package.json missing"
exit 1
fi
if [[ ! -f .nvmrc ]]; then
echo "Missing .nvmrc"
exit 1
fi
# Set nvmdir explicitly before installation. Default dir doesn't work for some reason.
export NVM_DIR="${HOME}/.nvm"
# Installation fails if install dir is specified but doesn't exist
if ! [[ -d "$NVM_DIR" ]]; then
echo "NVM_DIR '$NVM_DIR' doesn't exist - creating it now"
mkdir $NVM_DIR
fi
# Remove any sneaky attempts to put __install-nvm.sh into pull-requests
if [[ -f __install-nvm.sh ]]; then
rm __install-nvm.sh
fi
# Install nvm
cp ${{ github.action_path }}/install-nvm.sh __install-nvm.sh
chmod +x __install-nvm.sh
./__install-nvm.sh
if [[ $? != 0 ]]; then
echo "Error while installing nvm"
exit 1
fi
# this loads nvm into the current terminal
[[ -s "$NVM_DIR/nvm.sh" ]] && \. "$NVM_DIR/nvm.sh" --no-use
ADMIN_NPM_VERSION=
if [[ -d vendor/silverstripe/admin ]]; then
cd vendor/silverstripe/admin
nvm install
nvm use
ADMIN_NPM_VERSION=$(npm -v)
npm install -g yarn
yarn install --network-concurrency 1
cd ../../..
fi
nvm install
nvm use
if [[ $(npm -v) != $ADMIN_NPM_VERSION ]]; then
npm install -g yarn;
fi
yarn install --network-concurrency 1
if [[ $(cat package.json | jq -r '.scripts.build') != 'null' ]]; then
DIST_DIR=
if [[ -d client/dist ]]; then
DIST_DIR=client/dist
elif [[ -d dist ]]; then
DIST_DIR=dist
else
echo "No dist directory found"
exit 1
fi
echo "Deleting $DIST_DIR"
rm -rf $DIST_DIR
echo "Running yarn build"
yarn run build
echo "Running git diff"
# Add all files to ensure that any new files previously uncommitted are tracked
git add $DIST_DIR
GIT_DIFF=$(git diff --cached --name-status --relative=$DIST_DIR)
if [[ $GIT_DIFF != "" ]]; then
echo "git diff found modified files when it should not have:"
echo $GIT_DIFF
echo "sha1sum of files that are different:"
for FILEPATH in $(git diff --cached --name-only); do
if [[ -f $FILEPATH ]]; then
sha1sum $FILEPATH
fi
done
exit 1
fi
fi
if [[ $(cat package.json | jq -r '.scripts.test') != 'null' ]]; then
echo "Running yarn test"
yarn run test
fi
if [[ $(cat package.json | jq -r '.scripts.lint') != 'null' ]]; then
echo "Running yarn lint"
yarn run lint
fi
echo "Passed"
- name: "Run PHP linting"
if: ${{ inputs.phplinting == 'true' }}
shell: bash
run: |
if [[ -f vendor/bin/parallel-lint ]]; then
echo "Running parallel-lint"
vendor/bin/parallel-lint --exclude vendor --exclude .git .
fi
echo "Running PHPCS"
if ! [[ -f phpcs.xml ]] && ! [[ -f phpcs.xml.dist ]]; then
echo "Missing phpcs.xml or phpcs.xml.dist"
exit 1
fi
vendor/bin/phpcs
# phpstan is optional
if [[ -f phpstan.neon.dist ]]; then
echo "Running PHPStan"
vendor/bin/phpstan analyse
fi
echo "Passed"
- name: "Run PHP coverage"
if: ${{ inputs.phpcoverage == 'true' }}
shell: bash
run: |
echo "Running codecov"
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --import
curl -Os https://uploader.codecov.io/latest/codecov-linux
curl -Os https://uploader.codecov.io/latest/codecov-linux.SHA256SUM
curl -Os https://uploader.codecov.io/latest/codecov-linux.SHA256SUM.sig
gpg --verify codecov-linux.SHA256SUM.sig codecov-linux.SHA256SUM
shasum -a 256 -c codecov-linux.SHA256SUM
chmod +x codecov-linux
phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml
./codecov-linux -f coverage.xml;
echo "coverage.xml generated and uploaded to codecov"
- name: "Run documentation linting"
if: ${{ inputs.doclinting == 'true' }}
shell: bash
run: |
echo "Running documentation linting"
if [[ ! -f vendor/silverstripe/documentation-lint/.nvmrc ]]; then
echo "File vendor/silverstripe/documentation-lint/.nvmrc is missing. Check dependencies."
exit 1
fi
# Remove any sneaky attempts to put __install-nvm.sh into pull-requests
if [[ -f __install-nvm.sh ]]; then
rm __install-nvm.sh
fi
# Install nvm
cp ${{ github.action_path }}/install-nvm.sh __install-nvm.sh
chmod +x __install-nvm.sh
./__install-nvm.sh
if [[ $? != 0 ]]; then
echo "Error while installing nvm"
exit 1
fi
export NVM_DIR="$HOME/.nvm"
# this loads nvm into the current terminal
[[ -s "$NVM_DIR/nvm.sh" ]] && \. "$NVM_DIR/nvm.sh"
# Swap to correct version and make sure yarn is installed
NPM_VERSION=$(cat vendor/silverstripe/documentation-lint/.nvmrc)
nvm install $NPM_VERSION && nvm use $NPM_VERSION
npm install --global yarn
# Run the linting script
vendor/bin/doclint
echo "Passed"
- name: Delete temporary files
shell: bash
if: always()
run: |
if [[ -f __install-nvm.sh ]]; then
rm __install-nvm.sh
fi