-
Notifications
You must be signed in to change notification settings - Fork 40
/
.gitlab-ci.yml
314 lines (294 loc) · 10.3 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
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
variables:
GITLAB_REPO: [email protected]:maix_sw/k230_sdk_release.git
GITHUB_REPO: [email protected]:kendryte/k230_sdk.git
GITEE_REPO: [email protected]:kendryte/k230_sdk.git
CONF: k230_evb_defconfig
IMAGE_DIR: images
IMAGE_NAME: "*_nncase_*.img.gz"
RELEASE_DIR: sdk_images
default:
image: ai.b-bug.org:5000/k230_sdk:latest
interruptible: true
# download dir publish with tag
download_dir_release:
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG =~ /^v\d+\.\d+.*$/
extends:
- .setup_env
- .release_download_dir
# k230_sdk.tar.gz github zip publish with tag
sdk_github_zip:
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG =~ /^v\d+\.\d+.*$/
extends:
- .setup_env
- .sync_sdk_github_zip
# image publish with tag
release_image_publish:
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG =~ /^v\d+\.\d+.*$/
parallel:
matrix:
- CONF: [k230_evb_defconfig, k230_canmv_defconfig]
extends:
- .setup_env
- .sync_release_image
# MR merged
merge_sync:
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"
extends:
- .setup_env
- .sync_github_gitee
# tag push
tag_sync:
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG =~ /^v\d+\.\d+.*$/
extends:
- .setup_env
- .sync_github_gitee
# auto sync
schedule_sync:
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
extends:
- .setup_env
- .sync_github_gitee
# manual sync
manual_sync:
rules:
- if: '$CI_PIPELINE_SOURCE == "web"'
when: always
extends:
- .setup_env
- .sync_github_gitee
# new MR open
build-image:
variables:
DST_BASE: /data1/k230/gitlab-ci/${IMAGE_DIR}/${CI_PROJECT_NAME}
SRC_DIR: ./output/${CONF}/images
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "dev"
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"
stage: build
tags:
- k230_sdk
timeout: 30m
extends:
- .setup_env
script:
- !reference [.common, build_image]
- !reference [.common, save_image]
artifacts:
reports:
dotenv: build.env
.setup_env:
before_script:
- echo '----------Build ENV Prepare----------'
- echo 'Add SSH KEY for Multiple repo'
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_PRIVATE_KEY" | ssh-add - > ~/.ssh/id_ed25519 || exit 1
- '[[ -f /.dockerenv ]] && echo -e "Host *\n StrictHostKeyChecking no\n" > ~/.ssh/config'
- echo $SHELL
- echo "increate ssh timeout for github"
- echo " ServerAliveInterval 30" >> ~/.ssh/config
- echo " ServerAliveCountMax 60" >> ~/.ssh/config
- echo " TCPKeepAlive yes" >> ~/.ssh/config
- cat ~/.ssh/config
- whoami
- uptime
- pwd
- uname -a
- cat /etc/issue
- echo $CI_PROJECT_DIR
- echo $CI_PROJECT_NAME
- echo '----------set git config ----------'
- echo "${GITLAB_USER_EMAIL}"
- echo "${GITLAB_USER_NAME}"
- git config --global user.email "${GITLAB_USER_EMAIL}"
- git config --global user.name "${GITLAB_USER_NAME}"
- git config --global --add safe.directory $CI_PROJECT_DIR
.sync_github_gitee:
timeout: 30m
retry: 2
tags:
- k230_sdk
script:
- cd $CI_PROJECT_DIR
- ls -alht
- rm -rf ./k230_sdk/
- git clone ${GITLAB_REPO} k230_sdk || exit 1
- cd k230_sdk || exit 1
- pwd
- git checkout main
- git branch -a
- git status
- echo '---pull latest main branch---'
- git pull origin main
- echo '---fetch all tags---'
- git fetch --tags
- git remote add github ${GITHUB_REPO}
- git remote add gitee ${GITEE_REPO}
- git remote -v
- git branch -a
- git status
- echo "---push to gitee---"
- git push --atomic --tags -u -f gitee main || git push --atomic --tags -u -f gitee main
- echo "---push to github---"
- git push --atomic --tags -u -f github main || git push --atomic --tags -u -f github main || git push --atomic --tags -u -f github main
.release_download_dir:
timeout: 60m
retry: 2
tags:
- k230_sdk
script:
- cd $CI_PROJECT_DIR
- ls -alht
- wget -qc https://ai.b-bug.org/k230/test_resources/ci/release/release_download_dir.sh -O ./release_download_dir.sh || exit 1
- chmod +x ./release_download_dir.sh
- time ./release_download_dir.sh || time ./release_download_dir.sh || exit 1
- echo "all file synced"
.sync_release_image:
timeout: 60m
retry: 2
tags:
- k230_sdk
script:
- cd $CI_PROJECT_DIR
- ls -alht
- wget -qc https://ai.b-bug.org/k230/test_resources/ci/release/release_images.sh -O ./release_images.sh || exit 1
- chmod +x ./release_images.sh
- echo $CI_COMMIT_TAG || exit 1
- echo $CONF || exit 1
- time ./release_images.sh $CI_COMMIT_TAG $CONF $IMAGE_DIR $IMAGE_NAME $RELEASE_DIR || time ./release_images.sh $CI_COMMIT_TAG $CONF $IMAGE_DIR $IMAGE_NAME $RELEASE_DIR || exit 1
- echo "all release file synced"
.sync_sdk_github_zip:
timeout: 60m
retry: 2
tags:
- k230_sdk
script:
- cd $CI_PROJECT_DIR
- ls -alht
- wget -qc https://ai.b-bug.org/k230/test_resources/ci/release/release_k230_sdk_github_zip.sh -O ./release_k230_sdk_github_zip.sh || exit 1
- chmod +x ./release_k230_sdk_github_zip.sh
- echo $CI_COMMIT_TAG || exit 1
- time ./release_k230_sdk_github_zip.sh $CI_COMMIT_TAG || time ./release_k230_sdk_github_zip.sh $CI_COMMIT_TAG || exit 1
- echo "all release file synced"
.generate_version: &generate_version
- echo "----------get version from file----------"
- pwd
- cat ./board/common/post_copy_rootfs/etc/version/release_version || exit 1
- ver=$(cat ./board/common/post_copy_rootfs//etc/version/release_version | grep ".*-gitlab-runner") || exit 1
- echo ${ver}
- echo "----------save version file to output----------"
- cp ./board/common/post_copy_rootfs/etc/version/release_version ${SRC_DIR}/version || exit 1
- ls -alht ${SRC_DIR}/version || exit 1
- cat ${SRC_DIR}/version || exit 1
.update_build_cfg: &update_build_cfg
- echo "------temp disable quick boot for CI image------"
- cat configs/${CONF} | sed -E 's/CONFIG_QUICK_BOOT=y/# CONFIG_QUICK_BOOT is not set/g' > configs/temp_config
- cat configs/temp_config | grep "QUICK_BOOT"
- cp -rf configs/temp_config configs/${CONF}
- echo "build config"
- cat configs/${CONF} | grep "QUICK_BOOT"
- echo "------temp enable RT-Smart utest for CI image------"
- rtconfig_file="src/big/rt-smart/kernel/bsp/maix3/rtconfig.h"
- echo "#define RT_USING_UTEST" >> ${rtconfig_file}
- echo "#define UTEST_THR_STACK_SIZE 16384" >> ${rtconfig_file}
- echo "#define UTEST_THR_PRIORITY 20" >> ${rtconfig_file}
- cat ${rtconfig_file} | grep "UTEST"
- echo "------check current job for security img build option------"
- >
if [[ $CI_PIPELINE_SOURCE == "merge_request_event" ]];
then
echo "current job is Merge Request, SKIP build security img to save build time";
echo "build config";
cat configs/${CONF} | grep "SECURITY_IMG";
else
echo "current job is NOT Merge Request, add security img build option";
cat configs/${CONF} | sed -E 's/# CONFIG_GEN_SECURITY_IMG is not set/CONFIG_GEN_SECURITY_IMG=y/g' > configs/temp_config2;
echo "temp config";
cat configs/temp_config2 | grep "SECURITY_IMG";
cp -rf configs/temp_config2 configs/${CONF};
echo "build config";
cat configs/${CONF} | grep "SECURITY_IMG";
fi
- echo "update config done"
.update_version: &update_version
- echo "---curren version ${ver}"
- >
if [[ $CI_COMMIT_TAG =~ ^v[0-9]+\.[0-9]+.*$ ]];
then
echo "release tag exist, will replace version dir with tag";
ver=$CI_COMMIT_TAG;
echo "tag is ${ver}";
else
echo "tag is null, skip ver overwrite";
echo "ver is ${ver}";
fi
- echo "---update version ${ver}"
.build_job: &build_job
- pwd
- echo "----------skip toolchain download in local docker----------"
- mkdir toolchain && touch toolchain/.toolchain_ready
- ls toolchain/.toolchain_ready || exit 1
- echo "----------download build source code----------"
- source tools/get_download_url.sh
- time make prepare_sourcecode || exit 1
- *update_build_cfg
- time make || exit 1
- echo "----------show sdk image build output----------"
- pwd
- du -h -d 2 output/${CONF}/ || exit 1
- ls -alht output/${CONF}/images || exit 1
- echo "----------remove img----------"
- rm -rf output/${CONF}/images/sysimage-sdcard.img
- rm -rf output/${CONF}/images/sysimage-spinand32m.img
- rm -rf output/${CONF}/images/sysimage-spinor32m.img
- echo "----------zip big-core/little-core ----------"
- cd output/${CONF}/images/ && pwd
- tar -zcf big-core.tgz ./big-core/
- tar -zcf little-core.tgz ./little-core/
- rm -rf ./big-core/
- rm -rf ./little-core/
- cd ../../../ && pwd
- echo "----------build sdk image done----------"
.common:
build_image:
- cd $CI_PROJECT_DIR
- echo "----------build image----------"
- *build_job
- echo "----------set test-image flag----------"
- echo "SKIP=False" > build.env
save_image:
- pwd
- echo "----------save image----------"
- echo ${DST_BASE}
- echo "set DST_DIR with different type based on docs/images/src"
- DST_DIR="${DST_BASE}/${IMAGE_DIR}"
- echo ${DST_DIR}
- echo "---create repo dir---"
- sudo mkdir -p ${DST_DIR}
- *generate_version
- echo "----------Save build to external path----------"
- *update_version
- SUB_DIR="${ver}/${CONF}";
- echo "---create current image version dir---"
- sudo mkdir -p ${DST_DIR}/${SUB_DIR}/ || exit 1
- echo "---remove image file---"
- rm -rf ${SRC_DIR}/${IMAGE_DIR}/
- echo "---save sdk build output---"
- sudo cp -rf --sparse=always ${SRC_DIR}/ ${DST_DIR}/${SUB_DIR}/
- echo "${DST_DIR}/${SUB_DIR}/"
- ls "${DST_DIR}/${SUB_DIR}/"
- echo "add latest link for current build"
- test -h ${DST_DIR}/latest && sudo rm ${DST_DIR}/latest
- sudo ln -s ${DST_DIR}/${ver} ${DST_DIR}/latest || exit 1
- ls ${DST_DIR}/latest
- echo "----------output URL----------"
- echo "${DST_DIR}/${SUB_DIR}/" | sed "s/\/data1/https:\/\/ai\.b-bug\.org/g"
- echo "----------save image done----------"