forked from GibbonEdu/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
139 lines (120 loc) · 4.16 KB
/
.gitlab-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
.tests:
stage: test
services:
- mariadb:latest
variables:
# supporess interative prompt from debian-based OS
DEBIAN_FRONTEND: noninteractive
# variables required for Gibbon to test with
TEST_ENV: codeception
GIT_SUBMODULE_STRATEGY: recursive
ABSOLUTE_URL: http://127.0.0.1:8888
DB_HOST: mariadb
DB_NAME: gibbon_test
DB_USERNAME: gibbon_test
DB_PASSWORD: gibbon_password
# variables to setup mariadb docker
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
MYSQL_DATABASE: gibbon_test
MYSQL_USER: gibbon_test
MYSQL_PASSWORD: gibbon_password
tags:
- git-annex
before_script:
# install apt packages
- apt-get update -qy
- apt-get install -qy mariadb-client gettext git libzip-dev libgd-dev libpng-dev locales unzip zip zlib1g-dev
# install php extensions
- docker-php-ext-install gd gettext pdo_mysql zip > /dev/null
# properly setup php
- cp -pdf /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini
# install composer
- |
# install composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (getenv('COMPOSER_CHECKSUM') === false) exit('No COMPOSER_CHECKSUM. Installer verification skipped.' . PHP_EOL); if (hash_file('SHA384', 'composer-setup.php') === getenv('COMPOSER_CHECKSUM')) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); exit(1); } echo PHP_EOL;"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
php -r "unlink('composer-setup.php');"
# create test log folder
- |
[ -d ./tests/log ] || mkdir ./tests/log
# run test server for codeception tests
- |
# run test server for codeception tests
php --server 127.0.0.1:8888 \
--docroot $CI_PROJECT_DIR \
--define display_startup_errors=1 \
--define display_errors=1 \
--define error_reporting=E_ALL \
>/dev/null 2>./tests/log/server_log &
# install dependencies for test
- composer install --prefer-dist --ansi --no-interaction --no-progress
# setup system locale for test
- |
# setup system locale for test
cat <<- EOF | tee -a /etc/locale.gen >/dev/null
es_ES.UTF-8 UTF-8
fr_FR.UTF-8 UTF-8
zh_TW.UTF-8 UTF-8
EOF
locale-gen
# configure php cli to only report severe errors
- |
# improve php cli error reporting manner
export PHP_D=$(php --ini | grep 'Scan for additional .ini files in' | tr -s ' ' '\n' | tail -n1)
cat <<- EOF | tee $PHP_D/custom-error-reporting.ini
[PHP]
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
EOF
script:
- composer test
after_script:
- |
# dump database, if test failed
if [ "$CI_JOB_STATUS" = "failed" ]; then
[ -d ./tests/log ] || mkdir ./tests/log
mysqldump \
--protocol=tcp \
--host=$DB_HOST \
--user=$DB_USERNAME \
--password=$DB_PASSWORD \
$DB_NAME > ./tests/log/$DB_NAME.sql
else
echo "skipped"
fi
- |
# extract php.ini information if test failed
if [ "$CI_JOB_STATUS" = "failed" ]; then
# create folder to store configs
echo "Create ./tests/configs"
[ -d ./tests/configs ] || mkdir ./tests/configs
# get php --ini output
echo "Gather php --ini to php--ini.txt"
php --ini | tee ./tests/configs/php--ini.txt
# get the main php ini config
export PHP_INI=$(php --ini | grep 'Loaded Configuration File' | tr -s ' ' '\n' | tail -n1)
echo "Backup $PHP_INI"
cp -pdf $PHP_INI ./tests/configs/.
# get all files in the php.d folder
export PHP_D=$(php --ini | grep 'Scan for additional .ini files in' | tr -s ' ' '\n' | tail -n1)
echo "Backup $PHP_D"
cp -Rpdf $PHP_D ./tests/configs/.
else
echo "skipped"
fi
# store test logs when fail.
artifacts:
paths:
- tests/log
- tests/configs
when: on_failure
expire_in: 1 week
php:7.3:
image: php:7.3
extends: .tests
php:7.4:
image: php:7.4
extends: .tests
php:8.0:
image: php:8.0
extends: .tests