-
-
Notifications
You must be signed in to change notification settings - Fork 200
362 lines (284 loc) · 11.3 KB
/
ci-cd.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
362
name: CI & CD
on:
push:
release:
types: [published]
env:
DOCKER_BUILDKIT: 1
DOCKER_COMPOSE_ARGS: -f docker-compose.yml -f docker-compose.ci.yml
EXEC_ARGS: -T
# Update this to force cache reset
CACHE_KEY: ${{ secrets.CACHE_KEY }}
HASH: ${{ github.sha }}
TAG: ${{ github.ref_name }}
NODE_VERSION: 18.x
PHP_VERSION: 8.3.7
REGISTRY: ${{ secrets.GCP_HOST_GCR }}/${{ secrets.GCP_REGISTRY_PROJECT_ID }}/${{ secrets.REGISTRY_NAME }}
REGISTRY_HOST: ${{ secrets.GCP_HOST_GCR }}
GCP_SA_KEY_GCR_PUSHER: ${{ secrets.GCP_SA_KEY_GCR_PUSHER }}
concurrency:
group: ${{ github.ref_name }}
cancel-in-progress: true
jobs:
build:
name: Build dev
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache composer
uses: actions/cache@v4
with:
path: vendor/
key: cache-${{ env.CACHE_KEY }}-composer-${{ hashFiles('composer.lock') }}
- uses: ./.github/actions/docker-login
- uses: ./.github/actions/docker-pull
with:
hash: ${{ hashFiles('Dockerfile', 'docker/*') }}
- uses: ./.github/actions/build
with:
hash: ${{ hashFiles('Dockerfile', 'docker/*') }}
- uses: ./.github/actions/docker-push
with:
hash: ${{ hashFiles('Dockerfile', 'docker/*') }}
build-static:
name: Build assets
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache yarn dependencies
uses: actions/cache@v4
with:
path: node_modules/
key: cache-${{ env.CACHE_KEY }}-yarn-${{ hashFiles('yarn.lock') }}
- name: Setup yarn
uses: ./.github/actions/setup-yarn
- name: Build static assets
run: yarn build-prod
- name: Cache static assets
uses: actions/cache@v4
with:
path: |
public/built/
public/css/
public/select2/
key: cache-${{ env.CACHE_KEY }}-static-${{ github.sha }}
lint:
name: Lint
runs-on: ubuntu-latest
needs: [build]
env:
EXEC:
steps:
- uses: actions/checkout@v4
- name: Cache composer
uses: actions/cache@v4
with:
path: vendor/
key: cache-${{ env.CACHE_KEY }}-composer-${{ hashFiles('composer.lock') }}
- name: Cache yarn dependencies
uses: actions/cache@v4
with:
path: node_modules/
key: cache-${{ env.CACHE_KEY }}-yarn-${{ hashFiles('yarn.lock') }}
- name: Cache PHP CS Fixer
uses: actions/cache@v4
with:
path: var/.php_cs/.php_cs.cache
key: cache-${{ env.CACHE_KEY }}-phpcsfixer-${{ github.sha }}
restore-keys: |
cache-${{ env.CACHE_KEY }}-phpcsfixer-
- name: Cache PHPStan
uses: actions/cache@v4
with:
path: var/phpstan-tmp/
key: cache-${{ env.CACHE_KEY }}-phpstan-${{ github.sha }}
restore-keys: |
cache-${{ env.CACHE_KEY }}-phpstan-
- uses: ./.github/actions/setup-composer
- uses: ./.github/actions/setup-yarn
- name: PHP Coding Standards Fixer
run: make phpcs
- name: Lint YAML files
run: make ly
- name: Lint Twig files
run: make lt
- name: Lint container
run: make lc
- name: Yarn Eslint
run: make lj
- name: Yarn Prettier
run: make lp
- name: PHPStan - PHP Static Analysis Tool
run: make phpstan
- name: Local PHP Security Checker
run: |-
lastReleaseInfo=$(curl --silent "https://api.github.com/repos/fabpot/local-php-security-checker/releases/latest")
securityCheckVersion=$(echo "${lastReleaseInfo}" | grep '"tag_name":' | sed -E 's/.*"v(.+)",/\1/')
curl -L https://github.com/fabpot/local-php-security-checker/releases/download/v${securityCheckVersion}/local-php-security-checker_linux_$(dpkg --print-architecture) --output ./local-php-security-checker
chmod +x ./local-php-security-checker
./local-php-security-checker
phpunit:
name: PHPUnit
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/dependencies-cache
- name: Cache PHPUnit
uses: actions/cache@v4
with:
path: var/.phpunit.cache/
key: cache-${{ env.CACHE_KEY }}-phpunit-${{ github.sha }}
restore-keys: |
cache-${{ env.CACHE_KEY }}-phpunit-
- uses: ./.github/actions/docker-login
- uses: ./.github/actions/docker-pull
with:
hash: ${{ hashFiles('Dockerfile', 'docker/*') }}
- uses: ./.github/actions/build
with:
hash: ${{ hashFiles('Dockerfile', 'docker/*') }}
extra-containers: db rabbitmq
keys: true
cache-warmup: true
- name: Prepare app (assets, cache, db, rabbitmq)
run: make tfp
- env:
PHPUNIT_ARGS: --log-junit ./phpunit/junit.xml
run: |-
make test-phpunit
behat:
name: Behat
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/dependencies-cache
- uses: ./.github/actions/docker-login
- uses: ./.github/actions/docker-pull
with:
hash: ${{ hashFiles('Dockerfile', 'docker/*') }}
- uses: ./.github/actions/build
with:
hash: ${{ hashFiles('Dockerfile', 'docker/*') }}
extra-containers: db redis rabbitmq
keys: true
cache-warmup: true
- name: Prepare app (assets, cache, db, rabbitmq)
run: make tfp
- env:
BEHAT_ARGS: --suite=default -vvv --colors -f progress -o std -f junit -o ./behat --
run: |-
make test-behat
behat-selenium:
name: Behat/Selenium
runs-on: ubuntu-latest
needs: [build, build-static]
strategy:
fail-fast: false
matrix:
tags:
- '@javascript1'
- '@javascript2'
- '@javascript3'
- '@ux-component'
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/dependencies-cache
- uses: ./.github/actions/docker-login
- uses: ./.github/actions/docker-pull
with:
hash: ${{ hashFiles('Dockerfile', 'docker/*') }}
- uses: ./.github/actions/build
with:
hash: ${{ hashFiles('Dockerfile', 'docker/*') }}
extra-containers: db redis rabbitmq selenium
keys: true
- name: Prepare app (assets, cache, db, rabbitmq)
run: make tfp
- env:
BEHAT_ARGS: --suite=javascript --tags="${{ matrix.tags }}" -vvv --colors -f progress -o std -f junit -o ./behat --
run: |-
make test-behat
- uses: actions/upload-artifact@v4
if: failure()
with:
name: behat-selenium-screenshots-${{ matrix.tags }}
path: var/behat/
retention-days: 1
docker-build-push-gcr:
name: Build prod & push on registry
runs-on: ubuntu-latest
needs: [lint, phpunit, behat, behat-selenium]
if: github.event.ref == 'refs/heads/master' || github.event_name == 'release'
steps:
- uses: actions/checkout@v4
- name: Cache composer
uses: actions/cache@v4
with:
path: vendor/
key: cache-${{ env.CACHE_KEY }}-composer-${{ hashFiles('composer.lock') }}
- name: Cache yarn dependencies
uses: actions/cache@v4
with:
path: node_modules/
key: cache-${{ env.CACHE_KEY }}-yarn-${{ hashFiles('yarn.lock') }}
- name: Cache static assets
uses: actions/cache@v4
with:
path: |
public/built/
public/css/
public/select2/
key: cache-${{ env.CACHE_KEY }}-static-${{ github.sha }}
- name: Setup yarn
uses: ./.github/actions/setup-yarn
- name: Build static assets
run: yarn build-prod
- uses: ./.github/actions/docker-login
- uses: ./.github/actions/docker-pull
with:
hash: ${{ env.HASH }}
tag: ${{ env.TAG }}
- run: perl -pi -e "s/default/${{ github.sha }}/g" ./config/packages/app_version.yaml
- run: |-
docker build \
--quiet \
--cache-from=${{ env.REGISTRY }}:${{ env.TAG }} \
--tag ${{ env.REGISTRY }}:${{ env.TAG }}-${{ env.HASH }} \
--target=php_caddy \
--build-arg BUILDKIT_INLINE_CACHE=1 \
.
- uses: ./.github/actions/docker-push
with:
hash: ${{ env.HASH }}
tag: ${{ env.TAG }}
deploy-staging:
name: Deploy Staging
runs-on: ubuntu-latest
needs: [docker-build-push-gcr]
environment: staging
if: github.event.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4
- name: Create Sentry release
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
environment: staging
ignore_missing: true
ignore_empty: true
- uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY_GKE_DEPLOYER }}
- uses: google-github-actions/get-gke-credentials@v2
with:
cluster_name: ${{ secrets.GKE_CLUSTER }}
location: ${{ secrets.GKE_REGION }}
- run: |-
for GKE_DEPLOYMENT in $(echo ${{ vars.GKE_DEPLOYMENTS }}); do
kubectl set image deployment/$GKE_DEPLOYMENT ${{ secrets.GKE_CONTAINER }}=${{ env.REGISTRY }}:$TAG-$HASH
done