-
Notifications
You must be signed in to change notification settings - Fork 4
210 lines (204 loc) · 7.49 KB
/
ci-cd.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
# yamllint disable rule:line-length
---
name: CI/CD workflow.
# Run the workflow on when code or a semver tag is pushed to main branch,
# and on pull requests towards main branch
on:
push:
branches:
- "main"
tags:
# semver, e.g. 1.2.0 (does not match 0.1.2)
- "[1-9]+.[0-9]+.[0-9]+"
# semver with prerelease info, e.g. 1.0.2-beta.1 or 1.2.3-rc.10
- "[1-9]+.[0-9]+.[0-9]+-[a-z]+.[0-9]+"
# do not match prerelease starting w/ 0, e.g. 1.0.2-beta.0 or 1.2.3-rc.01
- "![1-9]+.[0-9]+.[0-9]+-[a-z]+.[0]*"
# semver with date info, e.g. 1.0.2-20221125
- "[1-9]+.[0-9]+.[0-9]+-[0-9]+"
# do not match date starting w/ 0, e.g. 1.0.2-01232023
- "![1-9]+.[0-9]+.[0-9]+-[0]*"
pull_request:
paths-ignore:
# do not run if only markdown or other administrative files have been updated
- "*.md"
- "CODEOWNERS"
- "LICENSE"
- ".clang-format"
- ".editorconfig"
- ".gitignore"
- ".hadolint.yaml"
- ".yamllint.yaml"
- ".vscode/*"
branches:
- "main"
jobs:
general_settings:
name: Set general settings
runs-on: ubuntu-latest
outputs:
EVENT_TYPE: ${{ steps.set_outputs.outputs.EVENT_TYPE }}
SHORT_SHA: ${{ steps.set_outputs.outputs.SHORT_SHA }}
BUILD_EAP: ${{ steps.set_outputs.outputs.BUILD_EAP }}
steps:
- name: get_trigger_event
run: |
eventtype=${{ (github.ref_type == 'tag') || (github.event_name == 'push' && github.ref == 'refs/heads/main') }}
echo "EVENT_TYPE=${eventtype}" >> $GITHUB_ENV
- name: get_short_sha
run: |
sha=${{ github.sha }}
strip_sha=${sha:0:7}
echo "SHORT_SHA=${strip_sha}" >> $GITHUB_ENV
- name: set_outputs
id: set_outputs
run: |
echo "EVENT_TYPE=${{ env.EVENT_TYPE }}" >> $GITHUB_OUTPUT
echo "SHORT_SHA=${{ env.SHORT_SHA }}" >> $GITHUB_OUTPUT
echo "BUILD_EAP=false" >> $GITHUB_OUTPUT
# Build and run the test suite
build_and_test:
name: Build and run test image
runs-on: ubuntu-latest
needs: general_settings
strategy:
fail-fast: false
matrix:
arch: [armv7hf, aarch64]
# Environment variables that are used by the pytest script
env:
AXIS_TARGET_ADDR_ARMV7HF: "${{ secrets.DEVICE_SRVR_IP }}/camera1"
AXIS_TARGET_ADDR_AARCH64: "${{ secrets.DEVICE_SRVR_IP }}/camera2"
AXIS_TARGET_USER: ${{ secrets.DEVICE_USER }}
AXIS_TARGET_PASS: ${{ secrets.DEVICE_SRVR_PASS }}
AXIS_EXTERNAL_POOL: true
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Create test image metadata
id: meta_test
uses: ./.github/actions/metadata-action
with:
suffix: -${{ matrix.arch }}-test
repository: ${{ vars.REPOSITORY_DOCKER_HUB }}
latest: "false"
get_version: "true"
- name: Update manifest file
if: ( github.ref_type == 'tag')
uses: ./.github/actions/update-acap-manifest-action
with:
manifest_file: ./manifest-test.json
value: ${{ steps.meta_test.outputs.version }}
- name: Build test image
uses: ./.github/actions/docker-build-push-action
with:
dockerfile: Dockerfile
tags: ${{ steps.meta_test.outputs.tags }}
labels: ${{ steps.meta_test.outputs.labels }}
push: true
build-args: |
ARCH=${{ matrix.arch }}
TEST=true
target: runtime-base
registry_user: ${{ secrets.ECOSYSTEM_SERVICE_USER_DOCKER_HUB }}
registry_token: ${{ secrets.ECOSYSTEM_ACCESS_TOKEN_DOCKER_HUB }}
- name: Pull test image
shell: bash
run: |
docker pull ${{ steps.meta_test.outputs.full_name }}
- name: Set environment variables for test
shell: bash
run: |
echo "AXIS_TARGET_ARCH=${{ matrix.arch }}" >> $GITHUB_ENV
if [ ${{ matrix.arch }} = armv7hf ]
then
echo "AXIS_TARGET_ADDR=${{ env.AXIS_TARGET_ADDR_ARMV7HF }}" >> $GITHUB_ENV
elif [ ${{ matrix.arch }} = aarch64 ]
then
echo "AXIS_TARGET_ADDR=${{ env.AXIS_TARGET_ADDR_AARCH64 }}" >> $GITHUB_ENV
else
echo "::error::Non valid architecture '${{ matrix.arch }}' encountered"
fi
echo "ACAP_DOCKER_IMAGE_NAME=${{ steps.meta_test.outputs.full_name }}" >> $GITHUB_ENV
- name: Run the test image
uses: ./.github/actions/pytest-action
with:
testfile: ./.github/test/test_acapruntimetest.py
requirements_file: ./.github/test/requirements.txt
logfile: test_log_${{ matrix.arch }}.txt
# Build containerized image and push to Docker Hub
build_containerized:
name: Build and push containerized images
runs-on: ubuntu-latest
needs: [general_settings]
# if: (github.event_name != 'pull_request')
strategy:
matrix:
arch: [armv7hf, aarch64]
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Create containerized image metadata
id: meta_containerized
uses: ./.github/actions/metadata-action
with:
suffix: -${{ matrix.arch }}-containerized
repository: ${{ vars.REPOSITORY_DOCKER_HUB }}
get_version: "true"
- name: Update manifest file
if: ( github.ref_type == 'tag')
uses: ./.github/actions/update-acap-manifest-action
with:
manifest_file: ./manifest-${{ matrix.arch }}.json
value: ${{ steps.meta_containerized.outputs.version }}
- name: Build and push containerized image
uses: ./.github/actions/docker-build-push-action
with:
dockerfile: Dockerfile
tags: ${{ steps.meta_containerized.outputs.tags }}
labels: ${{ steps.meta_containerized.outputs.labels }}
# only push the resulting image on when building on main
push: "${{ github.event_name != 'pull_request' }}"
build-args: |
ARCH=${{ matrix.arch }}
RUNTIME_VERSION=${{ steps.meta.outputs.version }}
target: "containerized"
use_qemu: "true"
registry_user: ${{ secrets.ECOSYSTEM_SERVICE_USER_DOCKER_HUB }}
registry_token: ${{ secrets.ECOSYSTEM_ACCESS_TOKEN_DOCKER_HUB }}
# Create a pre-release and upload
# This job is skipped if not a tag or if the build_and_test and
# build_containerized jobs have not completed successfully.
create_prerelease:
if: (github.ref_type == 'tag')
permissions:
contents: write
runs-on: ubuntu-latest
needs: [build_and_test, build_containerized]
outputs:
RELEASE_ID: ${{ steps.prerelease.outputs.RELEASE_ID }}
steps:
- name: Set TAG
id: vars
run: echo "TAG=${GITHUB_REF#refs/*/}" >> ${GITHUB_ENV}
- name: Create prerelease
uses: actions/github-script@v7
id: prerelease
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
try {
const response = await github.rest.repos.createRelease({
draft: false,
generate_release_notes: true,
name: '${{ env.TAG }}',
owner: context.repo.owner,
prerelease: true,
repo: context.repo.repo,
tag_name: '${{ env.TAG }}',
});
core.setOutput('RELEASE_ID', response.data.id);
} catch (error) {
core.setFailed(error.message);
}