-
Notifications
You must be signed in to change notification settings - Fork 18
432 lines (386 loc) · 15.4 KB
/
build-cli.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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
name: Build CLI
on:
workflow_dispatch:
repository_dispatch:
push:
branches: [ "**" ]
tags-ignore: [ "**" ]
release:
types: [ published ]
# References:
# - https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
# - https://docs.github.com/en/actions/learn-github-actions/expressions#functions
jobs:
build-tekton:
name: Build Tekton Definitions
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, '[doc]') }}
steps:
# 1. Initialize the build
# -------------------------------------------------------------------------------------------
- name: Checkout
uses: actions/checkout@v4
# Without this option, we don't get the tag information
with:
fetch-depth: 0
- name: Initialise the build system
run: |
chmod u+x $GITHUB_WORKSPACE/build/bin/*.sh
$GITHUB_WORKSPACE/build/bin/initbuild.sh
source $GITHUB_WORKSPACE/build/bin/.functions.sh
# 2. Tekton
# -------------------------------------------------------------------------------------------
- name: Build the Tekton definitions
run: $GITHUB_WORKSPACE/build/bin/build-tekton.sh
- name: Upload the Tekton definitions
uses: actions/upload-artifact@v4
with:
name: ibm-mas-tekton.yaml
path: ${{ github.workspace }}/tekton/target/ibm-mas-tekton.yaml
retention-days: 30
- name: Upload the Tekton definitions (FVT)
uses: actions/upload-artifact@v4
with:
name: ibm-mas-tekton-fvt.yaml
path: ${{ github.workspace }}/tekton/target/ibm-mas-tekton-fvt.yaml
retention-days: 30
- name: Upload definition to Artifactory
env:
ARTIFACTORY_GENERIC_RELEASE_URL: ${{ secrets.ARTIFACTORY_GENERIC_RELEASE_URL }}
ARTIFACTORY_TOKEN: ${{ secrets.ARTIFACTORY_TOKEN }}
run: |
$GITHUB_WORKSPACE/build/bin/artifactory-release.sh $GITHUB_WORKSPACE/tekton/target/ibm-mas-tekton.yaml
$GITHUB_WORKSPACE/build/bin/artifactory-release.sh $GITHUB_WORKSPACE/tekton/target/ibm-mas-tekton-fvt.yaml
build-python:
name: Build Python Package
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, '[doc]') }}
needs: build-tekton
steps:
# 1. Initialize the build
# -------------------------------------------------------------------------------------------
- name: Checkout
id: checkout
uses: actions/checkout@v4
# Without this option, we don't get the tag information
with:
fetch-depth: 0
- name: Initialise the build system
id: init
run: |
chmod u+x $GITHUB_WORKSPACE/build/bin/*.sh
$GITHUB_WORKSPACE/build/bin/initbuild.sh
source $GITHUB_WORKSPACE/build/bin/.functions.sh
# 2. Build Python Package
# -------------------------------------------------------------------------------------------
- name: Download tekton definitions
id: download-tekton
uses: actions/download-artifact@v4
with:
name: ibm-mas-tekton.yaml
path: ${{ github.workspace }}/python/src/mas/cli/templates/
- name: Install
id: install
run: |
cd $GITHUB_WORKSPACE/python
sed -i "s#__version__ = \"100.0.0\"#__version__ = \"${{ env.VERSION_NOPREREL }}\"#g" ${GITHUB_WORKSPACE}/python/src/mas/cli/__init__.py
sed -i "s#self.version = \"100.0.0-pre.local\"#self.version = \"${{ env.VERSION }}\"#g" ${GITHUB_WORKSPACE}/python/src/mas/cli/cli.py
cat ${GITHUB_WORKSPACE}/python/src/mas/cli/__init__.py
python -m pip install --upgrade pip
pip install .[dev]
- name: Lint
id: lint
run: |
cd $GITHUB_WORKSPACE/python
flake8 src --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 src --count --exit-zero --max-complexity=10 --max-line-length=200 --statistics
- name: Test
id: test
run: |
cd $GITHUB_WORKSPACE/python
pytest
- name: Build
id: build
run: |
cd $GITHUB_WORKSPACE/python
python -m build
cp $GITHUB_WORKSPACE/python/dist/mas_cli-${{ env.VERSION_NOPREREL }}.tar.gz $GITHUB_WORKSPACE/mas_cli.tar.gz
# 3. Upload and Publish
# -------------------------------------------------------------------------------------------
- name: Upload
id: upload
uses: actions/upload-artifact@v4
with:
name: mas_cli.tar.gz
path: ${{ github.workspace }}/mas_cli.tar.gz
retention-days: 30
- name: Publish package
id: publish
if: github.event_name == 'release'
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
packages-dir: python/dist
build-container:
name: Build Container Image
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, '[doc]') }}
needs:
- build-tekton
- build-python
steps:
# 1. Initialize the build
# -------------------------------------------------------------------------------------------
- name: Checkout
id: checkout
uses: actions/checkout@v4
# Without this option, we don't get the tag information
with:
fetch-depth: 0
- name: Initialise the build system
id: init
run: |
chmod u+x $GITHUB_WORKSPACE/build/bin/*.sh
$GITHUB_WORKSPACE/build/bin/initbuild.sh
source $GITHUB_WORKSPACE/build/bin/.functions.sh
# 2. Download Ansible collection from Artifactory
# -------------------------------------------------------------------------------------------
- name: Download Ansible collection from Artifactory
id: download-ansible
if: contains(fromJson('["push", "workflow_dispatch", "repository_dispatch"]'), github.event_name)
env:
ARTIFACTORY_GENERIC_RELEASE_URL: ${{ secrets.ARTIFACTORY_GENERIC_RELEASE_URL }}
ARTIFACTORY_TOKEN: ${{ secrets.ARTIFACTORY_TOKEN }}
run: |
if [[ -e $GITHUB_WORKSPACE/image/cli/install/ibm-mas_devops.tar.gz ]]; then
echo "Found a local Ansible collection to be used in $GITHUB_WORKSPACE/image/cli/install/ibm-mas_devops.tar.gz! Skip download from Artifactory..."
else
echo "Downloading from ***/ibm-mas/ansible-devops/latest/ibm-mas_devops-latest.tar.gz"
wget --header="Authorization:Bearer $ARTIFACTORY_TOKEN" $ARTIFACTORY_GENERIC_RELEASE_URL/ibm-mas/ansible-devops/latest/ibm-mas_devops-latest.tar.gz -O $GITHUB_WORKSPACE/image/cli/install/ibm-mas_devops.tar.gz
fi
# 3. Download Built Artifacts
# -------------------------------------------------------------------------------------------
- name: Download the tekton file built in the other job
id: download-tekton
uses: actions/download-artifact@v4
with:
name: ibm-mas-tekton.yaml
path: ${{ github.workspace }}/image/cli/mascli/templates/
- name: Download the python package
id: download-python
uses: actions/download-artifact@v4
with:
name: mas_cli.tar.gz
path: ${{ github.workspace }}/image/cli/install/
# 4. CLI container image
# -------------------------------------------------------------------------------------------
- name: Build the container image
id: docker-build
run: |
$GITHUB_WORKSPACE/build/bin/docker-build.sh -n ibmmas -i cli
- name: Push the container image
id: docker-push
run: |
docker tag ibmmas/cli quay.io/ibmmas/cli:${{ env.DOCKER_TAG }}
docker images
docker login --username "${{ secrets.QUAYIO_USERNAME }}" --password "${{ secrets.QUAYIO_PASSWORD }}" quay.io
docker push quay.io/ibmmas/cli:${{ env.DOCKER_TAG }}
- name: Push the container image (master)
id: docker-push-master
if: github.ref == 'refs/heads/master'
run: |
docker tag ibmmas/cli quay.io/ibmmas/cli:master
docker images
docker push quay.io/ibmmas/cli:master
- name: Push the container image (latest)
id: docker-push-latest
if: github.event_name == 'release'
run: |
docker tag ibmmas/cli quay.io/ibmmas/cli:latest
docker images
docker push quay.io/ibmmas/cli:latest
# 5. OWASP Dependency Check
# -------------------------------------------------------------------------------------------
- name: Perform dependency check
id: owasp
uses: dependency-check/Dependency-Check_Action@main
with:
project: 'cli'
path: '.'
format: 'HTML'
args: >
--failOnCVSS 7
--enableRetired
- name: Upload dependency check results
id: upload-owasp
uses: actions/upload-artifact@v4
with:
name: OWASP dependency check report
path: ${{github.workspace}}/reports
retention-days: 30
pyinstaller-windows:
name: Build Windows CLI
runs-on: windows-latest
if: ${{ !contains(github.event.head_commit.message, '[doc]') }}
needs:
- build-tekton
- build-python
steps:
# 1. Initialize the build
# -------------------------------------------------------------------------------------------
- name: Checkout
id: checkout
uses: actions/checkout@v4
# 2. Run PyInstaller
# -------------------------------------------------------------------------------------------
- name: Download the tekton file
id: download-tekton
uses: actions/download-artifact@v4
with:
name: ibm-mas-tekton.yaml
path: ${{ github.workspace }}/python/src/mas/cli/templates/
- name: Download the python package
id: download-python
uses: actions/download-artifact@v4
with:
name: mas_cli.tar.gz
path: ${{ github.workspace }}/
- name: Build the Windows executable
id: build
run: |
python -m pip install --upgrade pip virtualenv
python -m venv .venv
.\.venv\Scripts\activate
python -m pip install "./mas_cli.tar.gz[dev]"
python -m pip list
pyinstaller --distpath python/dist --onefile --noconfirm --collect-data mas.devops --collect-data mas.cli python/src/mas-cli
# 3. Upload and Publish
# -------------------------------------------------------------------------------------------
- name: Upload mas-cli
id: upload
uses: actions/upload-artifact@v4
with:
name: mas-cli-windows-amd64
path: ${{ github.workspace }}/python/dist/mas-cli.exe
retention-days: 30
- name: Publish the new cli
id: publish
if: github.event_name == 'release'
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ github.workspace }}/python/dist/mas-cli.exe
asset_name: mas-cli-windows-amd64.exe
tag: ${{ github.ref }}
overwrite: true
pyinstaller-linux:
name: Build Linux CLI
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, '[doc]') }}
needs:
- build-tekton
- build-python
steps:
# 1. Initialize the build
# -------------------------------------------------------------------------------------------
- name: Checkout
id: checkout
uses: actions/checkout@v4
# 2. Run PyInstaller
# -------------------------------------------------------------------------------------------
- name: Download the tekton file
id: download-tekton
uses: actions/download-artifact@v4
with:
name: ibm-mas-tekton.yaml
path: ${{ github.workspace }}/python/src/mas/cli/templates/
- name: Download the python package
id: download-python
uses: actions/download-artifact@v4
with:
name: mas_cli.tar.gz
path: ${{ github.workspace }}/
- name: Build the Linux executable
id: build
run: |
python -m pip install --upgrade pip virtualenv
python -m venv .venv
source .venv/bin/activate
python -m pip install ./mas_cli.tar.gz[dev]
python -m pip list
pyinstaller --distpath python/dist --onefile --noconfirm --collect-data mas.devops --collect-data mas.cli python/src/mas-cli
# 3. Upload and Publish
# -------------------------------------------------------------------------------------------
- name: Upload mas-cli
id: upload
uses: actions/upload-artifact@v4
with:
name: mas-cli-linux-amd64
path: ${{ github.workspace }}/python/dist/mas-cli
retention-days: 30
- name: Publish the new cli
id: publish
if: github.event_name == 'release'
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ github.workspace }}/python/dist/mas-cli
asset_name: mas-cli-linux-amd64
tag: ${{ github.ref }}
overwrite: true
pyinstaller-macos:
name: Build MacOS CLI
runs-on: macos-latest
if: ${{ !contains(github.event.head_commit.message, '[doc]') }}
needs:
- build-tekton
- build-python
steps:
# 1. Initialize the build
# -------------------------------------------------------------------------------------------
- name: Checkout
id: checkout
uses: actions/checkout@v4
# 2. Run PyInstaller
# -------------------------------------------------------------------------------------------
- name: Download the tekton file
id: download-tekton
uses: actions/download-artifact@v4
with:
name: ibm-mas-tekton.yaml
path: ${{ github.workspace }}/python/src/mas/cli/templates/
- name: Download the python package
id: download-python
uses: actions/download-artifact@v4
with:
name: mas_cli.tar.gz
path: ${{ github.workspace }}/
- name: Build the Linux executable
id: build
run: |
python -m pip install --upgrade pip virtualenv
python -m venv .venv
source .venv/bin/activate
python -m pip install ./mas_cli.tar.gz[dev]
python -m pip list
pyinstaller --distpath python/dist --onefile --noconfirm --collect-data mas.devops --collect-data mas.cli python/src/mas-cli
# 3. Upload and Publish
# -------------------------------------------------------------------------------------------
- name: Upload mas-cli
id: upload
uses: actions/upload-artifact@v4
with:
name: mas-cli-macos-arm64
path: ${{ github.workspace }}/python/dist/mas-cli
retention-days: 30
- name: Publish the new cli
id: publish
if: github.event_name == 'release'
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ github.workspace }}/python/dist/mas-cli
asset_name: mas-cli-macos-arm64
tag: ${{ github.ref }}
overwrite: true