-
Notifications
You must be signed in to change notification settings - Fork 0
327 lines (279 loc) · 10.3 KB
/
Copy pathci.yml
File metadata and controls
327 lines (279 loc) · 10.3 KB
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: Continuous Integration
on:
pull_request:
push:
branches:
- master
workflow_dispatch:
permissions:
contents: read
pull-requests: read
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
changes:
name: Change classification
uses: ./.github/workflows/change-classification.yml
php:
name: PHP quality and tests
runs-on: ubuntu-latest
needs:
- changes
- frontend
if: >-
github.event_name == 'workflow_dispatch' ||
needs.changes.outputs.backend == 'true' ||
needs.changes.outputs.automation == 'true'
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.4"
tools: composer
extensions: intl, mbstring, pdo_sqlite, sqlite3
- name: Cache Composer dependencies
uses: actions/cache@v6
with:
path: ~/.cache/composer/files
key: ${{ runner.os }}-php-8.4-${{ hashFiles('composer.lock') }}
restore-keys: ${{ runner.os }}-php-8.4-
- name: Install PHP dependencies
run: composer install --no-interaction --no-progress --prefer-dist
- name: Download frontend assets
uses: actions/download-artifact@v8
with:
name: frontend-build
path: public/build
- name: Check PHP formatting
run: |
vendor/bin/pint
git diff --exit-code
- name: Run PHP tests
env:
APP_KEY: base64:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
run: php artisan test
frontend:
name: Frontend build
runs-on: ubuntu-latest
needs: changes
if: >-
github.event_name == 'workflow_dispatch' ||
needs.changes.outputs.backend == 'true' ||
needs.changes.outputs.frontend == 'true' ||
needs.changes.outputs.automation == 'true'
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.4"
tools: composer
- name: Install PHP dependencies
run: composer install --no-interaction --no-progress --prefer-dist
- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version: "24"
cache: npm
- name: Install Node dependencies
run: npm ci --no-audit --fund=false
- name: Build frontend assets
run: npm run build
- name: Upload frontend assets
uses: actions/upload-artifact@v7
with:
name: frontend-build
path: public/build
mariadb:
name: MariaDB integration tests
runs-on: ubuntu-latest
needs:
- changes
- frontend
if: >-
github.event_name == 'workflow_dispatch' ||
needs.changes.outputs.backend == 'true' ||
needs.changes.outputs.automation == 'true'
services:
db:
image: mariadb:11
env:
MARIADB_DATABASE: versiontracker
MARIADB_USER: versiontracker
MARIADB_PASSWORD: versiontracker
MARIADB_ROOT_PASSWORD: root
options: >-
--health-cmd="healthcheck.sh --connect --innodb_initialized"
--health-interval=10s
--health-timeout=5s
--health-retries=10
ports:
- 3306:3306
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.4"
tools: composer
extensions: intl, mbstring, pdo_mysql
- name: Install PHP dependencies
run: composer install --no-interaction --no-progress --prefer-dist
- name: Download frontend assets
uses: actions/download-artifact@v8
with:
name: frontend-build
path: public/build
- name: Run PHP tests with MariaDB
env:
APP_KEY: base64:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
DB_CONNECTION: mariadb
DB_HOST: 127.0.0.1
DB_PORT: 3306
DB_DATABASE: versiontracker
DB_USERNAME: versiontracker
DB_PASSWORD: versiontracker
run: php artisan test
container:
name: Container integration test
runs-on: ubuntu-latest
needs: changes
if: >-
github.event_name == 'workflow_dispatch' ||
needs.changes.outputs.infrastructure == 'true' ||
needs.changes.outputs.automation == 'true'
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build application image
uses: docker/build-push-action@v6
with:
context: .
load: true
tags: ghcr.io/soerennb/version-tracker:test
cache-from: type=gha,scope=container
cache-to: type=gha,mode=max,scope=container
- name: Scan application image
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25
with:
image-ref: ghcr.io/soerennb/version-tracker:test
format: table
exit-code: "1"
ignore-unfixed: true
severity: CRITICAL,HIGH
vuln-type: os,library
- name: Prepare Compose environment
run: |
cp .env.docker.example .env.docker
sed -i 's/^VERSION=$/VERSION=test/' .env.docker
sed -i 's/^DEPLOYMENT_MODE=$/DEPLOYMENT_MODE=proxy/' .env.docker
sed -i 's/^APP_KEY=$/APP_KEY=base64:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=/' .env.docker
sed -i 's/^DB_PASSWORD=$/DB_PASSWORD=versiontracker/' .env.docker
sed -i 's/^DB_ROOT_PASSWORD=$/DB_ROOT_PASSWORD=root/' .env.docker
docker compose --env-file .env.docker -f compose.yml -f compose.proxy.yml config --quiet
- name: Initialize and check application
run: |
docker compose --env-file .env.docker -f compose.yml -f compose.proxy.yml up --detach db
docker compose --env-file .env.docker -f compose.yml -f compose.proxy.yml run --rm app php artisan migrate --force
docker compose --env-file .env.docker -f compose.yml -f compose.proxy.yml up --detach app
for attempt in {1..30}; do
if curl --fail --silent http://127.0.0.1:8080/up; then
exit 0
fi
sleep 2
done
docker compose --env-file .env.docker -f compose.yml -f compose.proxy.yml logs
exit 1
- name: Back up and restore application data
run: |
backup_directory="$(./install.sh backup)"
test -s "$backup_directory/database.sql"
test -s "$backup_directory/storage.tar.gz"
test "$(stat --format=%a "$backup_directory/environment.backup")" = 600
docker compose --env-file .env.docker -f compose.yml -f compose.proxy.yml down --volumes --remove-orphans
docker compose --env-file .env.docker -f compose.yml -f compose.proxy.yml up --detach db
for attempt in {1..30}; do
if docker compose --env-file .env.docker -f compose.yml -f compose.proxy.yml exec --no-TTY db healthcheck.sh --connect --innodb_initialized; then
break
fi
sleep 2
done
docker compose --env-file .env.docker -f compose.yml -f compose.proxy.yml exec --no-TTY db sh -c 'exec mariadb -uroot -p"$MARIADB_ROOT_PASSWORD" "$MARIADB_DATABASE"' < "$backup_directory/database.sql"
docker compose --env-file .env.docker -f compose.yml -f compose.proxy.yml exec --no-TTY db sh -c 'mariadb -uroot -p"$MARIADB_ROOT_PASSWORD" "$MARIADB_DATABASE" --skip-column-names --execute="SELECT COUNT(*) FROM migrations"' | grep --extended-regexp '^[1-9][0-9]*$'
docker compose --env-file .env.docker -f compose.yml -f compose.proxy.yml run --rm app sh -c 'tar -xzf - -C /var/www/html' < "$backup_directory/storage.tar.gz"
docker compose --env-file .env.docker -f compose.yml -f compose.proxy.yml up --detach app
for attempt in {1..30}; do
if curl --fail --silent http://127.0.0.1:8080/up; then
exit 0
fi
sleep 2
done
docker compose --env-file .env.docker -f compose.yml -f compose.proxy.yml logs
exit 1
- name: Clean up containers
if: always()
run: |
if [[ -f .env.docker ]]; then
docker compose --env-file .env.docker -f compose.yml -f compose.proxy.yml down --volumes --remove-orphans
fi
compose:
name: Compose configuration
runs-on: ubuntu-latest
needs: changes
if: >-
github.event_name == 'workflow_dispatch' ||
needs.changes.outputs.infrastructure == 'true' ||
needs.changes.outputs.automation == 'true'
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Validate deployment configurations
run: |
cp .env.docker.example .env.docker
sed -i 's/^VERSION=$/VERSION=v0.0.0/' .env.docker
docker compose --env-file .env.docker -f compose.yml -f compose.proxy.yml config --quiet
docker compose --env-file .env.docker -f compose.yml -f compose.caddy.yml config --quiet
- name: Validate Caddyfile
run: docker run --rm --env CADDY_DOMAIN=example.invalid --env CADDY_EMAIL=ci@example.invalid --volume "$GITHUB_WORKSPACE/Caddyfile:/etc/caddy/Caddyfile:ro" caddy:2.11.4 caddy validate --config /etc/caddy/Caddyfile --adapter caddyfile
shell:
name: Installer script
runs-on: ubuntu-latest
needs: changes
if: >-
github.event_name == 'workflow_dispatch' ||
needs.changes.outputs.infrastructure == 'true' ||
needs.changes.outputs.automation == 'true'
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Install ShellCheck
run: sudo apt-get update && sudo apt-get install --yes shellcheck
- name: Lint installer
run: |
test -x install.sh
shellcheck install.sh
gate:
name: CI gate
runs-on: ubuntu-latest
if: always()
needs:
- changes
- php
- frontend
- mariadb
- container
- compose
- shell
steps:
- name: Require successful executed checks
if: >-
contains(needs.*.result, 'failure') ||
contains(needs.*.result, 'cancelled')
run: exit 1