-
Notifications
You must be signed in to change notification settings - Fork 6
327 lines (297 loc) · 11.4 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
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
name: CI
on:
pull_request:
branches: [ develop, main ]
workflow_dispatch:
env:
TARGET_PHP: 8.1
TARGET_MYSQL: 8
DB_HOST: mysql-8
DB_PORT: 3306
DB_USERNAME: cmfive_test
DB_PASSWORD: cmfive_test
DB_DATABASE: cmfive_test
PLAYWRIGHT_MODULES: "admin channel form tag report task timelog"
LANG: en_AU.UTF-8
jobs:
# Lint
php-codesniffer:
name: PHP CS
runs-on: ubuntu-22.04
strategy:
matrix:
php_version: [7.4, 8.0, 8.1, 8.3]
steps:
- name: Get phpcs
run: wget https://raw.githubusercontent.com/2pisoftware/cmfive-boilerplate/master/phpcs.xml
- name: Codesniffer
uses: pipeline-components/[email protected]
with:
options: -s -p --colors --extensions=php --runtime-set testVersion ${{matrix.php_version}}
# Test
run_test:
# Checkout Boilerplate
name: Unit/Acceptance tests
runs-on: ubuntu-22.04
needs: [ php-codesniffer]
strategy:
matrix:
node_version: [18, 20]
steps:
## NOTE: Current branch of cmfive-core will be used on the cmfive container
## See the `CORE_BRANCH` environment variable in the `Start containers` step
# Checkout current commit
- name: Checkout
uses: actions/checkout@v4
with:
path: core
# Set Boilerplate variables by determing which image and branch to use
- name: Set Boilerplate Vars
id: boilerplate_vars
run: |
if [ "${{ github.ref }}" == "refs/heads/main" ] || [ "${{ github.event.pull_request.base.ref }}" == "main" ]; then
# Base branch or current branch of core is main
echo "BOILERPLATE_IMAGE=ghcr.io/2pisoftware/cmfive:latest" >> $GITHUB_ENV
echo "BOILERPLATE_BRANCH=master" >> $GITHUB_ENV
else
# Base branch or current branch of core is another branch
echo "BOILERPLATE_IMAGE=ghcr.io/2pisoftware/cmfive:develop" >> $GITHUB_ENV
echo "BOILERPLATE_BRANCH=develop" >> $GITHUB_ENV
fi
# Checkout the boilerplate
- name: Checkout Boilerplate
uses: actions/checkout@v4
with:
repository: '2pisoftware/cmfive-boilerplate'
ref: ${{ env.BOILERPLATE_BRANCH }}
path: boilerplate
# Pre-requisites Prepare Cmfive Environment
- name: Pull Docker images
run: |
docker pull $BOILERPLATE_IMAGE
docker pull mysql:8
- name: Start containers
env:
CORE_BRANCH: "${{ github.event.pull_request.head.ref || github.ref_name }}"
run: |
# Link system dir
cd boilerplate
ln -s ../core/system system
# Change owner
sudo chown -R 1000:1000 .
# Create docker network
echo "Setting up docker"
docker network create cmfive
# Create MySQL 8 container
echo "Starting MySQL 8"
docker run --name mysql-8 -d -p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=root \
-e MYSQL_DATABASE=$DB_DATABASE \
-e MYSQL_USER=$DB_USERNAME \
-e MYSQL_PASSWORD=$DB_PASSWORD \
--network=cmfive \
mysql:8
# Wait for MySQL to start
echo "Waiting for MySQL to start"
time=0
while ! docker exec mysql-8 mysqladmin ping -u$DB_USERNAME -p$DB_PASSWORD --silent; do
sleep 1
time=$((time+1))
if [ $time -gt 60 ]; then
echo "MySQL failed to start"
exit 1
fi
done
# Get .composer dir ready
if [ ! -d /tmp/.composer ]; then
mkdir /tmp/.composer
fi
chmod -R ugo=rwX /tmp/.composer
# Create Cmfive container
echo "Starting Cmfive"
docker run --name cmfive -d -p 3000:80 \
-v /tmp/.composer:/home/cmfive/.composer/:rw \
-v ${{ github.workspace }}/boilerplate/.codepipeline/test_agent/configs/test_agent-config.php:/var/www/html/config.php:rw \
-v ${{ github.workspace }}/boilerplate/test:/var/www/html/test:rw \
-v ${{ github.workspace }}/boilerplate/storage:/var/www/html/storage:rw \
-v ${{ github.workspace }}/core/system:/var/www/html/system:rw \
-e DB_HOST=mysql-8 \
-e DB_USERNAME=$DB_USERNAME \
-e DB_PASSWORD=$DB_PASSWORD \
-e DB_DATABASE=$DB_DATABASE \
-e ENVIRONMENT=development \
--network=cmfive \
$BOILERPLATE_IMAGE
# Note: system is mounted to a volume to avoid conflicts with the symlink
# Wait for cmfive healthcheck to be healthy
echo "Waiting for Cmfive to start"
time=0
while [ "$(docker inspect -f '{{.State.Health.Status}}' cmfive)" != "healthy" ]; do
sleep 1
time=$((time+1))
if [ $time -gt 60 ]; then
echo "Cmfive failed to start"
exit 1
fi
done
- name: Get source code details
if: ${{ failure() }} || ${{ success() }}
run: |
echo ">> CONTAINER LABELS (BOILERPLATE) <<"
echo "===================================="
docker inspect --format='{{range $key, $value := .Config.Labels}}{{$key}}={{$value}}{{println}}{{end}}' cmfive
echo ""
echo ""
echo ">> CORE COMMIT DETAILS <<"
echo "========================="
echo "VENDOR DIRECTORY: (should be unused)"
docker exec -u cmfive cmfive sh -c "cd composer/vendor/2pisoftware/cmfive-core && git log -1 --pretty=format:"CORE_HASH=\"%H\"%nCORE_COMMIT_MSG=\"%s\"%nCORE_REF=\"%D\"""
echo ""
echo "MOUNTED CORE: (should be used, this is mounted to /system)"
pushd core
git log -1 --pretty=format:"CORE_HASH=\"%H\"%nCORE_COMMIT_MSG=\"%s\"%nCORE_REF=\"%D\""
- name: Compile the theme
run: |
# Copy the theme from the docker container
docker cp cmfive:/var/www/html/system/templates/base /tmp/cmfive-theme
cd /tmp/cmfive-theme
npm ci || npm install
npm run production
# Copy the compiled theme back to the docker container
docker cp /tmp/cmfive-theme/. cmfive:/var/www/html/system/templates/base
# Pre-requisites Prepare Cmfive Environment
- name: Setup cmfive Test Environment
run: |
docker exec -t cmfive sh -c "chmod -R ugo=rwX /var/www/html*"
sudo locale-gen en_AU.UTF-8
sudo update-locale en_AU.UTF-8
LANG=en_AU.UTF-8
LC_ALL=en_AU.UTF-8
echo "Test Execution context:"
echo "Runner locale info"
date
locale
echo "Web host timezone"
docker exec -t cmfive sh -c "date"
- name: Inject configs into cmfive Test Environment
run: |
echo "Inheriting test_agent config from PIPELINE"
# Define extra config
CONFIG='
Config::append(\"tests\", [\"testrunner\" => \"ENABLED\"]);
'
# Write extra config to cmfive container
docker exec -t cmfive sh -c "echo \"$CONFIG\" >> /var/www/html/config.php"
- name: Install dev tools
env:
CONTAINER: cmfive
run: |
if [ -f ./boilerplate/.codepipeline/docker/install_dev_tools.sh ]; then
./boilerplate/.codepipeline/docker/install_dev_tools.sh
else
echo "⚠️ WARNING: could not find dev tools in boilerplate"
fi
- name: Prepare cmfive Test DB
run: |
docker exec -t cmfive sh -c "DB_HOST=mysql-8 DB_USERNAME=root DB_PASSWORD=root DB_DATABASE=$DB_DATABASE DB_PORT=3306 php cmfive.php testDB setup; exit \$?";
# Build new layout
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node_version }}
# Run Unit Tests
- name: "Run unit tests"
run: |
docker exec -u root cmfive chmod -R ugo=rwX /var/www/html/test/
docker exec -u cmfive cmfive sh -c "DB_HOST=mysql-8 DB_USERNAME=$DB_USERNAME DB_PASSWORD=$DB_PASSWORD DB_DATABASE=$DB_DATABASE DB_PORT=3306 php cmfive.php tests unit all; exit \$?"
if [ $? -gt 0 ]; then
echo "Admin module tests failed"
fi
# Setup playwright
- name: Setup Playwright
run: |
echo "Installing Playwright"
cd boilerplate/test/playwright
npm ci
npx playwright install --with-deps
- name: "Run admin module tests"
run: |
docker exec -u root cmfive sh -c "chmod ugo=rwX -R /var/www/html/system/modules/admin/install/migrations/"
cd boilerplate/test/playwright
npm run build
npm run test --module="admin" --reporter="github"
if [ $? -gt 0 ]; then
echo "Admin module tests failed"
fi
- name: "Run channel module tests"
run: |
cd boilerplate/test/playwright
npm run build
npm run test --module="channel" --reporter="github"
if [ $? -gt 0 ]; then
echo "Channel module tests failed"
fi
- name: "Run form module tests"
run: |
cd boilerplate/test/playwright
npm run build
npm run test --module="form" --reporter="github"
if [ $? -gt 0 ]; then
echo "Form module tests failed"
fi
- name: "Run report module tests"
run: |
cd boilerplate/test/playwright
npm run build
npm run test --module="report" --reporter="github"
if [ $? -gt 0 ]; then
echo "Report module tests failed"
fi
- name: "Run tag module tests"
run: |
cd boilerplate/test/playwright
npm run build
npm run test --module="tag" --reporter="github"
if [ $? -gt 0 ]; then
echo "Tag module tests failed"
fi
- name: "Run task module tests"
run: |
cd boilerplate/test/playwright
npm run build
npm run test --module="task" --reporter="github"
if [ $? -gt 0 ]; then
echo "Task module tests failed"
fi
- name: "Run timelog module tests"
run: |
cd boilerplate/test/playwright
npm run build
npm run test --module="timelog" --reporter="github"
if [ $? -gt 0 ]; then
echo "Timelog module tests failed"
fi
- name: Get container logs
if: ${{ failure() }} || ${{ success() }}
run: |
docker logs cmfive | sudo tee cmfive_container.log
- name: Stop containers
# the containers should be stopped regardless of
# the test result
if: always()
run: |
docker rm cmfive -f
docker rm mysql-8 -f
docker network rm cmfive
# Store Test Results
- name: Test results
if: ${{ failure() }} || ${{ success() }}
uses: actions/upload-artifact@v4
with:
name: test-output-${{matrix.node_version}}
path: |
boilerplate/test/Codeception/tests/_output/
boilerplate/storage/log/
boilerplate/test/playwright/test-results/
boilerplate/test/playwright/playwright-report/
cmfive_container.log
retention-days: 5