forked from canonical/snapd
-
Notifications
You must be signed in to change notification settings - Fork 1
432 lines (425 loc) · 17.7 KB
/
test.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
name: Tests
on:
pull_request:
branches: [ "master", "release/**" ]
push:
# we trigger runs on master branch, but we do not run spread on master
# branch, the master branch runs are just for unit tests + codecov.io
branches: [ "master","release/**" ]
jobs:
snap-builds:
runs-on: ubuntu-20.04
# only build the snap for pull requests, it's not needed on release branches
# or on master since we have launchpad build recipes which do this already
if: ${{ github.event_name == 'pull_request' }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Cache snapd snap build status
id: cache-snapd-build-status
uses: actions/cache@v1
with:
path: "${{ github.workspace }}/.test-results"
key: "${{ github.run_id }}-${{ github.job }}-results"
- name: Check cached snap build
id: cached-results
run: |
CACHE_RESULT_STAMP="${{ github.workspace }}/.test-results/snap-build-success"
echo "CACHE_RESULT_STAMP=$CACHE_RESULT_STAMP" >> $GITHUB_ENV
if [ -e "$CACHE_RESULT_STAMP" ]; then
has_cached_snap=0
while read name; do
has_cached_snap=1
# bring back artifacts from the cache
cp -v "$name" "${{ github.workspace }}"
done < <(find "$(dirname $CACHE_RESULT_STAMP)" -name "*.snap")
if [ "$has_cached_snap" = "1" ]; then
# we have restored an artifact from the cache
echo "::set-output name=already-ran::true"
fi
fi
- name: Build snapd snap
if: steps.cached-results.outputs.already-ran != 'true'
uses: snapcore/action-build@v1
with:
snapcraft-channel: 4.x/candidate
- name: Cache and check built artifact
run: |
mkdir -p $(dirname "$CACHE_RESULT_STAMP")
unsquashfs snapd*.snap meta/snap.yaml usr/lib/snapd/info
if cat squashfs-root/meta/snap.yaml | grep -q "version:.*dirty.*"; then
echo "PR produces dirty snapd snap version"
cat squashfs-root/usr/lib/snapd/dirty-git-tree-info.txt
exit 1
elif cat squashfs-root/usr/lib/snapd/info | grep -q "VERSION=.*dirty.*"; then
echo "PR produces dirty internal snapd info version"
cat squashfs-root/usr/lib/snapd/info
exit 1
fi
cp -v *.snap "$(dirname $CACHE_RESULT_STAMP)/"
- name: Uploading snapd snap artifact
uses: actions/upload-artifact@v2
with:
name: snap-files
path: "*.snap"
- name: Mark successful snap build
run: |
mkdir -p $(dirname "$CACHE_RESULT_STAMP")
touch "$CACHE_RESULT_STAMP"
unit-tests:
runs-on: ubuntu-20.04
env:
GOPATH: ${{ github.workspace }}
# Set PATH to ignore the load of magic binaries from /usr/local/bin And
# to use the go snap automatically. Note that we install go from the
# snap in a step below. Without this we get the GitHub-controlled latest
# version of go.
PATH: /snap/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:${{ github.workspace }}/bin
GOROOT: ""
GITHUB_PULL_REQUEST: ${{ github.event.number }}
strategy:
# we cache successful runs so it's fine to keep going
fail-fast: false
matrix:
gochannel:
- 1.13
- latest/stable
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
# needed for git commit history
fetch-depth: 0
# NOTE: checkout the code in a fixed location, even for forks, as this
# is relevant for go's import system.
path: ./src/github.com/snapcore/snapd
# Fetch base ref, needed for golangci-lint
- name: Fetching base ref ${{ github.base_ref }}
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd
git fetch origin ${{ github.base_ref }}:${{ github.base_ref }}
- name: Cache Debian dependencies
id: cache-deb-downloads
uses: actions/cache@v1
with:
path: /var/cache/apt
key: var-cache-apt-{{ hashFiles('**/debian/control') }}
- name: Run "apt update"
run: |
sudo apt update
- name: Download Debian dependencies
if: steps.cache-deb-downloads.outputs.cache-hit != 'true'
run: |
sudo apt clean
sudo apt build-dep -d -y ${{ github.workspace }}/src/github.com/snapcore/snapd
- name: Cache snapd test results
id: cache-snapd-test-results
uses: actions/cache@v1
with:
path: "${{ github.workspace }}/.test-results"
# must include matrix or things get racy, i.e. when latest/edge
# finishes after 1.9 it overrides the results from 1.9
key: "${{ github.run_id }}-${{ github.job }}-${{ matrix.gochannel }}-results"
- name: Check cached test results
id: cached-results
run: |
CACHE_RESULT_STAMP="${{ github.workspace }}/.test-results/${{ matrix.gochannel }}-success"
echo "CACHE_RESULT_STAMP=$CACHE_RESULT_STAMP" >> $GITHUB_ENV
if [ -e "$CACHE_RESULT_STAMP" ]; then
echo "::set-output name=already-ran::true"
fi
- name: Install Debian dependencies
if: steps.cached-results.outputs.cached-results != 'true'
run: |
sudo apt build-dep -y ${{ github.workspace }}/src/github.com/snapcore/snapd
# golang latest ensures things work on the edge
- name: Install the go snap
if: steps.cached-results.outputs.already-ran != 'true'
run: |
sudo snap install --classic --channel=${{ matrix.gochannel }} go
- name: Install ShellCheck as a snap
if: steps.cached-results.outputs.already-ran != 'true'
run: |
sudo apt-get remove --purge shellcheck
sudo snap install shellcheck
- name: Get C vendoring
run: cd ${{ github.workspace }}/src/github.com/snapcore/snapd/c-vendor && ./vendor.sh
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
if: ${{ matrix.gochannel == 'latest/stable' }}
with:
# version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest`
# to use the latest version
version: v1.40.0
working-directory: ./src/github.com/snapcore/snapd
# show only new issues
# use empty path prefix to make annotations work
args: --new-from-rev=${{ github.base_ref }} --path-prefix=
# skip all additional steps
skip-go-installation: true
skip-pkg-cache: true
skip-build-cache: true
# XXX: does no work with working-directory
# only-new-issues: true
- name: Run static checks
if: steps.cached-results.outputs.already-ran != 'true'
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1
# run gofmt checks only with Go 1.13
if ! echo "${{ matrix.gochannel }}" | grep -E '1\.13' ; then
# and skip with other versions
export SKIP_GOFMT=1
echo "Formatting checks will be skipped due to the use of Go version ${{ matrix.gochannel }}"
fi
sudo apt-get install -y python3-yamlordereddictloader
./run-checks --static
- name: Build C
if: steps.cached-results.outputs.already-ran != 'true'
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd/cmd/
./autogen.sh
make -j2
- name: Build Go
if: steps.cached-results.outputs.already-ran != 'true'
run: |
go build github.com/snapcore/snapd/...
- name: Test C
if: steps.cached-results.outputs.already-ran != 'true'
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd/cmd/ && make check
- name: Reset code coverage data
if: steps.cached-results.outputs.already-ran != 'true'
run: |
rm -rf ${{ github.workspace }}/.coverage/
- name: Test Go
if: steps.cached-results.outputs.already-ran != 'true'
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1
./run-checks --unit
- name: Test Go (SNAPD_DEBUG=1)
if: steps.cached-results.outputs.already-ran != 'true'
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1
SKIP_DIRTY_CHECK=1 SNAPD_DEBUG=1 ./run-checks --unit
- name: Test Go (withbootassetstesting)
if: steps.cached-results.outputs.already-ran != 'true'
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1
SKIP_DIRTY_CHECK=1 GO_BUILD_TAGS=withbootassetstesting ./run-checks --unit
- name: Test Go (nosecboot)
if: steps.cached-results.outputs.already-ran != 'true'
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1
echo "Dropping github.com/snapcore/secboot"
# use govendor remove so that a subsequent govendor sync does not
# install secboot again
# ${{ github.workspace }}/bin/govendor remove github.com/snapcore/secboot
# ${{ github.workspace }}/bin/govendor remove +unused
SKIP_DIRTY_CHECK=1 GO_BUILD_TAGS=nosecboot ./run-checks --unit
- name: Test Go (faultinject)
if: steps.cached-results.outputs.already-ran != 'true'
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1
SKIP_DIRTY_CHECK=1 GO_BUILD_TAGS=faultinject ./run-checks --unit
- name: Merge coverage results
if: ${{ steps.cached-results.outputs.already-ran != 'true' && matrix.gochannel != 'latest/stable' }}
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1
go install github.com/makholm/covertool
covertool merge -o .coverage/all.cov .coverage/coverage*.cov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
# uploading to codecov occasionally fails, so continue running the test
# workflow regardless of the upload
continue-on-error: true
if: ${{ steps.cached-results.outputs.already-ran != 'true' && matrix.gochannel != 'latest/stable' }}
with:
fail_ci_if_error: true
flags: unittests
name: codecov-umbrella
files: .coverage/all.cov
verbose: true
- name: Cache successful run
run: |
mkdir -p $(dirname "$CACHE_RESULT_STAMP")
touch "$CACHE_RESULT_STAMP"
spread:
needs: [unit-tests]
# have spread jobs run on master on PRs only, but on both PRs and pushes to
# release branches
if: ${{ github.event_name != 'push' || github.ref != 'refs/heads/master' }}
runs-on: self-hosted
strategy:
# FIXME: enable fail-fast mode once spread can cancel an executing job.
# Disable fail-fast mode as it doesn't function with spread. It seems
# that cancelling tasks requires short, interruptible actions and
# interrupting spread, notably, does not work today. As such disable
# fail-fast while we tackle that problem upstream.
fail-fast: false
matrix:
system:
- amazon-linux-2-64
- arch-linux-64
- centos-7-64
- centos-8-64
- debian-10-64
- debian-11-64
- debian-sid-64
- fedora-34-64
- fedora-35-64
- opensuse-15.3-64
- opensuse-tumbleweed-64
- ubuntu-14.04-64
- ubuntu-16.04-64
- ubuntu-18.04-32
- ubuntu-18.04-64
- ubuntu-20.04-64
- ubuntu-21.10-64
- ubuntu-22.04-64
- ubuntu-core-16-64
- ubuntu-core-18-64
- ubuntu-core-20-64
- ubuntu-secboot-20.04-64
steps:
- name: Cleanup job workspace
id: cleanup-job-workspace
run: |
rm -rf "${{ github.workspace }}"
mkdir "${{ github.workspace }}"
- name: Checkout code
uses: actions/checkout@v2
with:
# spread uses tags as delta reference
fetch-depth: 0
- name: Cache snapd test results
id: cache-snapd-test-results
uses: actions/cache@v1
with:
path: "${{ github.workspace }}/.test-results"
key: "${{ github.run_id }}-${{ github.job }}-${{ matrix.system }}-results"
- name: Check cached test results
id: cached-results
run: |
CACHE_RESULT_STAMP="${{ github.workspace }}/.test-results/${{ matrix.system }}-success"
echo "CACHE_RESULT_STAMP=$CACHE_RESULT_STAMP" >> $GITHUB_ENV
if [ -e "$CACHE_RESULT_STAMP" ]; then
echo "::set-output name=already-ran::true"
fi
- name: Run spread tests
if: "!contains(github.event.pull_request.labels.*.name, 'Skip spread') && steps.cached-results.outputs.already-ran != 'true'"
env:
SPREAD_GOOGLE_KEY: ${{ secrets.SPREAD_GOOGLE_KEY }}
run: |
# Register a problem matcher to highlight spread failures
echo "::add-matcher::.github/spread-problem-matcher.json"
# "pipefail" ensures that a non-zero status from the spread is
# propagated; and we use a subshell as this option could trigger
# undesired changes elsewhere
(set -o pipefail; spread -abend google:${{ matrix.system }}:tests/... | tee spread.log)
- name: Cache successful run
run: |
mkdir -p $(dirname "$CACHE_RESULT_STAMP")
touch "$CACHE_RESULT_STAMP"
- name: Discard spread workers
if: always()
run: |
shopt -s nullglob;
for r in .spread-reuse.*.yaml; do
spread -discard -reuse-pid="$(echo "$r" | grep -o -E '[0-9]+')";
done
- name: report spread errors
if: always()
run: |
if [ -e spread.log ]; then
echo "Running spread log analyzer"
./tests/lib/external/snapd-testing-tools/utils/log-parser spread.log --print-detail error-debug --output spread-results.json --cut 100
while IFS= read -r line; do
if [ ! -z "$line" ]; then
echo "Reporting spread error..."
./tests/lib/tools/report-mongodb --db-name snapd --db-collection spread_errors "$line"
fi
done <<< $(jq -cr '.[] | select( .type == "info") | select( (.info_type == "Error") or (.info_type == "Debug"))' spread-results.json)
else
echo "No spread log found, skipping errors reporting"
fi
spread-nested:
needs: [unit-tests]
# have spread jobs run on master on PRs only, but on both PRs and pushes to
# release branches
if: ${{ github.event_name != 'push' || github.ref != 'refs/heads/master' }}
runs-on: self-hosted
strategy:
# FIXME: enable fail-fast mode once spread can cancel an executing job.
# Disable fail-fast mode as it doesn't function with spread. It seems
# that cancelling tasks requires short, interruptible actions and
# interrupting spread, notably, does not work today. As such disable
# fail-fast while we tackle that problem upstream.
fail-fast: false
matrix:
system:
- ubuntu-16.04-64
- ubuntu-18.04-64
- ubuntu-20.04-64
steps:
- name: Cleanup job workspace
id: cleanup-job-workspace
run: |
rm -rf "${{ github.workspace }}"
mkdir "${{ github.workspace }}"
- name: Checkout code
uses: actions/checkout@v2
- name: Cache snapd test results
id: cache-snapd-test-results
uses: actions/cache@v1
with:
path: "${{ github.workspace }}/.test-results"
key: "${{ github.run_id }}-${{ github.job }}-${{ matrix.system }}-nested-results"
- name: Check cached test results
id: cached-results
run: |
CACHE_RESULT_STAMP="${{ github.workspace }}/.test-results/${{ matrix.system }}-nested-success"
echo "CACHE_RESULT_STAMP=$CACHE_RESULT_STAMP" >> $GITHUB_ENV
if [ -e "$CACHE_RESULT_STAMP" ]; then
echo "::set-output name=already-ran::true"
fi
- name: Run spread tests
# run if the commit is pushed to the release/* branch or there is a 'Run
# nested' label set on the PR
if: "(contains(github.event.pull_request.labels.*.name, 'Run nested') || contains(github.ref, 'refs/heads/release/')) && steps.cached-results.outputs.already-ran != 'true'"
env:
SPREAD_GOOGLE_KEY: ${{ secrets.SPREAD_GOOGLE_KEY }}
run: |
# Register a problem matcher to highlight spread failures
echo "::add-matcher::.github/spread-problem-matcher.json"
export NESTED_BUILD_SNAPD_FROM_CURRENT=true
export NESTED_ENABLE_KVM=true
# "pipefail" ensures that a non-zero status from the spread is
# propagated; and we use a subshell as this option could trigger
# undesired changes elsewhere
(set -o pipefail; spread -abend google-nested:${{ matrix.system }}:tests/nested/... | tee spread.log)
- name: Cache successful run
run: |
mkdir -p $(dirname "$CACHE_RESULT_STAMP")
touch "$CACHE_RESULT_STAMP"
- name: Discard spread workers
if: always()
run: |
shopt -s nullglob;
for r in .spread-reuse.*.yaml; do
spread -discard -reuse-pid="$(echo "$r" | grep -o -E '[0-9]+')";
done
- name: report spread errors
if: always()
run: |
if [ -e spread.log ]; then
echo "Running spread log analyzer"
./tests/lib/external/snapd-testing-tools/utils/log-parser spread.log --print-detail error --output spread-results.json --cut 100
while IFS= read -r line; do
if [ ! -z "$line" ]; then
echo "Reporting spread error..."
./tests/lib/tools/report-mongodb --db-name snapd --db-collection spread_errors "$line"
fi
done <<< $(jq -cr '.[] | select( .type == "info") | select( .info_type == "Error")' spread-results.json)
else
echo "No spread log found, skipping errors reporting"
fi