-
Notifications
You must be signed in to change notification settings - Fork 4
355 lines (309 loc) · 11.3 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
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
---
name: main
on:
pull_request:
push:
branches:
- main
tags:
- '*'
schedule:
- cron: "0 5 * * 0"
# defaults:
# run:
# working-directory: 'mtulio.okd_installer'
jobs:
# Run linters: yaml-lint and ansible-lint.
lint:
name: lint
runs-on: ubuntu-latest
steps:
- name: Check out the codebase.
uses: actions/checkout@v3
with:
# path: 'mtulio.okd_installer'
submodules: recursive
- name: Set up Python 3.
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install test dependencies.
run: pip3 install yamllint ansible-lint
- name: YAML-lint
run: yamllint .
- name: Ansible-lint
run: ansible-lint ./
# Run molecule tests.
# TODO: more tests should be added to molecule before running it every build.
# Disabling molecule step (and debian) until more consistent tests is added.
molecule:
name: molecule
runs-on: ubuntu-latest
needs: [lint]
strategy:
matrix:
include:
- distro: centos7
playbook: converge.yml
# - distro: debian10
# playbook: converge.yml
steps:
- name: Check out the codebase.
uses: actions/checkout@v3
with:
# path: 'mtulio.okd_installer'
submodules: recursive
- name: Set up Python 3.
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install test dependencies.
run: |
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements.txt
# - name: Run Molecule tests.
# run: molecule test
# env:
# PY_COLORS: '1'
# ANSIBLE_FORCE_COLOR: '1'
# MOLECULE_DISTRO: ${{ matrix.distro }}
# MOLECULE_PLAYBOOK: ${{ matrix.playbook }}
# Build a Collection and save to artifacts.
build:
name: builder(Collection)
runs-on: ubuntu-latest
needs: [molecule]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
# path: 'mtulio.okd_installer'
# fetch-depth: 5
submodules: recursive
- name: Build Collection
env:
VERSION: "0.0.0-ci.${{ github.run_number }}-${{ github.run_id }}"
run: |
echo "> Building VERSION=[$VERSION]"
ansible-playbook hack/ci/deploy.yml \
-e tag="$VERSION" \
-t build
echo "> Listing built artifacts: "
ls build/mtulio-okd_installer-*.tar.gz
echo "> Renaming to 'latest': "
mv -v build/mtulio-okd_installer-$VERSION.tar.gz \
/tmp/mtulio-okd_installer-latest.tar.gz
- name: Save artifacts
uses: actions/upload-artifact@v3
with:
name: mtulio-okd_installer-builds
path: /tmp/mtulio-okd_installer-latest.tar.gz
# Build a container image in PRs only, without publishing it.
build-container:
name: release container(devel)
if: ${{ github.event_name == 'pull_request' && github.base_ref == 'main' }}
runs-on: ubuntu-latest
needs: [build]
env:
VERSION: "0.0.0-dev.${{ github.run_number }}-${{ github.run_id }}"
IMAGE: quay.io/mrbraga/okd-installer
VERCEL_VERSION: 28.20.0
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
# path: 'mtulio.okd_installer'
# fetch-depth: 5
submodules: recursive
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: mtulio-okd_installer-builds
path: /tmp/build/
- name: Build container image
env:
QUAY_USER: ${{ secrets.QUAY_USER }}
QUAY_PASS: ${{ secrets.QUAY_PASS }}
run: |
echo "> Check build artifacts dir /tmp/build:"
ls -l /tmp/build
echo "> Moving artifacts to local:"
mkdir ./build || true
mv -v /tmp/build/*.tar.gz ./build
echo "> Logging to Quay.io:"
podman login -u="${QUAY_USER}" -p="${QUAY_PASS}" quay.io
echo "> Build container image: ${IMAGE}:${VERSION}"
podman build -t ${IMAGE}:${VERSION} -f hack/Containerfile .
echo "> Publish container image: ${IMAGE}:${VERSION}"
podman push ${IMAGE}:${VERSION}
# Building docs preview
- name: Set step vars
id: vars
run: |
echo "cache-key-pip=pip-docs-${{ hashFiles('**/docs/requirements.txt') }}" >> $GITHUB_OUTPUT
echo "cache-dir-pip=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: Set pip cache
uses: actions/cache@v3
with:
path: ${{ steps.vars.outputs.cache-dir-pip }}
key: ${{ steps.vars.outputs.cache-key-pip }}
- name: Set npm cache
uses: actions/cache@v3
with:
path: "${HOME}/.npm"
key: "npm-vercel-${VERCEL_VERSION}"
- name: Build and Deploy Preview Docs
id: verceldeploy
run: |
npm install --global vercel@${VERCEL_VERSION}
vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
vercel build --token=${{ secrets.VERCEL_TOKEN }}
PREVIEW_URL=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})
echo "Discovered Preview URL: ${PREVIEW_URL}"
echo "url=$PREVIEW_URL" >> $GITHUB_OUTPUT
# Commenting in PR the build information (force to always create a comment)
# - name: Find comment
# uses: peter-evans/find-comment@v2
# id: fbc
# with:
# issue-number: ${{ github.event.pull_request.number }}
# comment-author: 'github-actions[bot]'
# body-includes: '<!-- id-build-comment -->'
- name: Create comment
# if: steps.fbc.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
<!-- id-build-comment -->
Artifacts built by CI:
- Container: ${{ env.IMAGE }}:${{ env.VERSION }}
- Docs Preview: ${{ steps.verceldeploy.outputs.url }}
reactions: rocket
# - name: Update comment
# if: steps.fbc.outputs.comment-id != ''
# uses: peter-evans/create-or-update-comment@v3
# with:
# comment-id: ${{ steps.fbc.outputs.comment-id }}
# body: |
# <!-- id-build-comment -->
# Artifacts built by CI:
# - Container: ${{ env.IMAGE }}:${{ env.VERSION }}
# - Docs Preview: ${{ steps.verceldeploy.outputs.url }}
# reactions: hooray
# edit-mode: replace
# Build a container image on main branch, publishing the 'latest' to repository.
publish-container-latest:
name: release container(latest/ci)
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
# path: 'mtulio.okd_installer'
# fetch-depth: 5
submodules: recursive
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: mtulio-okd_installer-builds
path: /tmp/build/
- name: Build container image
env:
VERSION: latest
VERSION_BUILD: "0.0.0-ci.${{ github.run_number }}-${{ github.run_id }}"
IMAGE: quay.io/mrbraga/okd-installer
QUAY_USER: ${{ secrets.QUAY_USER }}
QUAY_PASS: ${{ secrets.QUAY_PASS }}
run: |
echo "> Check build artifacts dir /tmp/build:"
ls -l /tmp/build
echo "> Moving artifacts to local:"
mkdir ./build || true
mv -v /tmp/build/*.tar.gz ./build
echo "> Logging to Quay.io:"
podman login -u="${QUAY_USER}" -p="${QUAY_PASS}" quay.io
echo "> Build container image: ${IMAGE}:${VERSION_BUILD}"
podman build -t ${IMAGE}:${VERSION} -f hack/Containerfile .
podman tag ${IMAGE}:${VERSION} ${IMAGE}:${VERSION_BUILD}
echo "> Publish container image: ${IMAGE}:${VERSION} ${VERSION_BUILD}"
podman push ${IMAGE}:${VERSION}
podman push ${IMAGE}:${VERSION_BUILD}
# Build a Collection when the tag is created, publishing it to Galaxy.
release-to-galaxy:
name: release collection(Galaxy)
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
# path: 'mtulio.okd_installer'
# fetch-depth: 5
submodules: recursive
- name: Get version
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
- name: Deploy to Galaxy
env:
VERSION: ${{ steps.get_version.outputs.VERSION }}
BUILD_FILE: mtulio-okd_installer-${{ steps.get_version.outputs.VERSION }}.tar.gz
ANSIBLE_GALAXY_TOKEN: ${{ secrets.ANSIBLE_GALAXY_TOKEN }}
run: |
echo VERSION=[$VERSION]
ansible-playbook hack/ci/deploy.yml \
-e tag="${VERSION}" \
-t build,deploy
mv -v build/${BUILD_FILE} /tmp/${BUILD_FILE}
- name: Save artifacts
uses: actions/upload-artifact@v3
with:
name: mtulio-okd_installer-build-${{ steps.get_version.outputs.VERSION }}
path: /tmp/mtulio-okd_installer-${{ steps.get_version.outputs.VERSION }}.tar.gz
# Build a Container image with the Collection release, publishing it to repository.
publish-container-release:
name: release container(tag)
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
needs: [release-to-galaxy]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
# path: 'mtulio.okd_installer'
# fetch-depth: 5
submodules: recursive
- name: Get version
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: mtulio-okd_installer-build-${{ steps.get_version.outputs.VERSION }}
path: /tmp/build/
- name: Build container image
env:
VERSION: ${{ steps.get_version.outputs.VERSION }}
VERSION_BUILD: "0.0.0-ci.${{ github.run_number }}-${{ github.run_id }}"
IMAGE: quay.io/mrbraga/okd-installer
QUAY_USER: ${{ secrets.QUAY_USER }}
QUAY_PASS: ${{ secrets.QUAY_PASS }}
run: |
echo "> Check build artifacts dir /tmp/build:"
ls -l /tmp/build
echo "> Moving artifacts to local:"
mkdir ./build || true
mv -v /tmp/build/*.tar.gz ./build
echo "> Logging to Quay.io:"
podman login -u="${QUAY_USER}" -p="${QUAY_PASS}" quay.io
echo "> Build container image:"
podman build --build-arg=QUAY_EXPIRATION=never -t ${IMAGE}:${VERSION} -f hack/Containerfile .
podman tag ${IMAGE}:${VERSION} ${IMAGE}:${VERSION_BUILD}
echo "> Publish container image:"
podman push ${IMAGE}:${VERSION}
podman push ${IMAGE}:${VERSION_BUILD}