forked from hyperledger/indy-plenum
-
Notifications
You must be signed in to change notification settings - Fork 0
464 lines (405 loc) · 17.7 KB
/
build.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
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
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
name: indy-plenum-build
on: [ push, pull_request, workflow_dispatch ]
jobs:
workflow-setup:
name: Initialize Workflow
runs-on: ubuntu-latest
outputs:
CACHE_KEY_BUILD: ${{ steps.cache.outputs.CACHE_KEY_BUILD }}
CACHE_KEY_LINT: ${{ steps.cache.outputs.CACHE_KEY_LINT }}
# Expose the lowercase version of the GitHub repository name
# to all subsequent jobs that reference image repositories
# as the push and pull operations require the URL of the repository
# to be in lowercase.
GITHUB_REPOSITORY_NAME: ${{ steps.repository-name.outputs.lowercase }}
GITHUB_REF: ${{ steps.cache.outputs.GITHUB_REF }}
isDev: ${{ steps.build-flags.outputs.isDev }}
isRC: ${{ steps.build-flags.outputs.isRC }}
publish: ${{ steps.build-flags.outputs.publish }}
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Convert the GitHub repository name to lowercase
id: repository-name
uses: ASzc/change-string-case-action@v1
with:
string: ${{ github.repository }}
- name: Set outputs
id: cache
run: |
echo "::set-output name=CACHE_KEY_BUILD::${{ hashFiles('.github/workflows/build/Dockerfile') }}"
echo "::set-output name=CACHE_KEY_LINT::${{ hashFiles('.github/workflows/lint/Dockerfile') }}"
if [[ "${{github.base_ref}}" == 'master' || "${{github.ref}}" == 'refs/heads/master' || "${{github.base_ref}}" == 'main' || "${{github.ref}}" == 'refs/heads/main' ]]; then
echo "::set-output name=GITHUB_REF::main"
elif [[ "${{github.base_ref}}" == 'release*' || "${{github.ref}}" == 'refs/heads/release*' ]]; then
echo "::set-output name=GITHUB_REF::rc"
elif [[ "${{github.base_ref}}" == 'stable' || "${{github.ref}}" == 'refs/heads/stable' ]]; then
echo "::set-output name=GITHUB_REF::stable"
else
echo "::set-output name=GITHUB_REF::dev"
fi
- name: Set build flags
id: build-flags
run: |
if [[ "${{steps.cache.outputs.GITHUB_REF}}" == 'dev' || "${{steps.cache.outputs.GITHUB_REF}}" == 'main' ]]; then
echo "::set-output name=isDev::true"
else
echo "::set-output name=isDev::false"
fi
if [[ "${{steps.cache.outputs.GITHUB_REF}}" == 'rc' ]]; then
echo "::set-output name=isRC::true"
else
echo "::set-output name=isRC::false"
fi
# Ensure publishing is only performed when the build is executed from the main (hyperledger/indy-plenum) repository.
if [[ ${{github.event.repository.full_name}} == 'hyperledger/indy-plenum' && ${{github.event_name}} == 'push' && ( ${{steps.cache.outputs.GITHUB_REF}} == 'main' || ${{steps.cache.outputs.GITHUB_REF}} == 'rc' || ${{steps.cache.outputs.GITHUB_REF}} == 'stable' ) ]]; then
echo "::set-output name=publish::true"
else
echo "::set-output name=publish::false"
fi
build-image:
name: Create Builder Image
# Reference to workflow-setup job is required to access its various outputs.
needs: workflow-setup
runs-on: ubuntu-latest
env:
CACHE_KEY_BUILD: ${{ needs.workflow-setup.outputs.CACHE_KEY_BUILD }}
GITHUB_REPOSITORY_NAME: ${{ needs.workflow-setup.outputs.GITHUB_REPOSITORY_NAME }}
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Try load from cache
id: cache-image
uses: actions/cache@v2
with:
path: ${GITHUB_WORKSPACE}/cache
key: ${{ env.CACHE_KEY_BUILD}}
- name: Prepare image labels and tags
if: steps.cache-image.outputs.cache-hit != 'true'
id: prep
shell: bash
run: |
DOCKER_IMAGE=ghcr.io/${{ env.GITHUB_REPOSITORY_NAME }}/plenum-build
# ToDo - Update hard coded 'ubuntu-16-04' tag when integrating these flows with the ubuntu-20.04-upgrade branch.
TAGS="${DOCKER_IMAGE}:latest,${DOCKER_IMAGE}:ubuntu-16-04"
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Log into the GitHub Container Registry
if: steps.cache-image.outputs.cache-hit != 'true'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
if: steps.cache-image.outputs.cache-hit != 'true'
uses: docker/setup-buildx-action@v1
- name: Build and push image
if: steps.cache-image.outputs.cache-hit != 'true'
uses: docker/build-push-action@v2
with:
context: .
file: .github/workflows/build/Dockerfile
no-cache: true
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
- name: Touch Cache
if: steps.cache-image.outputs.cache-hit != 'true'
run: |
mkdir -p ${GITHUB_WORKSPACE}/cache
touch ${GITHUB_WORKSPACE}/cache/${{ env.CACHE_KEY_BUILD }}
lint-image:
name: Create Linter Image
# Reference to workflow-setup job is required to access its various outputs.
needs: workflow-setup
runs-on: ubuntu-latest
env:
CACHE_KEY_LINT: ${{ needs.workflow-setup.outputs.CACHE_KEY_LINT }}
GITHUB_REPOSITORY_NAME: ${{ needs.workflow-setup.outputs.GITHUB_REPOSITORY_NAME }}
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Try load from cache
id: cache-image
uses: actions/cache@v2
with:
path: ${GITHUB_WORKSPACE}/cache
key: ${{ env.CACHE_KEY_LINT }}
- name: Prepare image labels and tags
if: steps.cache-image.outputs.cache-hit != 'true'
id: prep
shell: bash
run: |
DOCKER_IMAGE=ghcr.io/${{ env.GITHUB_REPOSITORY_NAME }}/plenum-lint
# ToDo - Update hard coded 'ubuntu-18-04' tag when integrating these flows with the ubuntu-20.04-upgrade branch.
TAGS="${DOCKER_IMAGE}:latest,${DOCKER_IMAGE}:ubuntu-18-04"
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Log into the GitHub Container Registry
if: steps.cache-image.outputs.cache-hit != 'true'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
if: steps.cache-image.outputs.cache-hit != 'true'
uses: docker/setup-buildx-action@v1
- name: Build and push image
if: steps.cache-image.outputs.cache-hit != 'true'
uses: docker/build-push-action@v2
with:
context: .
file: .github/workflows/lint/Dockerfile
no-cache: true
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
- name: Touch Cache
if: steps.cache-image.outputs.cache-hit != 'true'
run: |
mkdir -p ${GITHUB_WORKSPACE}/cache
touch ${GITHUB_WORKSPACE}/cache/${{ env.CACHE_KEY_LINT }}
indy_plenum_tests:
name: Sliced Module Tests
# Reference to workflow-setup job is required to access the GITHUB_REPOSITORY_NAME output.
needs: [workflow-setup, build-image]
runs-on: ubuntu-20.04
# Fix for scacap/action-surefire-report out of memory error:
# - https://github.com/ScaCap/action-surefire-report/issues/17
env:
NODE_OPTIONS: '--max_old_space_size=4096'
container:
image: ghcr.io/${{ needs.workflow-setup.outputs.GITHUB_REPOSITORY_NAME }}/plenum-build:ubuntu-16-04
strategy:
matrix:
module: [plenum]
# To slice up the tests into smaller chunks add additional sequential
# numbers here. The subsequent steps will adjust automatically.
# ${{ strategy.job-total }} is used to get the total number of slices.
slice: [1, 2, 3, 4, 5, 6, 7, 8]
fail-fast: false
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Cache pip
uses: actions/cache@v2
with:
# pip cache on the plenum-build image is not in the default location.
# path: ~/.cache/pip
path: /root/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/setup.py') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
# Explicitly use the existing pip cache location in the plenum-build image.
pip --cache-dir /root/.cache/pip install .[tests]
- name: Run Indy Plenum ${{ matrix.module }} test slice ${{ matrix.slice }}/${{ strategy.job-total }}
id: plenum-test
run: RUSTPYTHONASYNCIODEBUG=0 python3 runner.py --pytest "python3 -m pytest -l -vv" --dir "${{ matrix.module }}" --output "test-result-plenum-${{ matrix.slice }}.txt" --test-only-slice "${{ matrix.slice }}/${{ strategy.job-total }}"
- name: Publish Test Report
if: success() || failure()
uses: scacap/action-surefire-report@v1.0.7
continue-on-error: true
with:
check_name: Indy Plenum ${{ matrix.module }} Test Report for slice ${{ matrix.slice }}/${{ strategy.job-total }}
github_token: ${{ secrets.GITHUB_TOKEN }}
report_paths: "*-test-results.xml"
- name: Upload Detailed Test Failure Results
# The test runner only emits the detailed test results if the tests fail.
if: (steps.plenum-test.outcome == 'failure') && failure()
uses: actions/upload-artifact@v2
with:
name: detailed-test-result-slice-${{ matrix.slice }}
path: test-result-plenum-${{ matrix.slice }}.txt
retention-days: 5
indy_plenum_module_tests:
name: Module Tests
# Reference to workflow-setup job is required to access the GITHUB_REPOSITORY_NAME output.
needs: [workflow-setup, build-image]
runs-on: ubuntu-20.04
container:
image: ghcr.io/${{ needs.workflow-setup.outputs.GITHUB_REPOSITORY_NAME }}/plenum-build:ubuntu-16-04
strategy:
matrix:
module: [common, crypto, ledger, state, storage, stp_core, stp_zmq]
fail-fast: false
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Cache pip
uses: actions/cache@v2
with:
# pip cache on the plenum-build image is not in the default location.
# path: ~/.cache/pip
path: /root/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/setup.py') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
# Explicitly use the existing pip cache location in the plenum-build image.
pip --cache-dir /root/.cache/pip install .[tests]
- name: Run Indy Plenum ${{ matrix.module }} tests
run: python3 -m pytest -l -vv --junitxml=test-result-plenum-${{ matrix.module }}.xml ${{ matrix.module }}
- name: Publish Test Report
uses: scacap/action-surefire-report@v1.0.7
continue-on-error: true
with:
check_name: Indy Plenum ${{ matrix.module }} Test Report
github_token: ${{ secrets.GITHUB_TOKEN }}
report_paths: test-result-plenum-${{ matrix.module }}.xml
lint:
name: Lint
# Reference to workflow-setup job is required to access the GITHUB_REPOSITORY_NAME output.
needs: [workflow-setup, lint-image]
runs-on: ubuntu-20.04
container:
image: ghcr.io/${{ needs.workflow-setup.outputs.GITHUB_REPOSITORY_NAME }}/plenum-lint:ubuntu-18-04
steps:
- name: Check out code
uses: actions/checkout@v2
- name: flake8
run: python3 -m flake8
build_release:
name: Build Release
needs: [workflow-setup, indy_plenum_tests, indy_plenum_module_tests, lint]
runs-on: ubuntu-20.04
container:
image: ghcr.io/${{ needs.workflow-setup.outputs.GITHUB_REPOSITORY_NAME }}/plenum-build:ubuntu-16-04
steps:
- name: Check out code
uses: actions/checkout@v1
- name: Set Build Version
id: version
uses: ./.github/actions/set-version
with:
moduleName: plenum
isDev: ${{ needs.workflow-setup.outputs.isDev }}
isRC: ${{ needs.workflow-setup.outputs.isRC }}
- name: Build Deployment Package
run: |
mkdir -p /tmp/plenum-build
./build-scripts/ubuntu-1604/build-indy-plenum.sh "/__w/indy-plenum/indy-plenum" "${{ steps.version.outputs.upstreamVer }}" "/tmp/plenum-build" "${{ steps.version.outputs.pkgVer }}"
- uses: actions/upload-artifact@v2
with:
name: plenum-deb
path: /tmp/plenum-build
retention-days: 5
build_3rd_party_dependencies:
name: Build 3rd Party Dependencies
needs: [workflow-setup, indy_plenum_tests, indy_plenum_module_tests, lint]
runs-on: ubuntu-20.04
container:
image: ghcr.io/${{ needs.workflow-setup.outputs.GITHUB_REPOSITORY_NAME }}/plenum-build:ubuntu-16-04
steps:
- name: Check out code
uses: actions/checkout@v1
- name: Try load from cache.
id: third-party-dependencies
uses: actions/cache@v2
with:
path: /tmp/third-party-dependencies
key: third-party-dependencies-${{ hashFiles('./build-scripts/ubuntu-1604/build-3rd-parties.sh') }}
- name: Build 3rd party deployment packages
if: steps.third-party-dependencies.outputs.cache-hit != 'true'
run: |
mkdir -p ./build-scripts/ubuntu-1604/cache/3rd-party-dependencies/
./build-scripts/ubuntu-1604/build-3rd-parties.sh ./cache/3rd-party-dependencies
mv ./build-scripts/ubuntu-1604/cache/* /tmp/third-party-dependencies
build-python-packages:
name: Build Python Packages
runs-on: ubuntu-20.04
needs: [workflow-setup, indy_plenum_tests, indy_plenum_module_tests, lint]
steps:
- name: Check out code
uses: actions/checkout@v1
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install required packages via pip
run: |
python3 -m pip install pytest-runner wheel
- name: Set Build Version
id: version
uses: ./.github/actions/set-version
with:
moduleName: plenum
isDev: ${{ needs.workflow-setup.outputs.isDev }}
isRC: ${{ needs.workflow-setup.outputs.isRC }}
- name: Prepare package and set version
run: |
# ToDo - Update hard coded 'ubuntu-16-04' tag when integrating these flows with the ubuntu-20.04-upgrade branch.
./build-scripts/ubuntu-1604/prepare-package.sh . plenum "${{ steps.version.outputs.upstreamVer }}" python-packages
- name: Building python package
run: |
python3 setup.py sdist --dist-dir /tmp/dist bdist_wheel --dist-dir /tmp/dist
- uses: actions/upload-artifact@v2
with:
name: plenum-python
path: /tmp/dist
retention-days: 5
publish_artifacts:
name: Publish Artifacts
runs-on: ubuntu-20.04
needs: [workflow-setup, build_release, build_3rd_party_dependencies, build-python-packages]
if: needs.workflow-setup.outputs.publish == 'true'
env:
GITHUB_REF: ${{ needs.workflow-setup.outputs.GITHUB_REF }}
steps:
- name: Check out code
uses: actions/checkout@v1
- name: Setup JFrog CLI
uses: jfrog/setup-jfrog-cli@v2
env:
JF_ARTIFACTORY_1: ${{ secrets.INDY_ARTIFACTORY_REPO_CONFIG }}
- name: Ping Artifactory
run: |
# Test the connection to Ping the Hyperledger Artifactory server
# to ensure everything has been setup correctly.
jfrog rt ping
- name: Download Plenum Artifacts from Pipeline Artifacts
uses: actions/download-artifact@v4.1.7
with:
name: plenum-deb
path: to_publish
- name: Publish Plenum Artifacts
uses: ./.github/actions/publish-deb
with:
sourceDirectory: /home/runner/work/indy-plenum/indy-plenum/to_publish
distribution: xenial
component: ${{ env.GITHUB_REF }}
- name: Download 3rd Party Artifacts Dependencies from Cache
id: third-party-dependencies
uses: actions/cache@v2
with:
path: /tmp/third-party-dependencies
key: third-party-dependencies-${{ hashFiles('./build-scripts/ubuntu-1604/build-3rd-parties.sh') }}
restore-keys: |
third-party-dependencies-
- name: Publish 3rd Party Dependencies
uses: ./.github/actions/publish-deb
with:
sourceDirectory: /home/runner/tmp/third-party-dependencies
distribution: xenial
component: ${{ env.GITHUB_REF }}
- name: Download Python Packages from Pipeline Artifacts
uses: actions/download-artifact@v4.1.7
with:
name: plenum-python
path: dist
- name: Publish Python Package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
skip_existing: true