forked from naala89/apiopenstudio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
320 lines (303 loc) · 11.2 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
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
# GitLab pipelines definition.
#
# @package ApiOpenStudio
# @license This Source Code Form is subject to the terms of the ApiOpenStudio Public License.
# If a copy of the license was not distributed with this file,
# You can obtain one at https://www.apiopenstudio.com/license/.
# @author john89 (https://gitlab.com/john89)
# @copyright 2020-2030 Naala Pty Ltd
# @link https://www.apiopenstudio.com
#cache:
# key: "$CI_COMMIT_REF_SLUG"
# paths:
# - vendor/
# - .composer/
# - composer.lock
##################################
## GLOBAL VARIABLES
##################################
variables:
PHPDOC_OUTPUT: "/public/phpdoc"
PHPDOC_CONFIG_FILE: ""
PHPDOC_TITLE: "ApiOpenStudio PHPDoc"
PHPDOC_VERBOSITY: ""
PHPDOC_TEMPLATE: ""
PHPDOC_INCLUDE_HIDDEN: "false"
PHPDOC_IGNORE_SYMLINKS: "false"
PHPDOC_MARKERS: ""
PHPDOC_OPTIONS: ""
PHPDOC_PROJECT_ROOT: "/"
CSS_BOOTSWATCH: "spacelab"
CSS_PRISM: "prism"
MENU_LOGO: "/img/api_open_studio_logo_name_colour.png"
##################################
## WORKFLOW
##################################
workflow:
rules:
- if: '$CI_PROJECT_NAMESPACE != "apiopenstudio" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop"'
when: never
- if: '$CI_PROJECT_NAMESPACE != "apiopenstudio" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
when: never
- when: always
##################################
## RULES
##################################
.merge_request_to_apiopenstudio_develop:
rules:
- if: '$CI_PROJECT_NAMESPACE == "apiopenstudio" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop"'
when: always
.commit_to_apiopenstudio_develop:
rules:
- if: '$CI_PROJECT_NAMESPACE == "apiopenstudio" && $CI_COMMIT_BRANCH == "develop" && $CI_COMMIT_TAG == null'
when: always
.merge_request_to_apiopenstudio_master:
rules:
- if: '$CI_PROJECT_NAMESPACE == "apiopenstudio" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
when: always
.commit_to_apiopenstudio_master:
rules:
- if: '$CI_PROJECT_NAMESPACE == "apiopenstudio" && $CI_COMMIT_BRANCH == "master" && $CI_COMMIT_TAG == null'
when: always
.tag_to_apiopenstudio_master:
rules:
- if: '$CI_PROJECT_NAMESPACE == "apiopenstudio" && $CI_COMMIT_BRANCH == "master" && $CI_COMMIT_TAG != null'
when: always
##################################
## STAGES
##################################
stages:
- test
- deploy_phpdoc
##################################
## TESTS
##################################
test-7.4:
stage: test
rules:
- !reference [.merge_request_to_apiopenstudio_develop, rules]
- !reference [.merge_request_to_apiopenstudio_master, rules]
image: naala89/apiopenstudio-nginx-php-7.4:1.0.1
services:
- mariadb:latest
variables:
MYSQL_ROOT_PASSWORD: apiopenstudio
MYSQL_USERNAME: apiopenstudio
MYSQL_PASSWORD: apiopenstudio
artifacts:
when: on_failure
paths:
- tests/_output/
- log/
script:
- echo "Setting up for tests."
- eval $(ssh-agent -s)
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
# set ApiOpenStudio test .env and settings.yml
- cp tests/ci.env .env
- cp tests/ci.settings.yml settings.yml
- CI_ESCAPED_PROJECT_DIR="$(echo "$CI_PROJECT_DIR" | sed -e 's/[\/]/\\&/g')"
- sed -i 's/CI_PROJECT_DIR/'"${CI_ESCAPED_PROJECT_DIR}"'/g' settings.yml
- >
if [ -z "$ADMIN_NAME" ]; then
eval export ADMIN_NAME="admin"
fi
- >
if [ -z "$ADMIN_PASS" ]; then
eval export ADMIN_PASS="secret"
fi
- >
if [ -z "$ADMIN_EMAIL" ]; then
eval export ADMIN_EMAIL="[email protected]"
fi
- composer install
# Linting
- echo "Linting the codebase."
- ./vendor/bin/phpcs --standard=PSR12 --report-file=tests/_output/phpcs.txt includes/ public/*.php tests/api/ tests/_support/Helper/ tests/runner_generate_db.php
# Unit tests
- echo "Running api unit tests."
- mkdir log
- touch log/api.log
- touch log/db.log
- chmod -R 777 log
- ./vendor/bin/codecept run --env ci unit
# Install MySQL
- echo "Setting up the DB for functional tests."
- mysql --version
- php tests/runner_generate_db.php
# Create JWT token keys
- ssh-keygen -t rsa -b 4096 -P "" -m PEM -f jwt.key
- openssl rsa -in jwt.key -pubout -outform PEM -out jwt.key.pub
- chmod 777 jwt.key.pub jwt.key
# Run functional tests
- echo "Running api functional tests."
- cp -Rp ./* /www/
- ./vendor/bin/codecept build
- ./vendor/bin/codecept run --env ci api
test-8.0:
stage: test
rules:
- !reference [.merge_request_to_apiopenstudio_develop, rules]
- !reference [.merge_request_to_apiopenstudio_master, rules]
image: naala89/apiopenstudio-nginx-php-8.0:1.0.1
services:
- mariadb:latest
variables:
MYSQL_ROOT_PASSWORD: apiopenstudio
MYSQL_USERNAME: apiopenstudio
MYSQL_PASSWORD: apiopenstudio
artifacts:
when: on_failure
paths:
- tests/_output/
- log/
script:
- echo "Setting up for tests."
- eval $(ssh-agent -s)
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
# set ApiOpenStudio test .env and settings.yml
- cp tests/ci.env .env
- cp tests/ci.settings.yml settings.yml
- CI_ESCAPED_PROJECT_DIR="$(echo "$CI_PROJECT_DIR" | sed -e 's/[\/]/\\&/g')"
- sed -i 's/CI_PROJECT_DIR/'"${CI_ESCAPED_PROJECT_DIR}"'/g' settings.yml
- >
if [ -z "$ADMIN_NAME" ]; then
eval export ADMIN_NAME="admin"
fi
- >
if [ -z "$ADMIN_PASS" ]; then
eval export ADMIN_PASS="secret"
fi
- >
if [ -z "$ADMIN_EMAIL" ]; then
eval export ADMIN_EMAIL="[email protected]"
fi
- composer install
# Linting
- echo "Linting the codebase."
- ./vendor/bin/phpcs --standard=PSR12 --report-file=tests/_output/phpcs.txt includes/ public/*.php tests/api/ tests/_support/Helper/ tests/runner_generate_db.php
# Unit tests
- echo "Running api unit tests."
- mkdir log
- touch log/api.log
- touch log/db.log
- chmod -R 777 log
- ./vendor/bin/codecept run --env ci unit
# Install MySQL
- echo "Setting up the DB for functional tests."
- mysql --version
- php tests/runner_generate_db.php
# Create JWT token keys
- ssh-keygen -t rsa -b 4096 -P "" -m PEM -f jwt.key
- openssl rsa -in jwt.key -pubout -outform PEM -out jwt.key.pub
- chmod 777 jwt.key.pub jwt.key
# Run functional tests
- echo "Running api functional tests."
- cp -Rp ./* /www/
- ./vendor/bin/codecept build
- ./vendor/bin/codecept run --env ci api
##################################
## PHPDOC
##################################
phpdoc-dev:
stage: deploy_phpdoc
rules:
- !reference [.commit_to_apiopenstudio_develop, rules]
image:
name: naala89/phpdoc-rsync:3.1
entrypoint: [ "" ]
script:
- echo "Compile and deploy the phpdoc to dev."
- eval $(ssh-agent -s)
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- ssh-keyscan "$DEV_PHPDOC_URL" >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
# Define verbosity
- if [ ! -z "$PHPDOC_VERBOSITY" ]; then export PHPDOC_OPTIONS="-$PHPDOC_VERBOSITY $PHPDOC_OPTIONS"; fi
# Define template
- if [ ! -z "$PHPDOC_TEMPLATE" ]; then export PHPDOC_OPTIONS="--template=$PHPDOC_TEMPLATE $PHPDOC_OPTIONS"; fi
# Include config file
- if [ ! -z "$PHPDOC_CONFIG_FILE" ]; then export PHPDOC_OPTIONS="--config=$CI_PROJECT_DIR$PHPDOC_CONFIG_FILE $PHPDOC_OPTIONS"; fi
# Include hidden files
- if [ ! "$PHPDOC_INCLUDE_HIDDEN" = "true" ]; then export PHPDOC_OPTIONS="--hidden $PHPDOC_OPTIONS"; fi
# Include if ignore symlinks
- if [ ! "$PHPDOC_IGNORE_SYMLINKS" = "true" ]; then export PHPDOC_OPTIONS="--ignore-symlinks $PHPDOC_OPTIONS"; fi
# Include markers
- if [ ! "$PHPDOC_MARKERS" = "true" ]; then export PHPDOC_OPTIONS="--markers=$PHPDOC_MARKERS $PHPDOC_OPTIONS"; fi
- /opt/phpdoc/bin/phpdoc -d ${CI_PROJECT_DIR}${PHPDOC_PROJECT_ROOT} -t ${CI_PROJECT_DIR}${PHPDOC_OUTPUT} --title="$PHPDOC_TITLE" ${PHPDOC_OPTIONS}
- rsync -rvI --delete --exclude=".*" "$CI_PROJECT_DIR/public/phpdoc/" "$DEV_DEPLOYER"@"$DEV_PHPDOC_URL":"$DEV_PHPDOC_PATH/"
- ssh "$DEV_DEPLOYER"@"$DEV_PHPDOC_URL" "sudo chown -R $DEV_DEPLOYER:www-data $DEV_PHPDOC_PATH/*"
phpdoc-prod:
stage: deploy_phpdoc
rules:
- !reference [.commit_to_apiopenstudio_master, rules]
image:
name: naala89/phpdoc-rsync:3.1
entrypoint: [ "" ]
script:
- echo "Compile and deploy the phpdoc to prod."
- eval $(ssh-agent -s)
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- ssh-keyscan "$PROD_PHPDOC_URL" >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
# Define verbosity
- if [ ! -z "$PHPDOC_VERBOSITY" ]; then export PHPDOC_OPTIONS="-$PHPDOC_VERBOSITY $PHPDOC_OPTIONS"; fi
# Define template
- if [ ! -z "$PHPDOC_TEMPLATE" ]; then export PHPDOC_OPTIONS="--template=$PHPDOC_TEMPLATE $PHPDOC_OPTIONS"; fi
# Include config file
- if [ ! -z "$PHPDOC_CONFIG_FILE" ]; then export PHPDOC_OPTIONS="--config=$CI_PROJECT_DIR$PHPDOC_CONFIG_FILE $PHPDOC_OPTIONS"; fi
# Include hidden files
- if [ ! "$PHPDOC_INCLUDE_HIDDEN" = "true" ]; then export PHPDOC_OPTIONS="--hidden $PHPDOC_OPTIONS"; fi
# Include if ignore symlinks
- if [ ! "$PHPDOC_IGNORE_SYMLINKS" = "true" ]; then export PHPDOC_OPTIONS="--ignore-symlinks $PHPDOC_OPTIONS"; fi
# Include markers
- if [ ! "$PHPDOC_MARKERS" = "true" ]; then export PHPDOC_OPTIONS="--markers=$PHPDOC_MARKERS $PHPDOC_OPTIONS"; fi
- /opt/phpdoc/bin/phpdoc -d "$CI_PROJECT_DIR$PHPDOC_PROJECT_ROOT" -t "$CI_PROJECT_DIR$PHPDOC_OUTPUT" --title="$PHPDOC_TITLE" ${PHPDOC_OPTIONS}
- rsync -rvI --delete --exclude=".*" "$CI_PROJECT_DIR/public/phpdoc/" "$PROD_DEPLOYER"@"$PROD_PHPDOC_URL":"$PROD_PHPDOC_PATH/"
- ssh "$PROD_DEPLOYER"@"$PROD_PHPDOC_URL" "sudo touch $PROD_PHPDOC_PATH/sitemap.xml"
- ssh "$PROD_DEPLOYER"@"$PROD_PHPDOC_URL" "sudo chown -R $PROD_DEPLOYER:www-data $PROD_PHPDOC_PATH/*"
- ssh "$PROD_DEPLOYER"@"$PROD_PHPDOC_URL" "sudo chmod 664 $PROD_PHPDOC_PATH/sitemap.xml"
- ssh "$PROD_DEPLOYER"@"$PROD_PHPDOC_URL" "php $SITEMAP_GENERATOR file=$PROD_PHPDOC_PATH/sitemap.xml site=https://$PROD_PHPDOC_URL"
##################################
## Production Docker
##################################
#prod-docker-develop:
# stage: prod_docker
# rules:
# - !reference [.commit_to_apiopenstudio_develop, rules]
# variables:
# BRANCH: develop
# trigger:
# project: apiopenstudio/docker_images/apiopenstudio_docker_prod
# branch: master
# strategy: depend
#
#prod-docker-master:
# stage: prod_docker
# rules:
# - !reference [.commit_to_apiopenstudio_master, rules]
# variables:
# BRANCH: master
# trigger:
# project: apiopenstudio/docker_images/apiopenstudio_docker_prod
# branch: master
# strategy: depend
#
#prod-docker-tag:
# stage: prod_docker
# rules:
# - !reference [.tag_to_apiopenstudio_master, rules]
# variables:
# TAG: $CI_COMMIT_TAG
# trigger:
# project: apiopenstudio/docker_images/apiopenstudio_docker_prod
# branch: master
# strategy: depend