forked from netdisco/netdisco
-
Notifications
You must be signed in to change notification settings - Fork 0
363 lines (324 loc) · 13.6 KB
/
test_and_publish.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: Test and Publish Netdisco
on:
workflow_dispatch:
inputs:
success_irc_squawk:
description: 'Squawk to IRC on successful tests'
required: false
default: false
debug_test_enabled:
description: 'With build and test debug'
required: false
default: false
debug_docker_enabled:
description: 'With docker debug'
required: false
default: false
debug_dbdeploy_enabled:
description: 'With db deploy debug'
required: false
default: false
push:
branches:
- master
tags:
- '2.[0-9][0-9][0-9][0-9][0-9][0-9]'
pull_request:
types: [opened, synchronize, reopened]
jobs:
test_netdisco:
name: Test and CPAN Upload
if: github.repository == 'netdisco/netdisco'
runs-on: ubuntu-latest
container:
image: 'netdisco/netdisco:latest-do'
options: '--user root --entrypoint /bin/ash'
volumes:
- '/home/runner/work:/github/workspace'
defaults:
run:
working-directory: /github/workspace/netdisco/netdisco
steps:
- name: Get the Tag or Branch
run: echo "GH_REF_SHORT=$(echo ${GITHUB_REF##*/})" >> $GITHUB_ENV
- name: Install base packages
run: apk add tmux bash curl sudo xz
- name: Install other packages
run: apk add openssh-client gcc make musl-dev perl-dev unzip
- name: Install fake apt-get
run: echo 'if [ "$1" == "update" ]; then exec apk update; else exec apk add openssh-client xz; fi' > /usr/local/bin/apt-get && chmod +x /usr/local/bin/apt-get
- name: Add localhost
run: echo "127.0.0.1 localhost" >> /etc/hosts
- name: Check out latest code
uses: actions/checkout@v1
- name: Fix owner of checkout
run: chown -R netdisco:netdisco /github/workspace/netdisco/netdisco
- name: Install Perl deps
run: |
sudo -u netdisco /home/netdisco/bin/localenv cpanm --notest Env::Path Test::Compile CPAN::Uploader Test::Pod
sudo -u netdisco /home/netdisco/bin/localenv cpanm --notest --installdeps /github/workspace/netdisco/netdisco
- name: Run Tests
id: build_and_run_tests
run: |
sudo -u netdisco /home/netdisco/bin/localenv perl ./Build.PL
sudo -u netdisco /home/netdisco/bin/localenv ./Build test --test_files xt/
continue-on-error: true
- name: IRC test failure notification
if: (steps.build_and_run_tests.outcome == 'failure') && (github.event_name != 'workflow_dispatch') && (github.event_name != 'pull_request')
uses: Gottox/irc-message-action@v2
with:
channel: '#netdisco'
nickname: github-actions
message: |-
🤖 ${{ github.actor }} pushed to ${{ env.GH_REF_SHORT }}: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
😭 TESTS have FAILED! 👀 https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
- name: IRC test success notification
if: (steps.build_and_run_tests.outcome == 'success') && github.event.inputs.success_irc_squawk
uses: Gottox/irc-message-action@v2
with:
channel: '#netdisco'
nickname: github-actions
message: |-
🤖 ${{ github.actor }} pushed to ${{ env.GH_REF_SHORT }}: https://github.com/${{ github.repository }}/commit/${{ github.sha }} (tests PASSED 🎉)
- name: Make release
if: steps.build_and_run_tests.outcome == 'success'
run: |
sudo -u netdisco /home/netdisco/bin/localenv rm ./MANIFEST
sudo -u netdisco /home/netdisco/bin/localenv ./Build manifest
sudo -u netdisco /home/netdisco/bin/localenv ./Build distmeta
sudo -u netdisco /home/netdisco/bin/localenv ./Build dist
- name: Upload to CPAN
id: upload_to_cpan
if: startsWith(github.ref, 'refs/tags/')
env:
PAUSE_USERNAME: ${{ secrets.PAUSE_USERNAME }}
PAUSE_PASSWORD: ${{ secrets.PAUSE_PASSWORD }}
run: |
bash -c 'RELEASENAME=(App-Netdisco-*.tar.gz) && ! curl -LI --fail https://cpan.metacpan.org/authors/id/O/OL/OLIVER/${RELEASENAME}'
sudo -u netdisco /home/netdisco/bin/localenv cpan-upload -u '${{ env.PAUSE_USERNAME }}' -p '${{ env.PAUSE_PASSWORD }}' App-Netdisco-*.tar.gz
continue-on-error: true
- name: IRC upload failure notification
if: steps.upload_to_cpan.outcome == 'failure'
uses: Gottox/irc-message-action@v2
with:
channel: '#netdisco'
nickname: github-actions
message: |-
🤖 Failed to upload Netdisco release ${{ env.GH_REF_SHORT }} to CPAN! 😭
👀 https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
- name: IRC upload success notification
if: steps.upload_to_cpan.outcome == 'success'
uses: Gottox/irc-message-action@v2
with:
channel: '#netdisco'
nickname: github-actions
message: |-
🤖 Uploaded Netdisco release ${{ env.GH_REF_SHORT }} to CPAN 🎉
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
if: always() && github.event.inputs.debug_test_enabled
with:
sudo: true
- name: Preserve status from tests
if: always() && (steps.build_and_run_tests.outcome == 'failure')
run: exit 1
build_docker_images:
name: Build Docker Images
needs: test_netdisco
if: (github.event_name == 'workflow_dispatch') || startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
defaults:
run:
working-directory: /home/runner/work/netdisco/netdisco-docker
steps:
- name: Check out latest code
uses: actions/checkout@v1
with:
repository: 'netdisco/netdisco-docker'
ref: 'master'
- name: Get the Tag
run: |
echo "TAG=$(echo ${GITHUB_REF##*/})" >> $GITHUB_ENV
echo "IMAGE_ROOT=netdisco:$(echo ${GITHUB_REF##*/})" >> $GITHUB_ENV
- name: Build netdisco-postgresql
run: |
cd netdisco-postgresql
docker build -t ${IMAGE_ROOT}-postgresql \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg TAG=${TAG} \
--build-arg COMMITTISH=${TAG} .
docker tag ${IMAGE_ROOT}-postgresql netdisco/${IMAGE_ROOT}-postgresql
- name: Build netdisco-base
run: |
cd netdisco-base
docker build -t ${IMAGE_ROOT}-base \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg TAG=${TAG} \
--build-arg COMMITTISH=${TAG} .
docker tag ${IMAGE_ROOT}-base netdisco/${IMAGE_ROOT}-base
- name: Build netdisco-backend
run: |
cd netdisco-backend
docker build -t ${IMAGE_ROOT}-backend \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg TAG=${TAG} \
--build-arg COMMITTISH=${TAG} .
docker tag ${IMAGE_ROOT}-backend netdisco/${IMAGE_ROOT}-backend
- name: Build netdisco-web
run: |
cd netdisco-web
docker build -t ${IMAGE_ROOT}-web \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg TAG=${TAG} \
--build-arg COMMITTISH=${TAG} .
docker tag ${IMAGE_ROOT}-web netdisco/${IMAGE_ROOT}-web
- name: Build netdisco-demo
run: |
cd netdisco-demo
docker build -t ${IMAGE_ROOT}-demo \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg TAG=${TAG} \
--build-arg COMMITTISH=${TAG} .
docker tag ${IMAGE_ROOT}-demo registry.heroku.com/netdisco2-demo/web
echo "DEMO_IMAGE_ID=$(docker inspect registry.heroku.com/netdisco2-demo/web --format={{.Id}})" >> $GITHUB_ENV
- name: Build netdisco-do
run: |
cd netdisco-do
docker build -t ${IMAGE_ROOT}-do \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg TAG=${TAG} \
--build-arg COMMITTISH=${TAG} .
docker tag ${IMAGE_ROOT}-do netdisco/${IMAGE_ROOT}-do
- name: Login to DH
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
echo '${{ env.DOCKER_PASSWORD }}' | docker login -u '${{ env.DOCKER_USERNAME }}' --password-stdin
- name: Upload to Docker Hub
id: upload_docker_hub
if: startsWith(github.ref, 'refs/tags/')
run: |
for image in postgresql backend web do; do
docker push netdisco/${IMAGE_ROOT}-$image
docker tag ${IMAGE_ROOT}-$image netdisco/netdisco:latest-$image
docker push netdisco/netdisco:latest-$image
done
continue-on-error: true
- name: Logout from DH
run: docker logout
- name: Login to GHP
run: |
echo '${{ secrets.GITHUB_TOKEN }}' | docker login ghcr.io -u '${{ github.actor }}' --password-stdin
- name: Upload to GitHub Packages
id: upload_github_packages
if: startsWith(github.ref, 'refs/tags/')
run: |
for image in postgresql backend web do; do
docker tag ${IMAGE_ROOT}-$image ghcr.io/netdisco/${IMAGE_ROOT}-$image
docker push ghcr.io/netdisco/${IMAGE_ROOT}-$image
docker tag ${IMAGE_ROOT}-$image ghcr.io/netdisco/netdisco:latest-$image
docker push ghcr.io/netdisco/netdisco:latest-$image
done
continue-on-error: true
- name: Logout from GHP
run: docker logout
- name: Login to Heroku
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
run: |
echo '${{ env.HEROKU_API_KEY }}' | docker login registry.heroku.com --username=_ --password-stdin
- name: Upload to Heroku
id: upload_heroku_packages
if: startsWith(github.ref, 'refs/tags/')
run: |
docker push registry.heroku.com/netdisco2-demo/web
continue-on-error: true
- name: Logout from Heroku
run: docker logout
- name: Release on Heroku
if: (github.event_name == 'workflow_dispatch') || (steps.upload_heroku_packages.outcome == 'success')
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
run: |
curl -X PATCH https://api.heroku.com/apps/netdisco2-demo/formation \
-d "{ \"updates\": [ { \"type\": \"web\", \"docker_image\": \"$DEMO_IMAGE_ID\" } ] }" \
-H "Content-Type: application/json" \
-H "Accept: application/vnd.heroku+json; version=3.docker-releases" \
-H "Authorization: Bearer $HEROKU_API_KEY"
continue-on-error: true
- name: IRC DH upload failure notification
if: steps.upload_docker_hub.outcome == 'failure'
uses: Gottox/irc-message-action@v2
with:
channel: '#netdisco'
nickname: github-actions
message: |-
🤖 Failed to publish Netdisco release ${{ env.TAG }} to Docker Hub! 😭
👀 https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
- name: IRC DH upload success notification
if: (steps.upload_docker_hub.outcome == 'success') && github.event.inputs.success_irc_squawk
uses: Gottox/irc-message-action@v2
with:
channel: '#netdisco'
nickname: github-actions
message: |-
🤖 Published Netdisco release ${{ env.TAG }} to Docker Hub! 🎉
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
if: always() && github.event.inputs.debug_docker_enabled
with:
sudo: true
- name: Fix job exit status
if: always() && (steps.upload_docker_hub.outcome == 'failure')
run: exit 1
demo_db_redeploy:
name: Redeploy Demo DB
needs: build_docker_images
if: (github.event_name == 'workflow_dispatch') || startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: 'netdisco/netdisco:latest-do'
options: '--user root --entrypoint /bin/ash'
volumes:
- '/home/runner/work:/github/workspace'
defaults:
run:
working-directory: /github/workspace/netdisco/netdisco
steps:
- name: Install base packages
run: apk add tmux bash curl sudo xz
- name: Install packages
run: apk add openssh-client gcc make musl-dev perl-dev unzip
- name: Install fake apt-get
run: echo 'if [ "$1" == "update" ]; then exec apk update; else exec apk add openssh-client xz; fi' > /usr/local/bin/apt-get && chmod +x /usr/local/bin/apt-get
- name: Check out latest code
uses: actions/checkout@v1
- name: Fix owner of checkout
run: chown -R netdisco:netdisco /github/workspace/netdisco/netdisco
- name: Reinitialise DB
env:
PGUSER: ${{ secrets.DEMO_PGUSER }}
PGPASSWORD: ${{ secrets.DEMO_PGPASSWORD }}
PGHOST: ${{ secrets.DEMO_PGHOST }}
PGDATABASE: ${{ secrets.DEMO_PGDATABASE }}
run: |
psql -c "drop owned by $PGUSER"
psql -c "create schema public"
curl -LO https://github.com/netdisco/netdisco2-demo/raw/master/netdisco2-demo-cumulus-clean.db.bin
pg_restore -x -O -1 -d ${{ env.PGDATABASE }} netdisco2-demo-cumulus-clean.db.bin
- name: Update schema
env:
NETDISCO_HOME: /github/workspace/netdisco/netdisco
NETDISCO_DB_USER: ${{ secrets.DEMO_PGUSER }}
NETDISCO_DB_PASS: ${{ secrets.DEMO_PGPASSWORD }}
NETDISCO_DB_HOST: ${{ secrets.DEMO_PGHOST }}
NETDISCO_DB_NAME: ${{ secrets.DEMO_PGDATABASE }}
run: |
/home/netdisco/bin/localenv /github/workspace/netdisco/netdisco/bin/netdisco-db-deploy
/home/netdisco/bin/localenv /github/workspace/netdisco/netdisco/bin/netdisco-do stats -D
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
if: always() && github.event.inputs.debug_dbdeploy_enabled
with:
sudo: true