forked from aarron-lee/hid-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
271 lines (243 loc) · 6.98 KB
/
.gitlab-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
# vim: set expandtab shiftwidth=2 tabstop=8 textwidth=0:
.templates_sha: &template_sha d03cddbcff35f26861429fc816c00323f48e99af # see https://docs.gitlab.com/ee/ci/yaml/#includefile
include:
# Fedora container builder template
- project: 'freedesktop/ci-templates'
ref: *template_sha
file:
- '/templates/fedora.yml'
variables:
PYTHON_VERSION: '3.9'
PYTHON: python$PYTHON_VERSION
PIP: pip$PYTHON_VERSION
TEST_PACKAGES: 'python3.9 python3.10 python3.11 python3 make jq systemd-udev libevdev'
TEST_EXEC: > # multi-line yaml that replaces new lines by spaces
$PYTHON -m ensurepip --upgrade;
$PYTHON -m pip install --upgrade pip;
$PIP install hatch\
ruff \
attrs \
parse \
pyudev \
pytest \
libevdev \
click \
pyyaml \
pytest-retry \
pytest_tap \
pytest-xdist \
typing_extensions
BUILD_PACKAGES: >
file
git-core
gcc
gcc-c++
diffutils
make
flex
bison
sparse
bc
xz
findutils
hostname
elfutils-libelf-devel
openssl-devel
perl-Term-ANSIColor
perl-Encode
jq
FDO_DISTRIBUTION_VERSION: 39
FDO_UPSTREAM_REPO: 'libevdev/hid-tools'
TEST_CONTAINER_TAG: '2023-12-05.1'
BUILD_CONTAINER_TAG: '2023-05-25.1'
FDO_DISTRIBUTION_TAG: $TEST_CONTAINER_TAG
KERNEL_VERSION: '6.6'
stages:
- sanity check
- prep
- build
- test
- analysis
fail-if-fork-is-not-public:
stage: sanity check
script:
- |
if [ $CI_PROJECT_VISIBILITY != "public" ]; then
echo "*************************************************************************************"
echo "Project visibility must be set to 'public'"
echo "Change this in $CI_PROJECT_URL/edit under 'Visibility, project features, permissions'"
echo "*************************************************************************************"
exit 1
fi
except:
- main@libevdev/hid-tools
- master@libevdev/hid-tools
test container prep:
extends:
- .fdo.container-build@fedora
stage: prep
variables:
GIT_STRATEGY: none
FDO_DISTRIBUTION_PACKAGES: $TEST_PACKAGES
FDO_DISTRIBUTION_EXEC: $TEST_EXEC
.build_variables:
variables:
FDO_DISTRIBUTION_TAG: $BUILD_CONTAINER_TAG
FDO_DISTRIBUTION_PACKAGES: $BUILD_PACKAGES
FDO_REPO_SUFFIX: build-kernel
.b2c_kernel_url:
before_script: &b2c-kernel-url
- export KERNEL_URL=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/kernel-$(arch)/v$KERNEL_VERSION/bzImage
build container prep:
extends:
- .fdo.container-build@fedora
- .build_variables
stage: prep
variables:
GIT_STRATEGY: none
rebuild kernel:
extends:
- .fdo.suffixed-image@fedora
- .build_variables
stage: build
needs:
- build container prep
script:
- echo -e "section_start:`date +%s`:check\r\e[0KCheck for existing bzImage"
- *b2c-kernel-url
- echo $KERNEL_URL
- |
curl --header "JOB-TOKEN: $CI_JOB_TOKEN" -LO $KERNEL_URL
# the kernel is already published, abort
# -> if the file type is not 'kernel', file|grep
# is true, otherwise, exit 0
- file bzImage | grep -v kernel || exit 0
- echo -e "section_end:`date +%s`:check\r\e[0K"
- echo -e "section_start:`date +%s`:download\r\e[0KDownload and unpack kernel sources"
- curl -LO https://cdn.kernel.org/pub/linux/kernel/v${KERNEL_VERSION/.*/}.x/linux-${KERNEL_VERSION}.tar.xz
- tar xf linux-${KERNEL_VERSION}.tar.xz
- echo -e "section_end:`date +%s`:download\r\e[0K"
- cd linux-${KERNEL_VERSION}
- echo -e "section_start:`date +%s`:build[collapsed=true]\r\e[0KBuild the kernel"
- ../.gitlab-ci/make-config.sh
- make -j${FDO_CI_CONCURRENT:-4} bzImage
- echo -e "section_end:`date +%s`:build\r\e[0K"
- echo -e "section_start:`date +%s`:upload\r\e[0KUpload the kernel"
- |
curl --header "JOB-TOKEN: $CI_JOB_TOKEN" \
--upload-file ./arch/$(arch)/boot/bzImage\
$KERNEL_URL | tee upload.txt
# check that the upload was successful
- grep '201 Created' upload.txt
- echo -e "section_end:`date +%s`:upload\r\e[0K"
.default_image:
extends:
- .fdo.distribution-image@fedora
needs:
- test container prep
python formatting:
extends: .default_image
stage: build
script:
- ruff format --check .
python lint:
extends: .default_image
stage: build
script:
- hatch run types:check
install:
extends: .default_image
stage: build
script:
- $PIP install . --verbose
pytest:
extends:
- .fdo.b2c-image@fedora
tags:
- kvm
stage: test
needs:
- python formatting
- rebuild kernel
script:
- *b2c-kernel-url
- export B2C_KERNEL=$KERNEL_URL
- echo "[pytest]" > pytest.ini
- echo "junit_family=xunit2" >> pytest.ini
- export B2C_COMMAND="hatch run +py=$PYTHON_VERSION test:pytest -v --junitxml=junit-$CI_JOB_NAME_SLUG.xml tests"
- rm -f junit-$CI_JOB_NAME.xml
- /app/boot2container
artifacts:
name: "qemu-pytest-logs-$CI_JOB_NAME"
when: always
expire_in: 1 week
paths:
- junit-*.xml
reports:
junit: junit-*.xml
parallel:
matrix:
- PYTHON_VERSION:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
pytest kernel:
extends:
- .fdo.b2c-image@fedora
tags:
- kvm
stage: test
needs:
- python formatting
- rebuild kernel
script:
- *b2c-kernel-url
- export B2C_KERNEL=$KERNEL_URL
- echo "[pytest]" > pytest.ini
- echo "junit_family=xunit2" >> pytest.ini
- export B2C_COMMAND="hatch run +py=$PYTHON_VERSION test:pytest -v --udevd --junitxml=junit-$CI_JOB_NAME_SLUG.xml --retries 2"
- rm -f junit-$CI_JOB_NAME.xml
- set +e # Disable exit on error
- /app/boot2container ; echo $? > .exit_code
- set -e # Re-enable exit on error
- cat '.exit_code'
# pytest uses 2 and above for any errors outside the tests themselves
- if [[ `cat .exit_code` -gt 1 ]] ;
then
exit 1 ;
fi
artifacts:
name: "qemu-pytest-logs-$CI_JOB_NAME"
when: always
expire_in: 1 week
paths:
- junit-*.xml
reports:
junit: junit-*.xml
pytest errors:
extends:
- .fdo.distribution-image@fedora
stage: analysis
needs:
- pytest kernel
script:
- $PIP install yq
- errors=`cat junit-*.xml | xq -r '.testsuites.testsuite."@errors"'`
- test $errors -ne 0 && echo "pytest encountered $errors errors, please fix"
- echo "See the previous stage for test logs"
- exit $errors
allow_failure: false
pytest failures:
extends:
- .fdo.distribution-image@fedora
stage: analysis
needs:
- pytest kernel
script:
- $PIP install yq
- failures=`cat junit-*.xml | xq -r '.testsuites.testsuite."@failures"'`
- test $failures -ne 0 && echo "pytest encountered $failures test case failures"
- echo "See the previous stage for test logs"
- exit $failures
allow_failure: true