forked from canonical/microcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
403 lines (352 loc) · 14.4 KB
/
Copy pathtests.yml
File metadata and controls
403 lines (352 loc) · 14.4 KB
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
name: Tests
on:
schedule:
- cron: '0 0 * * 0' # Weekly on Sunday at 00:00 UTC
push:
branches:
- main
pull_request:
workflow_dispatch:
env:
CGO_CFLAGS: -I/home/runner/go/deps/dqlite/include/
CGO_LDFLAGS: -L/home/runner/go/deps/dqlite/.libs/
LD_LIBRARY_PATH: /home/runner/go/deps/dqlite/.libs/
CGO_LDFLAGS_ALLOW: (-Wl,-wrap,pthread_create)|(-Wl,-z,now)
# Use the github.workspace variable to adapt the cover directory path based on the used runner.
GOCOVERDIR: ${{ ( github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' ) && format('{0}/cover', github.workspace) || '' }}
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
defaults:
run:
# Make sure bash is always invoked with `-eo pipefail`
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell
shell: bash
jobs:
changes:
if: ${{ github.repository_owner == 'canonical' }}
name: Changes
runs-on: ubuntu-slim
outputs:
except_docs: ${{ steps.check.outputs.changes }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Check for changes
uses: ./.github/actions/check-changes
id: check
with:
glob: ":!doc/*"
code-tests:
if: ${{ (needs.changes.outputs.except_docs == 'true' || github.event_name == 'schedule') && github.repository_owner == 'canonical' }}
name: Code
runs-on: ubuntu-22.04
needs: [changes]
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# A non-shallow clone is needed for the Differential ShellCheck
fetch-depth: 0
persist-credentials: false
- name: Install Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Check compatibility with min Go version
run: |
set -eux
GOMIN="$(sed -n 's/^GOMIN=\([0-9.]\+\)$/\1/p' Makefile)"
go mod tidy -go="${GOMIN}"
- name: Dependency Review
uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 # v5.0.0
if: github.event_name == 'pull_request'
- id: ShellCheck
name: Differential ShellCheck
uses: redhat-plumbers-in-action/differential-shellcheck@d965e66ec0b3b2f821f75c8eff9b12442d9a7d1e # v5.5.6
with:
token: ${{ secrets.GITHUB_TOKEN }}
strict-check-on-push: true
if: github.event_name == 'pull_request'
- name: Upload artifact with ShellCheck defects in SARIF format
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: Differential ShellCheck SARIF
path: ${{ steps.ShellCheck.outputs.sarif }}
if: github.event_name == 'pull_request'
- name: Install MicroCloud build dependencies
uses: ./.github/actions/install-builddeps
- name: Build
run: |
make deps
make build-test
- name: Run static analysis
run: make check-static
- name: Make GOCOVERDIR
run: mkdir -p "${GOCOVERDIR}"
if: env.GOCOVERDIR != ''
- name: Unit tests
run: |
set -eux
make check-unit
- name: Upload coverage data
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: coverage-unit
path: ${{env.GOCOVERDIR}}
if: env.GOCOVERDIR != ''
- name: Prepare dqlite dependencies for system tests
run: |
# Include dqlite libs in dependencies for system tests.
mkdir /home/runner/go/bin/dqlite
mv ~/go/deps/dqlite/include /home/runner/go/bin/dqlite/include
mv ~/go/deps/dqlite/.libs /home/runner/go/bin/dqlite/libs
- name: Upload system test dependencies
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: system-test-deps
path: |
/home/runner/go/bin/microcloud
/home/runner/go/bin/microcloudd
/home/runner/go/bin/dqlite
retention-days: 1
system-tests-core:
env:
DEBUG: "1"
SKIP_VM_LAUNCH: "1"
SNAPSHOT_RESTORE: "1"
if: ${{ github.repository_owner == 'canonical' }}
name: System (core)
runs-on: ubuntu-24.04
needs: code-tests
strategy:
fail-fast: false
matrix:
# Test suites that will be combined with the set versions.
# Define this first in the matrix so that it's readable
# after GitHub as formed the name for the respective check.
suite:
- "add_interactive"
- "add_services"
- "cluster_manager"
- "e2e"
- "instances"
- "interactive"
- "interactive_combinations"
- "mismatch"
- "non_ha"
- "preseed"
- "recover"
- "remove_cluster"
- "reuse_cluster"
- "terraform_demo"
# Set of versions to use for the matrix tests.
os: ["24.04"]
microceph: ["tentacle/edge"]
microovn: ["latest/edge"]
lxd:
# Both LXD 5.21 and 6 are supported.
- "5.21/edge"
- "6/edge"
microcloud: ["latest/edge"]
exclude:
# Exclude LXD 6 for regular development pipelines to speed up the result cycle.
# But launch the LXD 6 tests both for schedules and manual workflow dispatch.
- lxd: ${{ github.event_name != 'schedule' && github.event_name != 'workflow_dispatch' && '6/edge' }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: System test
uses: ./.github/actions/system-test
with:
setup_testbed: ${{ matrix.suite != 'terraform_demo' }}
setup_terraform: ${{ matrix.suite == 'e2e' || matrix.suite == 'terraform_demo' }}
collect_coverage: ${{ matrix.suite != 'terraform_demo' }}
system-tests-upgrade:
env:
DEBUG: "1"
SKIP_VM_LAUNCH: "1"
SNAPSHOT_RESTORE: "1"
if: ${{ github.repository_owner == 'canonical' }}
name: System (upgrade)
runs-on: ubuntu-24.04
needs: code-tests
strategy:
fail-fast: false
matrix:
suite: ["upgrade"]
os:
- "22.04"
- "24.04"
microceph:
- "squid/stable"
microovn: ["24.03/stable"]
lxd: ["5.21/stable"]
microcloud: ["2/candidate"]
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: System test
uses: ./.github/actions/system-test
tics:
name: Tiobe TICS
runs-on: ubuntu-22.04
needs: [system-tests-core, system-tests-upgrade]
env:
CGO_CFLAGS: "-I/home/runner/go/bin/dqlite/include/"
CGO_LDFLAGS: "-L/home/runner/go/bin/dqlite/libs/"
LD_LIBRARY_PATH: "/home/runner/go/bin/dqlite/libs/"
CGO_LDFLAGS_ALLOW: "(-Wl,-wrap,pthread_create)|(-Wl,-z,now)"
if: ${{ ( github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' ) && github.ref_name == 'main' && github.repository_owner == 'canonical' }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Install Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'go.mod'
- name: Download coverage data
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
pattern: coverage-*
path: ${{env.GOCOVERDIR}}
merge-multiple: true
- name: Extract coverage data
run: |
find "${GOCOVERDIR}"/micro*/cover/ -type f -exec mv {} "${GOCOVERDIR}" \;
rm -rf "${GOCOVERDIR}"/micro*
ls -la "${GOCOVERDIR}"
- name: Download system test dependencies
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: system-test-deps
merge-multiple: true
path: /home/runner/go/bin
- name: Install MicroCloud build dependencies
uses: ./.github/actions/install-builddeps
- name: Install dependencies
run: |
go install github.com/afunix/gocov/gocov@latest
go install github.com/b-dean/gocov-xml@v1.2.1-bdd.0 # XXX: Using this repo is a temporary workaround until https://github.com/AlekSi/gocov-xml/pull/20 is merged. See https://github.com/AlekSi/gocov-xml/pull/20#issuecomment-3275134132 for more details.
go install honnef.co/go/tools/cmd/staticcheck@latest
- name: Convert coverage files
run: |
go tool covdata textfmt -i="${GOCOVERDIR}" -o "${GOCOVERDIR}"/coverage.out
gocov convert "${GOCOVERDIR}"/coverage.out > "${GOCOVERDIR}"/coverage.json
gocov-xml < "${GOCOVERDIR}"/coverage.json > "${GOCOVERDIR}"/coverage-go.xml
go tool covdata percent -i="${GOCOVERDIR}"
- name: Run TICS
uses: tiobe/tics-github-action@333078bc527399e5916a166bd1a3a788be5a01a9 # v3.12.0
with:
mode: qserver
project: microcloud
viewerUrl: https://canonical.tiobe.com/tiobeweb/TICS/api/cfg?name=GoProjects
branchdir: ${{ github.workspace }}
ticsAuthToken: ${{ secrets.TICSAUTHTOKEN }}
installTics: true
calc: ALL
tmpdir: /tmp/tics
doc-tests:
name: Documentation
uses: canonical/documentation-workflows/.github/workflows/documentation-checks.yaml@aaeaf091e8f55145184ad897cb9834f224bd31de # main
with:
working-directory: './doc'
makefile: 'Makefile'
python-version: '3.12'
snap:
name: Trigger snap build
runs-on: ubuntu-24.04
needs: [code-tests, system-tests-core, system-tests-upgrade, doc-tests]
if: ${{ github.repository_owner == 'canonical' && github.event_name == 'push' && github.actor != 'dependabot[bot]' }}
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
LATEST_MAJOR_VERSION: 3
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# A non-shallow clone is needed for the push to Launchpad.
fetch-depth: 0
persist-credentials: false
# XXX: from this point onwards in this **specific job**, the private SSH key is
# available through the SSH_AUTH_SOCK environment variable.
- uses: canonical/lxd/.github/actions/lp-snap-build@main # zizmor: ignore[unpinned-uses]
with:
repo: "git+ssh://lxdbot@git.launchpad.net/~microcloud-snap/microcloud"
ssh-key: ${{ secrets.LAUNCHPAD_LXD_BOT_KEY }} # zizmor: ignore[secrets-outside-env]
- name: Trigger Launchpad snap build
run: |
set -eux
set -o pipefail
# Record current commit hash.
localRev="$(git rev-parse HEAD)"
# Extract a strict major.minor[.patch] version.
version="$(sed -nE 's/^const RawVersion = "([0-9]+\.[0-9]+(\.[0-9]+)?)"$/\1/p' "${GITHUB_WORKSPACE}/version/version.go")"
if [ -z "${version}" ]; then
echo "ERROR: Invalid version format in version/version.go. Expected format: n.n or n.n.n" >&2
exit 1
fi
# Code branch Launchpad branch
# main -> latest-edge
# vX-edge -> vX-edge
# release-${LATEST_MAJOR_VERSION}.Y(.Z) -> latest-candidate
# release-X.Y(.Z) -> vX-candidate
if [ "${GITHUB_REF_NAME}" = "main" ]; then
BRANCH="latest-edge"
elif [[ "${GITHUB_REF_NAME}" =~ ^v[0-9]+-edge$ ]]; then
BRANCH="${GITHUB_REF_NAME}"
elif [[ "${GITHUB_REF_NAME}" =~ ^release-${LATEST_MAJOR_VERSION}\.[0-9]+(\.[0-9]+)?$ ]]; then
BRANCH="latest-candidate"
elif [[ "${GITHUB_REF_NAME}" =~ ^release-([0-9]+)\.[0-9]+(\.[0-9]+)?$ ]]; then
BRANCH="v${BASH_REMATCH[1]}-candidate"
else
echo "ERROR: Unsupported GITHUB_REF_NAME pattern: ${GITHUB_REF_NAME}" >&2
exit 1
fi
# Determine snap version and grade based on edge or candidate.
grade="devel"
if [[ "${BRANCH}" == *"-candidate" ]]; then
versionString="${version}-${localRev:0:7}"
grade="stable"
else
versionString="git-${localRev:0:7}"
fi
cd "${GITHUB_WORKSPACE}/snap"
# Fail unless exactly one `version: git` line exists, then replace it.
match_count="$(grep -cxF 'version: git' snapcraft.yaml || true)"
if [ "${match_count}" -ne 1 ]; then
echo "ERROR: Expected exactly one 'version: git' line in snapcraft.yaml, found ${match_count}" >&2
exit 1
fi
sed -i -e "s/^version: git$/version: ${versionString}/" snapcraft.yaml
if [ "${grade}" = "stable" ]; then
# Fail unless exactly one `grade: devel` line exists, then replace it.
match_count="$(grep -cxF 'grade: devel' snapcraft.yaml || true)"
if [ "${match_count}" -ne 1 ]; then
echo "ERROR: Expected exactly one 'grade: devel' line in snapcraft.yaml, found ${match_count}" >&2
exit 1
fi
sed -i -e "s/^grade: devel$/grade: stable/" snapcraft.yaml
fi
git add snapcraft.yaml
git commit --quiet -s -m "Automatic upstream build (${BRANCH})" -m "Upstream commit: ${localRev} (version: ${versionString})"
git show
# Pack all objects and generate a bitmap index
# right before the push so that pack generation benefits from full bitmap coverage.
git config --local pack.useBitmaps true
git gc --prune=now
git push --quiet --force launchpad HEAD:"${BRANCH}"
# Unload the SSH key from the agent now that the push is done, to
# prevent accidental usage in any subsequent steps within this job.
ssh-add -D