-
Notifications
You must be signed in to change notification settings - Fork 3
324 lines (312 loc) · 10.4 KB
/
main.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
name: CI
on:
push:
branches-ignore:
- 'dependabot/**'
tags:
- 'v*'
pull_request:
branches-ignore:
- 'dependabot/**'
workflow_dispatch:
concurrency:
group: ci-${{ github.head_ref }}
cancel-in-progress: true
jobs:
test-cgl:
name: Coding Guidelines Check
runs-on: ubuntu-latest
continue-on-error: false
env:
PHP_CS_FIXER_FUTURE_MODE: 1
steps:
- uses: actions/checkout@v4
- name: Setup PHP environment
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: composer:v2
- name: Check code formatting with PHP-CS-Fixer
run: |
rm composer.json composer.lock
composer require friendsofphp/php-cs-fixer:3.4
vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist --diff --dry-run -v
lint:
name: FE Asset Linting
runs-on: ubuntu-latest
continue-on-error: false
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Cache node_modules
uses: actions/cache@v4
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- name: Install npm packages
working-directory: ./src/Resources
run: yarn install
- name: Run FE linters
working-directory: ./src/Resources
run: yarn lint
phpmd:
name: PHPMD
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP environment
uses: shivammathur/setup-php@v2
with:
coverage: none
tools: phpmd
- name: Run PHPMD
run: phpmd src github ./phpmd.xml --baseline-file ./phpmd.baseline.xml --exclude */Tests/*
psalm:
name: Static Code Analysis
runs-on: ubuntu-latest
continue-on-error: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP environment
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: composer
- name: Run composer install
run: composer install -n --prefer-dist
- name: Run Psalm
run: ./vendor/bin/psalm
buildImages:
name: Build Docker Images
runs-on: ubuntu-latest
needs: [test-cgl, lint, psalm]
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 10
- name: Prepare build
run: |
mkdir -p /tmp/docker/buildx
git log -n 10 --date=short --format=format:"%C(auto)%h %ad @%al %s" >> public/changelog.txt
- name: Setup docker build caches
uses: actions/cache@v4
with:
key: ${{ runner.os }}-buildx
path: /tmp/docker/buildx
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
# Production image
- name: Get Docker meta for production image
id: meta
uses: docker/metadata-action@v5
with:
images: aoepeople/meals
tags: |
type=sha
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=edge,branch=master
- name: Build and push production image
id: build_latest
uses: docker/build-push-action@v5
with:
context: .
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
aoepeople/meals:edge
type=local,src=/tmp/docker/buildx
cache-to: type=local,dest=/tmp/docker/buildx
outputs: type=docker,dest=/tmp/docker/app.tar
# Development image
- name: Get Docker meta for development
id: devmeta
uses: docker/metadata-action@v5
with:
images: aoepeople/meals
flavor: |
suffix=-dev
tags: |
type=sha
type=ref,event=branch
- name: Build and push development image
id: build_dev
uses: docker/build-push-action@v5
with:
file: Dockerfile
push: false
tags: ${{ steps.devmeta.outputs.tags }}
labels: ${{ steps.devmeta.outputs.labels }}
build-args: |
BUILD_DEV="true"
cache-from: |
aoepeople/meals:edge-dev
type=local,src=/tmp/docker/buildx
cache-to: type=local,dest=/tmp/docker/buildx
outputs: type=docker,dest=/tmp/docker/dev.tar
# Upload artifacts
- name: Upload docker images
uses: actions/upload-artifact@v4
with:
name: docker-images
path: /tmp/docker/*.tar
outputs:
image: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
images: ${{ join(steps.meta.outputs.tags, ' ') }}
imageDev: ${{ fromJSON(steps.devmeta.outputs.json).tags[0] }}
imagesDev: ${{ join(steps.devmeta.outputs.tags, ' ') }}
testUnitFunctional:
name: Run unit- and functional-tests
needs: [ buildImages ]
runs-on: ubuntu-latest
env:
SERVICE: app # use `dev` to enable xdebug and code coverage
IMAGE_APP: ${{ needs.buildImages.outputs.image }}
IMAGE_DEV: ${{ needs.buildImages.outputs.imageDev }}
COMPOSE_INTERACTIVE_NO_CLI: true
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- uses: actions/checkout@v4
- name: Download docker images
uses: actions/download-artifact@v4
with:
name: docker-images
path: /tmp/docker
- name: Import docker image
run: |
docker load --input /tmp/docker/app.tar
docker load --input /tmp/docker/dev.tar
docker image ls -a | grep aoepeople
- name: Test with docker compose
run: |
mkdir build
docker-compose -f docker-compose-test.yaml up --abort-on-container-exit
docker-compose -f docker-compose-test.yaml down --remove-orphans
- name: Upload coverage report artifact
uses: actions/upload-artifact@v4
if: always()
with:
name: reports
path: build/artifacts/qa/
- name: Publish unit-test results
uses: mikepenz/action-junit-report@v4
if: always()
with:
report_paths: 'build/artifacts/qa/*.xml'
publish:
name: Publish
if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') }}
needs: [ buildImages, testUnitFunctional ]
runs-on: ubuntu-latest
env:
IMAGES_APP: ${{ needs.buildImages.outputs.images }}
IMAGES_DEV: ${{ needs.buildImages.outputs.imagesDev }}
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Download docker images
uses: actions/download-artifact@v4
with:
name: docker-images
path: /tmp/docker
- name: Import docker image
run: |
docker load --input /tmp/docker/app.tar
docker load --input /tmp/docker/dev.tar
docker image ls -a | grep aoepeople
- name: Deploy images
run: |
for tag in $IMAGES_APP; do
if [[ $tag = *sha-* ]]; then
continue;
fi
docker push $tag;
done
for tag in $IMAGES_DEV; do
if [[ $tag = *sha-* ]]; then
continue;
fi
docker push $tag;
done
- name: Image digest
id: image_digest
env:
IMAGE: ${{ needs.buildImages.outputs.image }}
run: |
docker pull $IMAGE
echo "digest=$(docker inspect $IMAGE | jq -r '.[0].RepoDigests[0]' | cut -d'@' -f2)" >> $GITHUB_OUTPUT
- name: Delete docker image artifact
uses: geekyeggo/delete-artifact@v4
with:
name: docker-images
outputs:
imageDigest: ${{ steps.image_digest.outputs.digest }}
snyk:
name: Scan vulnerabilities
if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') }}
needs: [ publish, buildImages ]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run Snyk to check Docker image for vulnerabilities
# Snyk can be used to break the build when it detects vulnerabilities.
# In this case we want to upload the issues to GitHub Code Scanning
continue-on-error: true
uses: snyk/actions/docker@master
env:
# In order to use the Snyk Action you will need to have a Snyk API token.
# More details in https://github.com/snyk/actions#getting-your-snyk-token
# or you can signup for free at https://snyk.io/login
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
image: ${{ needs.buildImages.outputs.image }}
args: --file=Dockerfile
- name: Upload result to GitHub Code Scanning
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: snyk.sarif
deploy:
name: Deploy and notify
needs: [ publish, buildImages ]
runs-on: ubuntu-latest
steps:
- name: Deploy to staging environment
env:
IMAGE_TAG: ${{ needs.buildImages.outputs.image }}
IMAGE_DIGEST: ${{ needs.publish.outputs.imageDigest }}
GITLAB_K8S_IT_TRIGGER: ${{ secrets.GITLAB_K8S_IT_TRIGGER }}
run: |
curl -X POST \
-F "ref=develop" \
-F "variables[IMAGE_TAG]=$IMAGE_TAG" \
-F "variables[IMAGE_DIGEST]=$IMAGE_DIGEST" \
-F "token=$GITLAB_K8S_IT_TRIGGER" \
https://gitlab.aoe.com/api/v4/projects/2872/trigger/pipeline
- name: Notify team
env:
COMMIT_MSG: ${{ github.event.head_commit.message }}
MATTERMOST_HOOK_URL: ${{ secrets.MATTERMOST_HOOK_URL }}
run: |
curl --silent -i -X POST -H 'Content-Type: application/json' \
-d '{"text": "Triggered deployment of `meals-staging.aoe.com@'"$GITHUB_SHA"'`\n> '"$COMMIT_MSG"'"}' \
$MATTERMOST_HOOK_URL