-
-
Notifications
You must be signed in to change notification settings - Fork 3
283 lines (248 loc) · 10.2 KB
/
build.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
name: Build
on:
push:
schedule:
- cron: '0 2 * * *'
jobs:
btp:
name: Build-Tag-Push
runs-on: ubuntu-22.04
if: github.repository == 'ds-wizard/engine-backend'
strategy:
matrix:
component: [registry, wizard]
stack: [2.15.3]
env:
COMPONENT: ${{ matrix.component }}
IMAGE_NAME: ${{ matrix.component }}-server
PUBLIC_IMAGE_PREFIX: datastewardshipwizard
DOCKER_META_CONTEXT: './${{ matrix.component }}-server'
DOCKER_META_FILE: './${{ matrix.component }}-server/Dockerfile'
DOCKER_META_PLATFORMS: 'linux/amd64'
STACK_VERSION: ${{ matrix.stack }}
services:
postgres:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: --name postgres
minio:
image: fclairamb/minio-github-actions
ports:
- 9000:9000
options: --name minio
steps:
- name: Detect force push
if: github.event_name == 'push' && github.event.forced
run: echo "Force push detected. Cache may be invalidated..."
- name: Checkout git repository
uses: actions/checkout@v4
- name: Fetch all git history
run: |
git fetch --prune --unshallow
- name: Prepare ~/.local/bin
run: |
mkdir -p ~/.local/bin
export PATH=~/.local/bin:$PATH
# (1) -> Setup cache
- name: Cache ~/.stack
id: cache-stack
uses: actions/cache@v3
with:
path: ~/.stack
key: stack-home-ubuntu22-${{ hashFiles('**/package.yaml')}}-${{ hashFiles('**/stack.yaml*') }}
restore-keys: |
stack-home-ubuntu22-
- name: Cache shared-common
id: cache-shared-common
uses: actions/cache@v3
with:
path: shared-common/.stack-work
key: shared-common-ubuntu22-${{ hashFiles('shared-common/package.yaml')}}-${{ hashFiles('shared-common/**/*.hs') }}
restore-keys: |
shared-common-ubuntu22-${{ hashFiles('shared-common/package.yaml')}}-
shared-common-ubuntu22-
- name: Invalidate shared-common cache (force push)
id: invalidate-cache-shared-common
if: github.event_name == 'push' && github.event.forced && steps.cache-shared-common.outputs.cache-hit != 'true'
run: |
rm -rf shared-common/.stack-work
- name: Cache wizard-common
id: cache-wizard-common
uses: actions/cache@v3
with:
path: wizard-common/.stack-work
key: wizard-common-ubuntu22-${{ hashFiles('wizard-common/package.yaml')}}-${{ hashFiles('wizard-common/**/*.hs') }}
restore-keys: |
wizard-common-ubuntu22-${{ hashFiles('wizard-common/package.yaml')}}-
wizard-common-ubuntu22-
- name: Invalidate wizard-common cache (force push)
id: invalidate-cache-wizard-common
if: github.event_name == 'push' && github.event.forced && steps.cache-wizard-common.outputs.cache-hit != 'true'
run: |
rm -rf wizard-common/.stack-work
- name: Cache wizard-public
id: cache-wizard-public
uses: actions/cache@v3
with:
path: wizard-public/.stack-work
key: wizard-public-ubuntu22-${{ hashFiles('wizard-public/package.yaml')}}-${{ hashFiles('wizard-public/**/*.hs') }}
restore-keys: |
wizard-public-ubuntu22-${{ hashFiles('wizard-public/package.yaml')}}-
wizard-public-ubuntu22-
- name: Invalidate wizard-public cache (force push)
id: invalidate-cache-wizard-public
if: github.event_name == 'push' && github.event.forced && steps.cache-wizard-public.outputs.cache-hit != 'true'
run: |
rm -rf wizard-public/.stack-work
- name: Cache registry-public
id: cache-registry-public
uses: actions/cache@v3
with:
path: registry-public/.stack-work
key: registry-public-ubuntu22-${{ hashFiles('registry-public/package.yaml')}}-${{ hashFiles('registry-public/**/*.hs') }}
restore-keys: |
registry-public-ubuntu22-${{ hashFiles('registry-public/package.yaml')}}-
registry-public-ubuntu22-
- name: Invalidate registry-public cache (force push)
id: invalidate-cache-registry-public
if: github.event_name == 'push' && github.event.forced && steps.cache-registry-public.outputs.cache-hit != 'true'
run: |
rm -rf registry-public/.stack-work
- name: Cache registry-server
id: cache-registry-server
uses: actions/cache@v3
with:
path: registry-server/.stack-work
key: registry-server-${{ matrix.component }}-ubuntu22-${{ hashFiles('registry-server/package.yaml')}}-${{ hashFiles('registry-server/**/*.hs') }}
restore-keys: |
registry-server-${{ matrix.component }}-ubuntu22-${{ hashFiles('registry-server/package.yaml')}}-
registry-server-${{ matrix.component }}-ubuntu22-
- name: Invalidate registry-server cache (force push)
id: invalidate-cache-registry-server
if: github.event_name == 'push' && github.event.forced && steps.cache-registry-server.outputs.cache-hit != 'true'
run: |
rm -rf registry-server/.stack-work
- name: Cache wizard-server
id: cache-wizard-server
uses: actions/cache@v3
if: matrix.component == 'wizard'
with:
path: wizard-server/.stack-work
key: wizard-server-${{ matrix.component }}-ubuntu22-${{ hashFiles('wizard-server/package.yaml')}}-${{ hashFiles('wizard-server/**/*.hs') }}
restore-keys: |
wizard-server-${{ matrix.component }}-ubuntu22-${{ hashFiles('wizard-server/package.yaml')}}-
wizard-server-${{ matrix.component }}-ubuntu22-
- name: Invalidate wizard-server cache (force push)
id: invalidate-cache-wizard-server
if: github.event_name == 'push' && github.event.forced && steps.cache-wizard-server.outputs.cache-hit != 'true'
run: |
rm -rf wizard-server/.stack-work
- name: Cache Stack in ~/.local/bin
id: cache-stack-local-bin
uses: actions/cache@v3
with:
path: ~/.local/bin
key: stack-local-bin-ubuntu22-${{ matrix.stack }}
# (2) -> Prepare and install dependencies
- name: Setup stack
if: steps.cache-stack-local-bin.outputs.cache-hit != 'true'
run: |
curl -L https://github.com/commercialhaskell/stack/releases/download/v$STACK_VERSION/stack-$STACK_VERSION-linux-x86_64.tar.gz | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack';
- name: Update config and build info
run: |
./scripts/update-file-timestamps.sh
./scripts/expand-example-files.sh
./scripts/generate-build-info.sh $COMPONENT-server
- name: Install GHC and dependencies
run: |
stack test --no-terminal --install-ghc --only-dependencies
# (3) -> Build binary
- name: Build and test application
run: |
set -o pipefail
stack test $COMPONENT-server --no-terminal --skip-ghc-check 2>&1 | tee log.txt
set +o pipefail
WARNINGS=$(grep -o ': warning: ' log.txt | wc -l)
if [ $WARNINGS -gt "0" ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "!! GHC WARNINGS DETECTED ($WARNINGS):"
grep ': warning: ' -A 3 log.txt
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit 1
fi
cp $(stack path --local-install-root)/bin/$COMPONENT-server $COMPONENT-server/$COMPONENT-server-bin
env:
FEEDBACK_TOKEN: ${{ secrets.FEEDBACK_TOKEN }}
# (4.1) -> Docker build (test)
- name: Docker meta [test]
id: meta-test
uses: docker/metadata-action@v5
with:
images: |
${{ env.PUBLIC_IMAGE_PREFIX }}/${{ env.IMAGE_NAME }}
tags: |
type=sha
- name: Docker build [test]
uses: docker/build-push-action@v5
with:
context: ${{ env.DOCKER_META_CONTEXT }}
file: ${{ env.DOCKER_META_FILE }}
platforms: ${{ env.DOCKER_META_PLATFORMS }}
push: false
tags: ${{ steps.meta-test.outputs.tags }}
labels: ${{ steps.meta-test.outputs.labels }}
# (4.2) -> Docker login
- name: Docker login [docker.io]
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
# (4.3) -> Docker build+push (dev)
- name: Docker meta [dev]
id: meta-dev
if: github.event_name != 'pull_request'
uses: docker/metadata-action@v5
with:
images: |
${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
- name: Docker build+push [dev]
uses: docker/build-push-action@v5
if: github.event_name != 'pull_request' && steps.meta-dev.outputs.tags != ''
with:
context: ${{ env.DOCKER_META_CONTEXT }}
file: ${{ env.DOCKER_META_FILE }}
platforms: ${{ env.DOCKER_META_PLATFORMS }}
push: true
tags: ${{ steps.meta-dev.outputs.tags }}
labels: ${{ steps.meta-dev.outputs.labels }}
# (4.4) -> Docker build+push (public)
- name: Docker meta [public]
id: meta-public
if: github.event_name != 'pull_request'
uses: docker/metadata-action@v5
with:
images: |
${{ env.PUBLIC_IMAGE_PREFIX }}/${{ env.IMAGE_NAME }}
${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
- name: Docker build+push [public]
uses: docker/build-push-action@v5
if: github.event_name != 'pull_request' && steps.meta-public.outputs.tags != ''
with:
context: ${{ env.DOCKER_META_CONTEXT }}
file: ${{ env.DOCKER_META_FILE }}
platforms: ${{ env.DOCKER_META_PLATFORMS }}
push: true
tags: ${{ steps.meta-public.outputs.tags }}
labels: ${{ steps.meta-public.outputs.labels }}