-
Notifications
You must be signed in to change notification settings - Fork 9
282 lines (241 loc) · 8.2 KB
/
hub.yaml
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
name: Hub
on:
push:
branches:
- master
paths:
- ".github/workflows/hub.yaml"
- "sourcecode/hub/**"
tags:
- 'v*'
pull_request:
branches:
- master
paths:
- '.github/workflows/hub.yaml'
- 'sourcecode/hub/**'
workflow_dispatch:
defaults:
run:
working-directory: sourcecode/hub
concurrency:
group: hub-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
composer-validate:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Validate
run: composer validate --no-check-publish
php-cs-fixer:
if: github.ref != 'refs/heads/master'
needs: [composer-validate]
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.CERPUSBOT_SECRET }}
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
- name: Manage php-cs-fixer cache
uses: actions/cache@v4
with:
path: sourcecode/hub/.php-cs-fixer.cache
key: hub-phpcsfixer-${{ github.sha }}
restore-keys: hub-phpcsfixer-
- name: Get Composer cache dir
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: hub-phpcsfixer-composer-${{ hashFiles('sourcecode/hub/tools/php-cs-fixer/composer.lock') }}
restore-keys: |
hub-phpcsfixer-composer-
- name: Install dependencies
run: composer install --working-dir=tools/php-cs-fixer --no-progress --prefer-dist
- name: Run php-cs-fixer
run: tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --show-progress=none
- name: Commit fixed code
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Run php-cs-fixer
phpstan:
if: always()
needs: [php-cs-fixer]
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
extensions: sockets, zip
coverage: pcov
- name: Get Composer cache dir
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: hub-composer-${{ hashFiles('sourcecode/hub/composer.lock') }}
restore-keys: |
hub-composer-
- name: Install dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader
- name: Run PHPStan
run: |
sourcecode/hub/vendor/bin/phpstan analyse \
--configuration=sourcecode/hub/phpstan.dist.neon \
--memory-limit=512M
working-directory: ${{ github.workspace }}
build_test_publish:
if: always()
needs: [php-cs-fixer]
runs-on: ubuntu-22.04
services:
postgres:
image: postgres:15-alpine
env:
POSTGRES_PASSWORD: thepgpassword
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
meilisearch:
image: getmeili/meilisearch:v1.0
env:
MEILI_NO_ANALYTICS: 'true'
MEILI_MASTER_KEY: masterkey1234567
options: >-
--health-cmd "curl -f http://localhost:7700/health"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 7700:7700
steps:
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: cerpusbot
password: ${{ secrets.CERPUSBOT_SECRET }}
- name: Set up Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.arch }}-buildx-hub-${{ github.sha }}
restore-keys: |
${{ runner.arch }}-buildx-hub-
- name: Checkout
uses: actions/checkout@v4
- name: Build test image
uses: docker/build-push-action@v5
with:
context: sourcecode/hub
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
load: true
tags: hub-test
target: test
- name: Run tests
run: |
docker run --rm --net=host \
-e MEILISEARCH_HOST=http://localhost:7700 \
-e DB_HOST=127.0.0.1 \
-e DB_DATABASE=postgres \
hub-test vendor/bin/phpunit --exclude-testsuite Browser
# TODO: insert codecov stuff here when repo is opened
- name: Gather Docker metadata for PHP image
id: php_meta
uses: docker/metadata-action@v5
with:
images: |
name=ghcr.io/cerpus/edlib-hub
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }},prefix=php-
type=semver,pattern={{version}},prefix=php-
type=semver,pattern={{major}}.{{minor}},prefix=php-
type=semver,pattern={{major}},prefix=php-
type=ref,event=branch,prefix=php-
type=ref,event=pr,prefix=php-
type=sha,prefix=php-
- name: Build PHP image
uses: docker/build-push-action@v5
with:
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/buildx-cache-new,mode=max
context: sourcecode/hub
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
target: prod
tags: ${{ steps.php_meta.outputs.tags }}
- name: Gather Docker metadata for web image
id: web_meta
uses: docker/metadata-action@v5
with:
images: |
name=ghcr.io/cerpus/edlib-hub
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }},prefix=web-
type=semver,pattern={{version}},prefix=web-
type=semver,pattern={{major}}.{{minor}},prefix=web-
type=semver,pattern={{major}},prefix=web-
type=ref,event=branch,prefix=web-
type=ref,event=pr,prefix=web-
type=sha,prefix=web-
- name: Build web image
uses: docker/build-push-action@v5
with:
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
context: sourcecode/hub
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
target: web
tags: ${{ steps.web_meta.outputs.tags }}
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
deploy-eb:
name: Deploy hub to test environments
if: always() && needs.build_test_publish.result == 'success' && github.event_name == 'push' && github.ref == 'refs/heads/master'
needs: [build_test_publish]
strategy:
matrix:
environment:
- test
- ndla_staging
environment: ${{ matrix.environment }}
concurrency: deploy-hub-${{ matrix.environment }}
runs-on: ubuntu-22.04
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: eu-west-1
role-duration-seconds: 3600
role-session-name: GithubCerpusDevDeploy
- name: Re-deploy docker-compose on Elastic Beanstalk
run: |
aws elasticbeanstalk update-environment --environment-name ${{ vars.HUB_ENVIRONMENT_NAME }} --version-label ${{ vars.HUB_APPLICATION_VERSION }}