forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
380 lines (332 loc) · 12 KB
/
ci.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
name: CI
on: [push, pull_request]
jobs:
build-fast-kernel:
runs-on: ubuntu-22.04
steps:
- name: Checkout testing repository in root folder
uses: actions/checkout@v4
with:
repository: LabNConsulting/iptfs-dev
- name: Checkout source repository under linux
uses: actions/checkout@v4
with:
path: linux
- name: Install build depencies
run: |
sudo apt-get update -y
sudo apt-get install -y ccache device-tree-compiler libelf-dev xz-utils
- name: Kernel build cache
id: linux-cache
uses: actions/cache@v4
with:
path: output-linux
# We need a unique key name in order for new versions to save
key: ${{ runner.os }}-kernel-${{ hashFiles('linux-fast.config', 'output-linux/**/*.[ch]') }}
restore-keys: |
key: ${{ runner.os }}-kernel-
- name: Build kernel
run: |
set -x
if [ -d output-linux ]; then
echo "Cache found, checking for config difference"
# If the kernel config is changed just wipe the cache
if ! diff -q -u1 linux-fast.config output-linux/.config -I '^[ \t]*#' -I '^[ \t]*$' 2>/dev/null; then
echo "Kernel configs differ erasing cache"
rm -rf output-linux
fi
fi
export CCACHE_DIR=$PWD/output-linux/.ccache
if [ ! -d output-linux ]; then
echo "Creating new output directory"
mkdir output-linux
cp linux-fast.config output-linux/.config
fi
cd output-linux
ccache -z
KBUILD_BUILD_TIMESTAMP='' make CC="ccache gcc" LINUXCONFIG=linux-fast.config O=$PWD -j2 -C ../linux
ccache -sz
[ -e arch/x86/boot/bzImage ] && cp arch/x86/boot/bzImage ..
# Ccache keeps it's own objects
# make clean
- name: Archive kernel bzImage
uses: actions/upload-artifact@v4
with:
name: kernel-bzImage
path: bzImage
retention-days: 1
build-cov-kernel:
runs-on: ubuntu-22.04
steps:
- name: Checkout testing repository in root folder
uses: actions/checkout@v4
with:
repository: LabNConsulting/iptfs-dev
- name: Checkout source repository under linux
uses: actions/checkout@v4
with:
ref: iptfs-ci
path: linux
- name: Install build depencies
run: |
sudo apt-get update -y
sudo apt-get install -y ccache device-tree-compiler libelf-dev xz-utils
- name: Coverage kernel build cache
id: linux-cov-cache
uses: actions/cache@v4
with:
path: output-linux
# We need a unique key name in order for new versions to save
key: ${{ runner.os }}-cov-kernel-${{ hashFiles('linux-cov.config', 'output-linux/**/*.[ch]') }}
restore-keys: |
key: ${{ runner.os }}-cov-kernel-
- name: Build coverage kernel
run: |
set -x
if [ -d output-linux ]; then
echo "Cache found, checking for config difference"
# If the kernel config is changed just wipe the cache
if ! diff -q -u1 linux-cov.config output-linux/.config -I '^[ \t]*#' -I '^[ \t]*$' 2>/dev/null; then
echo "Kernel configs differ erasing cache"
rm -rf output-linux
fi
fi
export CCACHE_DIR=$PWD/output-linux/.ccache
if [ ! -d output-linux ]; then
echo "Creating new output directory"
mkdir output-linux
cp linux-cov.config output-linux/.config
fi
cd output-linux
ccache -z
KBUILD_BUILD_TIMESTAMP='' make CC="ccache gcc" LINUXCONFIG=linux-cov.config O=$PWD -j2 -C ../linux
ccache -sz
[ -e arch/x86/boot/bzImage ] && cp arch/x86/boot/bzImage ..
# Ccache keeps it's own objects
# We want the objects and images too for now, restroy once we know
# coverage works
# make clean
- name: Archive coverage kernel bzImage
uses: actions/upload-artifact@v4
with:
name: kernel-cov-bzImage
path: bzImage
retention-days: 1
build-rootfs:
runs-on: ubuntu-22.04
timeout-minutes: 600
steps:
- name: Checkout testing repository in root folder
uses: actions/checkout@v4
with:
repository: LabNConsulting/iptfs-dev
- name: Checkout kernel repository
uses: actions/checkout@v4
with:
path: linux
- name: Checkout other repos
run: make setup SHALLOW_CLONE=1
- name: Install build depencies
run: |
sudo apt-get update -y
sudo apt-get install -y device-tree-compiler libelf-dev
- name: Buildroot Build Cache
id: buildroot-cache
uses: actions/cache@v4
with:
path: |
output-buildroot
root-key
root-key.pub
key: ${{ runner.os }}-br-${{ hashFiles('buildroot-ci.config', 'buildroot/dl/**', 'output-buildroot/build/linux-custom/.config', 'output-buildroot/build/linux-custom/**/*.c', 'output-buildroot/build/linux-custom/**/*.h', 'root-key', 'root-key.pub') }}
restore-keys: |
key: ${{ runner.os }}-br-
- name: Build Rootfs
timeout-minutes: 540
run: |
set -x
if [ -f output-buildroot.tar.xz ] || [ -f output-buildroot.tar.gz ]; then
echo "Cache found, extracting"
if [ -f output-buildroot.tar.xz ]; then
tar -xpJf output-buildroot.tar.xz
else
tar -xpzf output-buildroot.tar.gz
fi
# If the buildroot config is changed just wipe the cache
if ! diff -q -u1 buildroot-ci.config output-buildroot/.config -I '^[ \t]*#' -I '^[ \t]*$' 2>/dev/null; then
echo "Buildroot configs differ erasing cache"
rm -rf output-buildroot output-buildroot.tar.gz
fi
fi
if [ ! -d output-buildroot ]; then
echo "Creating new output directory"
mkdir -p output-buildroot
cp -p buildroot-ci.config output-buildroot/.config
else
make -C buildroot -j6 V=0 O=$PWD/output-buildroot iproute2-dirclean
fi
# make rootfs
echo "Starting build: $(date)"
make -C buildroot -j6 V=1 O=$PWD/output-buildroot LOCALVERSION='' > build-buildroot.txt 2>&1
echo "Build complete: $(date)"
- name: Archive buildroot build log
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: buildroot-build-log
path: build-buildroot.txt
retention-days: 30
if-no-files-found: error
- name: Archive buildroot rootfs.cpio.gz
uses: actions/upload-artifact@v4
with:
name: rootfs-compressed-cpio
path: output-buildroot/images/rootfs.cpio.gz
retention-days: 1
if-no-files-found: error
- name: Archive buildroot root-key
uses: actions/upload-artifact@v4
with:
name: root-key
path: |
root-key
root-key.pub
retention-days: 1
if-no-files-found: error
test:
runs-on: ubuntu-22.04
needs: ["build-cov-kernel", "build-rootfs"]
steps:
- name: Checkout testing repository in root folder
uses: actions/checkout@v4
with:
repository: LabNConsulting/iptfs-dev
- name: Checkout kernel repository
uses: actions/checkout@v4
with:
path: linux
- name: Install test depencies
run: |
sudo apt-get update -y
sudo apt-get install -y lcov qemu-system-x86 socat
sudo python3 -m pip install -U munet pytest pytest-asyncio scapy
#
# For coverage data, extract the source and full build to get the gcno
# files.
#
- name: Restore coverage kernel build
id: linux-cov-cache-restore
uses: actions/cache/restore@v4
with:
path: output-linux
# We need a unique key name in order for new versions to save
key: ${{ runner.os }}-cov-kernel-${{ hashFiles('linux-cov.config', 'output-linux/**/*.[ch]') }}
restore-keys: |
key: ${{ runner.os }}-cov-kernel-
#
# We only need to artifacts for buildroot
#
- name: Fetch buildroot rootfs.cpio.gz archive
uses: actions/download-artifact@v4
with:
name: rootfs-compressed-cpio
- name: Fetch root-key
uses: actions/download-artifact@v4
with:
name: root-key
# Would be nice to loop this w/ and w/o coverage
- name: Prep tests
run: |
test -f output-linux/arch/x86/boot/bzImage
mkdir -p output-buildroot/images/
mv rootfs.cpio.gz output-buildroot/images/
mkdir -p test-logs
- name: Print the environment under sudo
run: |
sudo -E env
qemu-system-x86_64 --version
munet --version
- name: Config test
run: |
set -e
set -o pipefail
tmpf=test-logs/results-config.txt
sudo -E env CI=$CI python3 -m pytest -s --coverage --cov-build-dir=$PWD/output-linux tests/config |& tee $tmpf
grep -qvz SKIPPED $tmpf
- name: Errors test
run: |
set -e
set -o pipefail
tmpf=test-logs/results-errors.txt
sudo -E env CI=$CI python3 -m pytest -s --coverage --cov-build-dir=$PWD/output-linux tests/errors |& tee $tmpf
grep -qvz SKIPPED $tmpf
- name: Simple test
run: |
set -e
set -o pipefail
tmpf=test-logs/results-simplenet.txt
sudo -E env CI=$CI python3 -m pytest -s --coverage --cov-build-dir=$PWD/output-linux tests/simplenet |& tee $tmpf
grep -qvz SKIPPED $tmpf
# Restore longer running test once working
- name: UT packet test
run: |
set -e
set -o pipefail
tmpf=test-logs/results-utpkt.txt
sudo python3 -m pytest -s --coverage --cov-build-dir=$PWD/output-linux tests/utpkt |& tee $tmpf
grep -qvz SKIPPED $tmpf
- name: Extract coverage data
if: ${{ always() }}
run: |
make ci-extract-cov
ls -l ./coverage.info
mv ./coverage.info linux/coverage.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
disable_search: true
fail_ci_if_error: false
# plugin: null
# file: ./linux/coverage.info
flags: unittests
root_dir: ./linux
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
- name: Collect test logs
if: ${{ always() }}
run: |
sudo find /tmp/unet-test -name 'gcov-data.tgz' -exec rm {} +
sudo find /tmp/unet-test -type s -exec rm {} +
sudo tar -C /tmp/unet-test -cf - . | tar -C test-logs -xf -
tar -cjf test-logs.tar.bz2 test-logs
- name: Archive test logs tarball
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: test-logs-tar
path: test-logs.tar.bz2
deploy:
runs-on: ubuntu-22.04
if: startsWith(github.ref, 'refs/tags/')
needs: ["build-fast-kernel", "build-rootfs", "test"]
steps:
- name: Download kernel bzImage
uses: actions/download-artifact@v4
with:
name: kernel-bzImage
- name: Download buildroot rootfs.cpio.gz
uses: actions/download-artifact@v4
with:
name: rootfs-compressed-cpio
- name: Downlaod root-key
uses: actions/download-artifact@v4
with:
name: root-key
- name: Deploy
uses: softprops/action-gh-release@v1
with:
files: |
bzImage
root-key
root-key.pub
rootfs.cpio.gz