-
Notifications
You must be signed in to change notification settings - Fork 100
/
.gitlab-ci.yml
242 lines (217 loc) · 8.06 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
variables:
RELEASE_BRANCH: drbd-9.1
DRBD_VERSION_BASE: 9.1.0
DRBD9_TESTS_REF: master
BUILD_HELPERS_VERSION: 2c873ab6e6e6bb6ec83f571eeada63d54ff805b5
# we have to change the way GitLab CI clones the repository.
# by default, it is shallow, which gives us a wrong commit count when
# we do `git rev-list --count origin/master` below.
GIT_DEPTH: 0
GIT_STRATEGY: clone
GIT_SUBMODULE_STRATEGY: normal
stages:
- check
- build
- test
.setup-lbbuild:
before_script:
- . gitlab-utils.sh
- ci_prepare_tools
- ci_fetch_rq
- ci_fetch_lbbuildctl
- git clone --branch ${DRBD9_TESTS_REF} https://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}/drbd/drbd9-tests.git
- |
kernels_from_vms() {
rq -t < drbd9-tests/virter/vms.toml | \
jq -r '.vms[].metadata | .BuildDistribution + " " + .BuildKernel'
}
# parameters: [version]
# select all "build targets" for the given drbd version,
# ignoring some distros that always fail in CI anyway
all_kernels() {
local version="$1"
lbbuildctl build drbd --ci -v $version --arch amd64 --debug debugSpecJson | \
jq -r 'map(.image + " " + .aux_version) | unique[]' | \
grep -v ^sles12 | grep -v ^docker
}
# parameters: [version] [release] [rel-version] [kernels]
# kernels should be a string with lines with the format: "[distribution] [kernel version]"
drbd_build () {
local version="$1"
local release="$2"
local rel_version="$3"
local kernels="$4"
set -x
./.gitlab/drbd-prepare-release.sh "$version" "$release" "$rel_version"
make FORCE=1 PRESERVE_DEBIAN=1 REL_VERSION="$rel_version" tarball
curl -isSf -u $LINBIT_REGISTRY_USER:$LINBIT_REGISTRY_PASSWORD \
--upload-file drbd-*.tar.gz \
$LINBIT_REGISTRY_URL/repository/lbbuild-upstream/
echo "$kernels" | parallel --colsep ' ' -k -j24 \
lbbuildctl build drbd --arch amd64 --ci -v "$rel_version" --compat-only \
-e LINBIT_REGISTRY_USER=$LINBIT_REGISTRY_USER \
-e LINBIT_REGISTRY_PASSWORD=$LINBIT_REGISTRY_PASSWORD \
-e LINBIT_REGISTRY_URL=$LINBIT_REGISTRY_URL \
-d {1} -k {2}
pushd drbd/drbd-kernel-compat
local compat_hs
while read line; do
kver=${line#* } # everything after " " -> the kernel version
curl -fsSLO "$LINBIT_REGISTRY_URL/repository/drbd-compat/$rel_version/compat.h.$kver"
compat_hs+=("compat.h.$kver")
done <<< "$kernels"
./build_cocci_cache.sh ${compat_hs[@]}
popd
make -j $(nproc) -C drbd compat
make FORCE=1 PRESERVE_DEBIAN=1 REL_VERSION="$rel_version" tarball
curl -isSf -u $LINBIT_REGISTRY_USER:$LINBIT_REGISTRY_PASSWORD \
--upload-file drbd-*.tar.gz \
$LINBIT_REGISTRY_URL/repository/lbbuild-upstream/
local build_rc=0
echo "$kernels" | parallel --colsep ' ' -k -j24 --joblog parallel.log \
lbbuildctl build drbd --arch amd64 --ci -v "$rel_version" \
-e LINBIT_REGISTRY_USER=$LINBIT_REGISTRY_USER \
-e LINBIT_REGISTRY_PASSWORD=$LINBIT_REGISTRY_PASSWORD \
-e LINBIT_REGISTRY_URL=$LINBIT_REGISTRY_URL \
-d {1} -k {2} \
|| build_rc=$?
parse_joblog.py drbd parallel.log
if [ "$build_rc" -ne 0 ]; then
exit $build_rc
fi
set +x
}
# rules clause determining whether to build
.rules-build:
rules:
- if: $CI_MERGE_REQUEST_ID
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
check:coccicheck:
stage: check
extends: [ .rules-build ]
image: szeder/coccinelle:1.1.0-1
script:
- make coccicheck
check:check-compat:
stage: check
extends: [ .rules-build ]
image: szeder/coccinelle:1.1.0-1
script:
- make check-compat
check:checkpatch.pl:
stage: check
rules:
- if: $CI_MERGE_REQUEST_ID
image: perl:5
script:
- curl -sSLO https://raw.githubusercontent.com/torvalds/linux/master/scripts/checkpatch.pl
- chmod +x checkpatch.pl
- git fetch --no-tags origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
- base=$(git merge-base remotes/origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} HEAD)
- git diff --submodule=diff ${base}...HEAD -- drbd/{drbd-headers/{linux/,},linux/,}*\.[ch] > merge_request.diff
- ./checkpatch.pl --no-tree --ignore FILE_PATH_CHANGES merge_request.diff
build:for-tests:
stage: build
extends: [ .setup-lbbuild ]
rules:
- !reference [.rules-build, rules]
# Useful for building DRBD without opening a merge request
- if: $CI_PIPELINE_SOURCE == 'api'
# Used by the tests pipeline, if a DRBD branch build is required
- if: $CI_PIPELINE_SOURCE == 'pipeline'
# Useful for testing the downstream trigger used in the tests pipeline
- if: $CI_PIPELINE_SOURCE == 'trigger'
image: $LINBIT_DOCKER_REGISTRY/build-helpers:$BUILD_HELPERS_VERSION
script:
- if [ "$CI_COMMIT_BRANCH" = "$RELEASE_BRANCH" ]; then
- DRBD_VERSION=$DRBD_VERSION_BASE.latest
- DRBD_RELEASE=$(git rev-list --count "origin/$CI_COMMIT_BRANCH")
- else
- DRBD_VERSION=$DRBD_VERSION_BASE.$CI_COMMIT_SHA
- DRBD_RELEASE=1
- fi
- echo DRBD_VERSION=$DRBD_VERSION >> build.env
- |
# If the build is conditional and some packages already exist, skip the build.
# Then the purpose of this job is just to generate build.env.
if [ "$DRBD_BUILD_CONDITIONAL" = true ]; then
curl -fsSL "$LINBIT_REGISTRY_URL/service/rest/v1/search?repository=ci-yum&version=$DRBD_VERSION*" \
| grep -q name \
&& exit 0
fi
- drbd_build $DRBD_VERSION $DRBD_RELEASE $DRBD_VERSION "$(kernels_from_vms)"
artifacts:
reports:
dotenv: build.env
paths:
- drbd/drbd-kernel-compat/cocci_cache
# Make the variables accessible through the API. See:
# https://stackoverflow.com/questions/72202825/download-dotenv-job-artifact-via-gitlab-api
- build.env
when: always
expire_in: 1 week
needs: []
build:all:
stage: build
extends: [ .setup-lbbuild ]
rules:
- when: manual
allow_failure: true
image: $LINBIT_DOCKER_REGISTRY/build-helpers:$BUILD_HELPERS_VERSION
script:
- DRBD_VERSION=$DRBD_VERSION_BASE.$CI_COMMIT_SHA
- DRBD_RELEASE=1
- echo DRBD_VERSION=$DRBD_VERSION >> build.env
- drbd_build $DRBD_VERSION $DRBD_RELEASE $DRBD_VERSION "$(all_kernels $DRBD_VERSION)"
artifacts:
reports:
dotenv: build.env
paths:
- drbd/drbd-kernel-compat/cocci_cache
when: always
expire_in: 1 week
needs: []
.test:
tags:
- libvirt
cache:
paths:
- download
before_script:
- |
set -e
run_test() {
git clone --branch ${DRBD9_TESTS_REF} https://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}/drbd/drbd9-tests.git
. drbd9-tests/virter/version.env
curl -sSfL -u gitlab-ci-token:$CI_JOB_TOKEN $CI_SERVER_URL/linbit/build-helpers/-/archive/$BUILD_HELPERS_VERSION/ignored.tar.gz | tar -xvzf -
mv build-helpers-* build-helpers
. build-helpers/gitlab-utils.sh
ci_prepare_tools
ci_fetch_rq
ci_fetch_binary virter virter-$VIRTER_VERSION https://github.com/LINBIT/virter/releases/download/$VIRTER_VERSION/virter-linux-amd64
ci_fetch_binary vmshed vmshed-$VMSHED_VERSION https://github.com/LINBIT/vmshed/releases/download/$VMSHED_VERSION/vmshed-linux-amd64
export DRBD_TEST_DOCKER_IMAGE=$LINBIT_DOCKER_REGISTRY/drbd9-tests:latest
docker image pull $DRBD_TEST_DOCKER_IMAGE
export DRBD_VERSION=$DRBD_VERSION
export DRBD_UTILS_VERSION=9.0.0.latest-*
cd drbd9-tests
./virter/run-test.sh --out-dir=../tests-out "$@"
}
dependencies:
- build:for-tests
artifacts:
# provide a convenient name so that the downloaded artifacts can be identified
name: $CI_PROJECT_NAME-$CI_JOB_ID
paths:
- tests-out/
when: always
reports:
junit: tests-out/test-results/*.xml
needs:
- build:for-tests
test:
stage: test
extends: [ .test ]
rules:
- if: $CI_MERGE_REQUEST_ID
script: run_test