-
Notifications
You must be signed in to change notification settings - Fork 7
/
.gitlab-ci.yml
1101 lines (1068 loc) · 41.7 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
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
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
variables:
GITLAB_REPO: [email protected]:maix_sw/k230_linux_sdk.git
GITHUB_REPO: [email protected]:kendryte/k230_linux_sdk.git
GITEE_REPO: [email protected]:kendryte/k230_linux_sdk.git
TEST_SCRIPTS_REPO: [email protected]:maix_sw/k230_testscripts.git
DL_SITE: https://ai.b-bug.org/~/wangjianxin/dl/
HW_VER: v0.1
TFTP_BASE: /data1/tftp_server
NFS_SERVER: 10.10.1.94
NFS_BASE: /data/nfs_server
IMAGE_DIR: linux_sdk_images
IMAGE_NAME: "*_linux_*_nncase_*.img.gz"
TEST_CONFIGS: >
k230_canmv_defconfig
k230d_canmv_defconfig
BPI-CanMV-K230D-Zero_defconfig
default:
image: ai.b-bug.org:5000/k230_sdk:latest
tags:
- k230_sdk
stages:
- build_setup
- build_src
- smoke_test
- test
- release
- send_msg
.show_vars: &show_vars
- echo "${JOB_TYPE}"
- echo "${DST_BASE}"
- echo "${SUB_BASE}"
- echo "${image_url}"
- echo "${image_path}"
- echo "${BUILD}"
.get_job_result: &get_job_result
- echo "get job result"
- |
echo "CI_JOB_NAME $CI_JOB_NAME";
echo "CI_JOB_STATUS $CI_JOB_STATUS";
echo "CI_JOB_ID $CI_JOB_ID";
echo "CI_JOB_IMAGE $CI_JOB_IMAGE";
echo "CI_JOB_NAME_SLUG $CI_JOB_NAME_SLUG";
echo "CI_JOB_STAGE $CI_JOB_STAGE";
echo "CI_JOB_TIMEOUT $CI_JOB_TIMEOUT";
echo "CI_JOB_URL $CI_JOB_URL";
echo "CI_PIPELINE_SOURCE $CI_PIPELINE_SOURCE";
echo "CI_PIPELINE_URL $CI_PIPELINE_URL";
echo "CI_PIPELINE_NAME $CI_PIPELINE_NAME";
echo "CI_PIPELINE_TRIGGERED $CI_PIPELINE_TRIGGERED";
echo "check send feishu msg to group";
SEND="FALSE";
if [[ "$CI_PIPELINE_SOURCE" != "merge_request_event" ]];
then
if [[ "$CI_JOB_STATUS" == "success" ]];
then
echo "job pass, check again";
if [[ "$CI_JOB_STAGE" == "send_msg" ]];
then
echo "match the last test, will send feishu pass msg";
SEND="TRUE";
else
echo "job pass but not the last one, continue the next job";
fi
elif [[ "$CI_JOB_STATUS" == "failed" ]];
then
echo "job failed, will send feishu msg now";
SEND="TRUE";
else
echo "unknown job status";
fi
else
echo "skip feishu msg for MR event";
fi
echo "Pipeline created at $CI_PIPELINE_CREATED_AT";
total_seconds=$(($(date +%s) - $(date -d $CI_PIPELINE_CREATED_AT +%s)));
echo "Total pipeline duration ${total_seconds} seconds";
t_hours=$((total_seconds / 3600));
t_minutes=$(( (total_seconds % 3600) / 60 ));
t_seconds=$((total_seconds % 60));
echo "Total pipeline duration ${t_hours}小时${t_minutes}分${t_seconds}秒";
if [[ "$SEND" == "TRUE" ]];
then
test -d bin || mkdir ./bin;
test -f ./bin/send_feishu && rm -rf ./bin/send_feishu;
echo "start to download send_feishu";
wget -qc https://ai.b-bug.org/k230/test_resources/ci/tools/send_feishu -O ./bin/send_feishu;
chmod +x ./bin/send_feishu;
echo "---start to send feishu msg in for loop"
stime=$(date +'%Y-%m-%d %H:%M:%S')
echo "---run send feishu msg start time: $stime"
send_cmd="timeout 1m ./bin/send_feishu --msg_type pipeline --gitlab_repo $CI_PROJECT_NAME --pipeline_source $CI_PIPELINE_SOURCE --pipeline_version ${SUB_BASE} --pipeline_seconds $total_seconds --pipeline_stage $CI_JOB_STAGE --pipeline_url $CI_PIPELINE_URL --pipeline_result $CI_JOB_STATUS --image_url '$image_url' --job_name='$CI_JOB_NAME'"
for i in {1..6}; do
if [ $i -eq 6 ]
then
echo "ERROR: Max retries reached with run send feishu msg"
exit 1
fi
starttime=$(date +'%Y-%m-%d %H:%M:%S')
echo "---loop $i start time: $starttime"
echo "---start to run send feishu msg in loop $i---"
if eval $send_cmd
then
echo "---loop $i run send feishu msg pass---"
break
else
echo "ERROR:loop $i run send feishu msg failed, ignore Error and try again..."
echo "---start to rerun in next loop..."
sleep 30
fi
endtime=$(date +'%Y-%m-%d %H:%M:%S')
start_seconds=$(date -d "$starttime" +%s)
end_seconds=$(date -d "$endtime" +%s)
echo "---loop $i end time: $endtime"
echo "---loop $i total cost time:$((end_seconds - start_seconds)) s"
done
etime=$(date +'%Y-%m-%d %H:%M:%S')
s_seconds=$(date -d "$stime" +%s)
e_seconds=$(date -d "$etime" +%s)
echo "---run send feishu msg end time: $etime"
echo "---run send feishu msg total cost time:$((e_seconds - s_seconds)) s"
echo "---finished run send feishu msg in loop $i"
echo "send feishu done";
else
echo "skip send feishu msg";
fi
.get_job_type: &get_job_type
- echo "----------get dst dir with job type----------"
- >
echo "check job from MR or tag or schedule or web";
if [[ $CI_PIPELINE_SOURCE == "merge_request_event" ]]; then
echo "current job is MR";
JOB_TYPE="merge_request";
DST_BASE="/data1/k230/gitlab-ci/images/${CI_PROJECT_NAME}";
elif [[ $CI_PIPELINE_SOURCE == "schedule" ]]; then
echo "current job is daily build schedule job";
JOB_TYPE="daily_build";
DST_BASE="/data1/k230/dev-release";
elif [[ $CI_PIPELINE_SOURCE == "web" && $CI_COMMIT_TAG =~ ^v[0-9]+\.[0-9]+.*$ ]]; then
echo "current job is pre release job";
JOB_TYPE="pre_release";
DST_BASE="/data1/k230/pre-release";
elif [[ $CI_PIPELINE_SOURCE == "web" ]]; then
echo "current job is manual test job";
JOB_TYPE="manual_test";
DST_BASE="/data1/k230/gitlab-ci/images/${CI_PROJECT_NAME}";
elif [[ $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG =~ ^v[0-9]+\.[0-9]+.*$ ]]; then
echo "current job is release job";
JOB_TYPE="release";
DST_BASE="/data1/k230/release";
else
echo "current job is not define, EXIT with ERROR";
exit 1;
fi
- echo ${JOB_TYPE}
- echo ${DST_BASE}
- echo "----------get dst dir job done----------"
.latest_version: &latest_version
- echo "check latest commit id for daily build"
- >
if [[ "${JOB_TYPE}" == "daily_build" ]]; then
echo "current job is daily_build, check commit id";
cur_commitid=$(git rev-parse --short HEAD);
echo "get latest commit id";
if [ -d "${DST_BASE}/sdk/latest/" ]; then
latest_file=$(ls "${DST_BASE}/sdk/latest/");
echo "latest_file $latest_file";
finished_commitid=$(echo $latest_file | sed "s/.*-gitlab-runner-\(.*\)\.tar\.gz/\1/g");
else
echo "latest_file not exist";
finished_commitid="";
fi
echo "current commit_id $cur_commitid";
echo "finished commit_id $finished_commitid";
if [[ "$cur_commitid" == "$finished_commitid" ]]; then
echo "WARNNING current commit id is equal to finished commit id";
echo "There is no any code changes, SKIP and EXIT";
echo "BUILD=False" > build.env;
exit 0;
else
echo "current commit id is NOT equal to finished commit id, will continue to run build job";
fi
echo "temp disable commit id check at 2023.12.18, and enable duplicate/same commit id build job";
else
echo "current job is NOT daily build, will continue to run build job";
fi
.generate_version: &generate_version
- echo "----------generate version----------"
- echo "generate version with tag or commit id"
- >
if [[ $CI_COMMIT_TAG =~ ^v[0-9]+\.[0-9]+.*$ ]];
then
echo "tag exist, version should be tag";
new_ver=$CI_COMMIT_TAG;
echo "tag is ${new_ver}";
else
echo "tag is null, version should be commit id";
commitid="unkonwn";
latest_tag="unkonwn";
git rev-parse --short HEAD && commitid=$(git rev-parse --short HEAD);
git describe --tags `git rev-list --tags --max-count=1` && latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`);
cur_date=$(date "+%Y%m%d-%H%M%S") || exit 1;
new_ver="${latest_tag}-${cur_date}-$(whoami)-$(hostname)-${commitid}" || exit 1;
echo "ver is ${new_ver}";
fi
- echo ${new_ver} > version || exit 1
- cat version || exit 1
.check_build_result: &check_build_result
- date
- >
if [[ "${BUILD}" == "False" ]];
then
echo "WARNNING: current commit id is equal to finished commit id";
echo "There is no any code changes, SKIP test job and quit";
exit 0;
else
echo "----------start to run test job----------";
fi
.generate_md5_file: &generate_md5_file
- echo "generate md5 for build image"
- pwd
- ls
- |
find . \( -type f -o -type l \) -name "*.img.gz" | while read file; do
sudo bash -c "md5sum \"$file\" > \"$file.md5\""
done
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
- echo '----------fetch all tags----------'
- timeout 3m git fetch --tags || { timeout 3m git fetch --tags || { timeout 3m git fetch --tags || exit 1; }; }
- |
echo "get hw type and modle based on configs name"
if [[ "$CONF" == "BPI-CanMV-K230D-Zero_defconfig" ]]; then
HW_TYPE="k230d"
HW_MODEL="bpi"
else
HW_TYPE=$(echo $CONF | awk -F '_' '{print $1}')
HW_MODEL=$(echo $CONF | awk -F "_" '{if ($3 == "v2") print $2"_"$3; else print $2}')
fi
echo "HW_TYPE ${HW_TYPE}, HW_MODEL ${HW_MODEL}"
- echo "set only_linux and only_rtt flag for test jobs"
- ONLY_LINUX=True
- ONLY_RTT=False
- echo "ONLY_RTT is ${ONLY_RTT}"
- echo "ONLY_LINUX is ${ONLY_LINUX}"
.github_to_gitlab_gitee:
timeout: 30m
retry: 2
script:
- echo $GITHUB_PUSH
- cd $CI_PROJECT_DIR
- ls -alht
- rm -rf ./k230_linux_sdk/
- echo "set http proxy for git clone"
- git config --global http.proxy ${GITHUB_PROXY}
- git config --global https.proxy ${GITHUB_PROXY}
- timeout 3m git clone ${GITHUB_REPO} k230_linux_sdk || { timeout 3m git clone ${GITHUB_REPO} k230_linux_sdk || { timeout 3m git clone ${GITHUB_REPO} k230_linux_sdk || exit 1; }; }
- cd k230_linux_sdk || exit 1
- pwd
- git checkout ${BRANCH}
- git branch -a
- git status
- echo '---pull latest ${BRANCH} branch---'
- timeout 3m git pull origin ${BRANCH} || { timeout 3m git pull origin ${BRANCH} || { timeout 3m git pull origin ${BRANCH} || exit 1; }; }
- echo '---fetch all tags---'
- timeout 3m git fetch --tags || { timeout 3m git fetch --tags || { timeout 3m git fetch --tags || exit 1; }; }
- git remote add gitlab ${GITLAB_REPO}
- git remote add gitee ${GITEE_REPO}
- git remote -v
- git branch -a
- git status
- echo "---push to gitee---"
- timeout 3m git push --atomic --tags -u gitee ${BRANCH} || { timeout 3m git push --atomic --tags -u gitee ${BRANCH} || { timeout 3m git push --atomic --tags -u gitee ${BRANCH} || exit 1; }; }
- echo "---push to gitlab---"
- timeout 3m git push --atomic --tags -u gitlab ${BRANCH} || { timeout 3m git push --atomic --tags -u gitlab ${BRANCH} || { timeout 3m git push --atomic --tags -u gitlab ${BRANCH} || exit 1; }; }
.gitlab_to_github_gitee:
timeout: 30m
retry: 2
script:
- cd $CI_PROJECT_DIR
- ls -alht
- rm -rf ./k230_linux_sdk/
- timeout 3m git clone ${GITLAB_REPO} k230_linux_sdk || { timeout 3m git clone ${GITLAB_REPO} k230_linux_sdk || { timeout 3m git clone ${GITLAB_REPO} k230_linux_sdk || exit 1; }; }
- cd k230_linux_sdk || exit 1
- pwd
- git checkout ${BRANCH}
- git branch -a
- git status
- echo '---pull latest ${BRANCH} branch---'
- timeout 3m git pull origin ${BRANCH} || { timeout 3m git pull origin ${BRANCH} || { timeout 3m git pull origin ${BRANCH} || exit 1; }; }
- echo '---fetch all tags---'
- timeout 3m git fetch --tags || { timeout 3m git fetch --tags || { timeout 3m git fetch --tags || exit 1; }; }
- git remote add github ${GITHUB_REPO}
- git remote add gitee ${GITEE_REPO}
- git remote -v
- git branch -a
- git status
- echo "---push to gitee---"
- timeout 3m git push --atomic --tags -u gitee ${BRANCH} || { timeout 3m git push --atomic --tags -u gitee ${BRANCH} || { timeout 3m git push --atomic --tags -u gitee ${BRANCH} || exit 1; }; }
- echo "---push to github---"
- timeout 3m git push --atomic --tags -u github ${BRANCH} || { timeout 3m git push --atomic --tags -u github ${BRANCH} || { timeout 3m git push --atomic --tags -u github ${BRANCH} || exit 1; }; }
.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
- chmod +x ./release_download_dir.sh
- time ./release_download_dir.sh || time ./release_download_dir.sh
- 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
- 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 $IMAGE_DIR || time ./release_images.sh $CI_COMMIT_TAG $CONF $IMAGE_DIR $IMAGE_NAME $IMAGE_DIR
- echo "all release file published"
.update_version: &update_version
- echo "---curren version ${SUB_BASE}"
- >
if [[ $CI_COMMIT_TAG =~ ^v[0-9]+\.[0-9]+.*$ ]];
then
echo "release tag exist, will replace version dir with tag";
SUB_BASE=$CI_COMMIT_TAG;
echo "tag is ${SUB_BASE}";
else
echo "tag is null, skip ver overwrite";
echo "ver is ${SUB_BASE}";
fi
- echo "---update version ${SUB_BASE}"
.build_job: &build_job
- pwd
- echo "----------start to build linux sdk image----------"
- time make CONF=${CONF} BR2_PRIMARY_SITE=${DL_SITE} || exit 1
- echo "----------show linux 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
- echo "----------build sdk image done----------"
.generate_nfs_dst_dir: &generate_nfs_dst_dir
- echo "---get nfs case folder---"
- |
echo ${NFS_BASE};
echo "set NFS_DST_DIR with different type based on docs/images/src";
NFS_DST_DIR="${NFS_BASE}/${HW_TYPE}/${HW_MODEL}_${HW_VER}";
echo ${NFS_DST_DIR};
echo "---create NFS dir---";
echo "generate sub dir for MR/Pre-releae/relese job";
echo "check job from MR or tag or schedule or web";
if [[ ${CI_MERGE_REQUEST_IID} ]]; then
echo "current job is MR, skip and use CI_MERGE_REQUEST_IID";
elif [[ ${CI_COMMIT_TAG} ]]; then
echo "current job is release job, use CI_COMMIT_TAG";
CI_MERGE_REQUEST_IID=${CI_COMMIT_TAG};
elif [[ $CI_PIPELINE_SOURCE == "schedule" ]]; then
echo "current job is daily build schedule job, use CI_PIPELINE_SOURCE";
CI_MERGE_REQUEST_IID=$CI_PIPELINE_SOURCE;
else
echo "current job is not match, use CI_PIPELINE_SOURCE";
CI_MERGE_REQUEST_IID=$CI_PIPELINE_SOURCE;
fi
echo "current MR ID ${CI_MERGE_REQUEST_IID}";
SUB_DIR="${CI_MERGE_REQUEST_IID}_${CI_PIPELINE_ID}";
NFS_CASE_FOLDER="${NFS_DST_DIR}/${SUB_DIR}/${CONF}/${DOMAIN}";
echo "NFS_CASE_FOLDER: $NFS_CASE_FOLDER";
echo "update current NFS_CASE_FOLDER permission before write";
sudo mkdir -p ${NFS_CASE_FOLDER} || exit 1;
sudo chmod -R 777 ${NFS_CASE_FOLDER} || exit 1;
- echo "---NFS_CASE_FOLDER is ${NFS_CASE_FOLDER}---"
.copy_linux_test_resource: ©_linux_test_resource
- echo "----------copy linux common resource to nfs case folder----------"
- echo "---copy linux common test resource to nfs dir in nfs_server"
- mkdir -p $NFS_CASE_FOLDER/output || exit 1
- sudo chmod -R 777 $NFS_CASE_FOLDER/output || exit 1
- echo "confirm dst dir not exist for rerun jobs"
- rm -rf $NFS_CASE_FOLDER/resource || echo "dir not exist"
- echo "copy src and rename to dst dir name"
- time cp -rf --sparse=always $NFS_BASE/k230_linux_resource $NFS_CASE_FOLDER/resource
- ls -alht $NFS_CASE_FOLDER
.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}
- echo "----------Save build to external path----------"
- *update_version
- SUB_DIR="${SUB_BASE}/${CONF}";
- echo "---create current image version dir---"
- sudo mkdir -p ${DST_DIR}/${SUB_DIR}/ || exit 1
- echo "---save sdk build output---"
- ls "${SRC_DIR}"
- sudo cp -rf --sparse=always -L ${SRC_DIR}/${IMAGE_NAME} ${DST_DIR}/${SUB_DIR}/
- pwd
- echo "switch to dst dir to generate md5 file"
- cd ${DST_DIR}/${SUB_DIR}/ || exit 1
- *generate_md5_file
- echo "return to work dir"
- cd $CI_PROJECT_DIR/ || exit 1
- ls
- echo "${DST_DIR}/${SUB_DIR}/"
- ls "${DST_DIR}/${SUB_DIR}/"
- echo "add latest link for current build"
- echo "generate three random numers to sleep and schedule more pipeline job"
- sleep $((RANDOM % 9 + 1))
- sleep $((RANDOM % 9 + 1))
- sleep $((RANDOM % 9 + 1))
- test -h ${DST_DIR}/latest && sudo rm ${DST_DIR}/latest
- sudo ln -s ${DST_DIR}/${SUB_BASE} ${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----------"
- image_path="${DST_DIR}/${SUB_BASE}"
- echo "image_path=${image_path}" >> $CI_PROJECT_DIR/build.env
- image_url=$(echo ${image_path} | sed 's/\/data1/https:\/\/ai\.b-bug\.org/g')
- echo "image_url=${image_url}" >> $CI_PROJECT_DIR/build.env
- cat $CI_PROJECT_DIR/build.env || exit 1
- echo "----------image output----------"
- echo "${image_path}"
- echo "${image_url}"
save_tftp:
- pwd
- echo "----------save image to tftp----------"
- >
for CONFIG in $TEST_CONFIGS
do
if [[ "${CONF}" == "${CONFIG}" ]];
then
echo "start to save test image for default config: ${CONF} ------";
echo ${TFTP_BASE};
echo "set DST_DIR with different type based on docs/images/src";
DST_DIR="${TFTP_BASE}/${HW_TYPE}/${HW_MODEL}_${HW_VER}";
echo ${DST_DIR};
echo "---create tftp dir---";
sudo mkdir -p ${DST_DIR} || exit 1;
echo "generate sub dir for MR/Pre-releae/relese job";
echo "check job from MR or tag or schedule or web";
if [[ ${CI_MERGE_REQUEST_IID} ]]; then
echo "current job is MR, skip and use CI_MERGE_REQUEST_IID";
elif [[ ${CI_COMMIT_TAG} ]]; then
echo "current job is release job, use CI_COMMIT_TAG";
CI_MERGE_REQUEST_IID=${CI_COMMIT_TAG};
elif [[ $CI_PIPELINE_SOURCE == "schedule" ]]; then
echo "current job is daily build schedule job, use CI_PIPELINE_SOURCE";
CI_MERGE_REQUEST_IID=$CI_PIPELINE_SOURCE;
else
echo "current job is not match, use CI_PIPELINE_SOURCE";
CI_MERGE_REQUEST_IID=$CI_PIPELINE_SOURCE;
fi
echo "current MR ID ${CI_MERGE_REQUEST_IID}";
SUB_DIR="${CI_MERGE_REQUEST_IID}_${CI_PIPELINE_ID}/${CONF}";
sudo mkdir -p ${DST_DIR}/${SUB_DIR}/ || exit 1;
src_file="${SRC_DIR}/${IMAGE_NAME}";
echo ${SRC_DIR};
echo ${src_file};
ls -alht output/${CONF}/images/ || exit 1;
ls -alht -L ${src_file} || exit 1;
sudo cp -rf --sparse=always -L ${src_file} ${DST_DIR}/${SUB_DIR}/sysimage-sdcard.img.gz;
echo "${DST_DIR}/${SUB_DIR}/";
ls -alht "${DST_DIR}/${SUB_DIR}/" || exit 1;
sysimage_md5=$(md5sum ${DST_DIR}/${SUB_DIR}/sysimage-sdcard.img.gz | awk '{print $1}');
echo "sysimage md5 is ${sysimage_md5}";
echo "release job works in release_sdk sub dir, use full path";
echo "sysimage_path=${DST_DIR}/${SUB_DIR}/sysimage-sdcard.img.gz" >> $CI_PROJECT_DIR/build.env;
echo "sysimage_md5=${sysimage_md5}" >> $CI_PROJECT_DIR/build.env;
ls;
cat $CI_PROJECT_DIR/build.env;
else
echo "SKIP save test image as current config ${CONF} not match build config ${CONFIG} ------";
fi
done
- echo "----------save image to tftp done----------"
.test:
test_setup:
- echo "----------Step 1. get available test devices----------"
- |
echo "check job from MR or tag or schedule or web";
if [[ ${CI_MERGE_REQUEST_IID} ]]; then
echo "current job is MR, skip and use CI_MERGE_REQUEST_IID";
elif [[ ${CI_COMMIT_TAG} ]]; then
echo "current job is release job, use CI_COMMIT_TAG";
CI_MERGE_REQUEST_IID=${CI_COMMIT_TAG};
elif [[ $CI_PIPELINE_SOURCE == "schedule" ]]; then
echo "current job is daily build schedule job, use CI_PIPELINE_SOURCE";
CI_MERGE_REQUEST_IID=$CI_PIPELINE_SOURCE;
else
echo "current job is not match, use CI_PIPELINE_SOURCE";
CI_MERGE_REQUEST_IID=$CI_PIPELINE_SOURCE;
fi
- echo "MR ID ${CI_MERGE_REQUEST_IID}"
- echo "Pipeline ID ${CI_PIPELINE_ID}"
- echo "generate three random numers to sleep and schedule more pipeline job"
- sleep $((RANDOM % 9 + 1))
- sleep $((RANDOM % 9 + 1))
- sleep $((RANDOM % 9 + 1))
- test -d bin || mkdir ./bin
- test -f ./bin/ailab && rm -rf ./bin/ailab
- wget -qc https://ai.b-bug.org/k230/test_resources/ci/tools/ailab -O ./bin/ailab
- chmod +x ./bin/ailab
- |
echo "for loop to get available test device"
for i in {1..6}; do
if [ $i -eq 6 ];
then
echo "ERROR: No Available DUT after 5 times retry, Please rerun curent job to check it again";
exit 1;
fi
starttime=$(date +'%Y-%m-%d %H:%M:%S');
echo "---loop $i start time: $starttime";
echo "---start to get available test device in loop $i---";
available=$(./bin/ailab show --dest available --domain ${DOMAIN} --hw_type ${HW_TYPE} --hw_model ${HW_MODEL} --hw_ver ${HW_VER} --format args)
echo ${available}
if [[ $available =~ "k230" ]];
then
echo "---Get Available DUT pass in loop $i---";
echo "----------get available test devices done----------";
echo "----------Step 2. reserve test device----------";
reserved=$(./bin/ailab add ${available} --time 15m --site ${CI_PROJECT_NAME} --source ${CI_MERGE_REQUEST_IID} --job ${CI_PIPELINE_ID} --format args);
echo ${reserved};
if [[ ${reserved} =~ "gitlab" ]];
then
echo "Reserve DUT pass in loop $i, break loop and continue the next job";
# exit for loop with break once device avaiable and reserved pass
break;
else
echo "ERROR: Reserve DUT failed";
if [ $i -eq 6 ];
then
echo "ERROR: No Available DUT after 5 times retry, Please rerun curent job to check it again";
exit 1;
else
echo "---sleep 30 seconds and auto rerun in next loop...";
sleep 30
fi
fi
else
echo "ERROR: Get available test device failed in loop $i, ignore Error and try again...";
echo "---sleep for 30seconds and start to rerun in next loop...";
sleep 30;
fi
done
- echo "----------Step 3. save reserved/available for after_script----------"
- echo "${available}" > available
- echo "${reserved}" > reserved
- echo "${HW_MODEL}" > HW_MODEL
- echo "----------reserve test device and preprare test resource done----------"
test_teardown:
- cd $CI_PROJECT_DIR
- echo "----------release test device----------"
- echo "get variables from previous steps"
- reserved=$(cat reserved)
- available=$(cat available)
- HW_MODEL=$(cat HW_MODEL)
- echo "Release DUT start"
- test -d bin || mkdir ./bin
- test -f ./bin/ailab && rm -rf ./bin/ailab
- wget -qc https://ai.b-bug.org/k230/test_resources/ci/tools/ailab -O ./bin/ailab
- chmod +x ./bin/ailab
- result=$(./bin/ailab update --dest=reserved ${reserved})
- echo $result
- |
if [[ $result =~ "True" ]]; then
echo "Release DUT pass";
else
echo "ERROR: Release DUT failed";
exit 1;
fi
- power_off="./bin/ailab power --type=off ${available}";
- power_on="./bin/ailab power --type=on ${available}";
- power_reset="./bin/ailab power --type=cycle ${available}";
- echo $power_off
- echo $power_on
- echo $power_reset
- |
echo "---start to run device power job after test done...";
if [[ "$HW_MODEL" =~ "evb" ]]; then
echo "---$HW_MODEL board will be power off and power on at test start---";
$power_off;
sleep 1;
$power_on;
sleep 1;
echo "$HW_MODEL board power off and power on done. continue in next loop";
else
echo "---$HW_MODEL board will be power reset at test start ---";
$power_reset;
sleep 1;
echo "---$HW_MODEL board power reset done. continue to run test job";
fi
echo "---device power job done---";
- echo "----------release test device done----------"
copy_test_resource:
- cd $CI_PROJECT_DIR
- echo "----------Step 5. copy test resource----------"
- echo "get build step result"
- echo $image_path
- echo $SUB_BASE
- echo $HW_TYPE
- echo $HW_MODEL
- echo $HW_VER
- echo "current test device config is ${CONF}"
- pwd
- *generate_nfs_dst_dir
- *copy_linux_test_resource
- echo "show test resource in nfs_server"
- echo $NFS_CASE_FOLDER
- ls -alht $NFS_CASE_FOLDER
- cd $CI_PROJECT_DIR
- pwd
- echo "finished copy test resource in nfs_server"
- echo "----------generate test device yml file for test job----------"
- echo "run command ./bin/ailab convert --dest=script --format yaml --file_name=${DOMAIN}.yml --nfs_server_ip $NFS_SERVER --nfs_case_folder $NFS_CASE_FOLDER --only_rtt ${ONLY_RTT} --only_linux ${ONLY_LINUX} --conf ${CONF} --pr_id ${CI_MERGE_REQUEST_IID} --job_id ${CI_PIPELINE_ID} --sysimage_md5 ${sysimage_md5} ${available}"
- ./bin/ailab convert --dest=script --format yaml --file_name=${DOMAIN}.yml --nfs_server_ip $NFS_SERVER --nfs_case_folder $NFS_CASE_FOLDER --only_rtt ${ONLY_RTT} --only_linux ${ONLY_LINUX} --conf ${CONF} --pr_id ${CI_MERGE_REQUEST_IID} --job_id ${CI_PIPELINE_ID} --sysimage_md5 ${sysimage_md5} ${available}
- test -f ${DOMAIN}.yml || exit 1
- cat ${DOMAIN}.yml || exit 1
- echo "cp ${DOMAIN}.yml to nfs_case_folder"
- cp -rf --sparse=always ${DOMAIN}.yml $NFS_CASE_FOLDER/ || exit 1
- test -f $NFS_CASE_FOLDER/${DOMAIN}.yml || exit 1
- echo "show test resource in nfs_server"
- echo $NFS_CASE_FOLDER
- ls -alht $NFS_CASE_FOLDER
load_image:
- echo "----------load image to test device----------"
- echo "sysimage-sdcard.img.gz md5 ${sysimage_md5}"
- test -d bin || mkdir ./bin
- test -f ./bin/aiload && rm -rf ./bin/aiload
- wget -qc https://ai.b-bug.org/k230/test_resources/ci/tools/k230load -O ./bin/aiload
- chmod +x ./bin/aiload
- echo "MR ID ${CI_MERGE_REQUEST_IID}"
- echo "Pipeline ID ${CI_PIPELINE_ID}"
- echo "----------power on/reset test device before load image start----------"
- power_off="./bin/ailab power --type=off ${available}";
- power_on="./bin/ailab power --type=on ${available}";
- power_reset="./bin/ailab power --type=cycle ${available}";
- echo $power_off
- echo $power_on
- echo $power_reset
- |
echo "---start to run device power job before test start...";
if [[ "$HW_MODEL" =~ "evb" ]]; then
echo "---$HW_MODEL board will be power off and power on at test start---";
$power_off;
sleep 1;
$power_on;
sleep 1;
echo "$HW_MODEL board power off and power on done. continue in next loop";
else
echo "---$HW_MODEL board will be power reset at test start ---";
$power_reset;
sleep 1;
echo "---$HW_MODEL board power reset done. continue to run job";
fi
echo "---device power action done, start to run load image job...";
- |
echo "---start to load image in for loop";
stime=$(date +'%Y-%m-%d %H:%M:%S');
echo "---load image start time: $stime";
load_cmd="./bin/aiload --file_name=$NFS_CASE_FOLDER/${DOMAIN}.yml";
echo "${load_cmd}";
for i in {1..6}; do
if [ $i -eq 6 ]
then
echo "ERROR: Max retries reached with load image";
exit 1;
fi
starttime=$(date +'%Y-%m-%d %H:%M:%S');
echo "---loop $i start time: $starttime";
echo "---start to load image in loop $i---";
if eval $load_cmd
then
echo "---loop $i load image pass---";
break;
else
echo "ERROR:loop $i load image failed, ignore Error and retry again...";
echo "---start to run device power job after failed job...";
if [[ "$HW_MODEL" =~ "evb" ]]; then
echo "---$HW_MODEL board will be power off and power on at test start---";
$power_off;
sleep 1;
$power_on;
sleep 1;
echo "$HW_MODEL board power off and power on done. continue in next loop";
else
echo "---$HW_MODEL board will be power reset at test start ---";
$power_reset;
sleep 1;
echo "---$HW_MODEL board power reset done. continue to run test job";
fi
echo "---device power action done, start to rerun in next loop...";
fi
endtime=$(date +'%Y-%m-%d %H:%M:%S');
start_seconds=$(date -d "$starttime" +%s);
end_seconds=$(date -d "$endtime" +%s);
echo "---loop $i end time: $endtime";
echo "---loop $i total cost time:$((end_seconds - start_seconds)) s";
done
etime=$(date +'%Y-%m-%d %H:%M:%S');
s_seconds=$(date -d "$stime" +%s);
e_seconds=$(date -d "$etime" +%s);
echo "---load image end time: $etime";
echo "---load image total cost time:$((e_seconds - s_seconds)) s";
echo "---finished load image in loop $i";
- echo "---load image pass"
- echo "----------load image to test device done----------"
smoke_test:
- echo "----------Run Smoke Test start----------"
- test -d bin || mkdir ./bin
- test -f ./bin/airobot && rm -rf ./bin/airobot
- wget -qc https://ai.b-bug.org/k230/test_resources/ci/tools/airobot -O ./bin/airobot
- chmod +x ./bin/airobot
- echo "---add smoke test script"
- git clone ${TEST_SCRIPTS_REPO} k230_testscripts || exit 1
- cd k230_testscripts || exit 1
- git fetch origin dev || { sleep 30; git fetch origin dev || { sleep 30; git fetch origin dev || exit 1; } }
- git checkout dev || exit 1
- cd ../ || exit 1
- echo "---download evb board smoke test script in loop $i---";
- wget -qc https://ai.b-bug.org/k230/test_resources/ci/testscripts/k230_linux_sdk_smoke_test.sh -O ./k230_linux_sdk_smoke_test.sh;
- chmod +x ./k230_linux_sdk_smoke_test.sh
- |
echo "---start to run k230 smoke test in for loop";
stime=$(date +'%Y-%m-%d %H:%M:%S');
echo "---run k230 smoke test start time: $stime";
test_cmd="./k230_linux_sdk_smoke_test.sh $NFS_CASE_FOLDER/${DOMAIN}.yml";
for i in {1..3}; do
if [ $i -eq 2 ];
then
echo "ERROR: Max retries reached with run k230 smoke test";
exit 1;
fi
starttime=$(date +'%Y-%m-%d %H:%M:%S');
echo "---loop $i start time: $starttime";
echo "---start to run k230 smoke test in loop $i---";
if eval $test_cmd;
then
echo "---loop $i run k230 smoke test pass---";
break;
else
echo "ERROR:loop $i run k230 smoke test failed, ignore Error and try again...";
echo "---start to rerun in next loop...";
sleep 3
fi
endtime=$(date +'%Y-%m-%d %H:%M:%S');
start_seconds=$(date -d "$starttime" +%s);
end_seconds=$(date -d "$endtime" +%s);
echo "---loop $i end time: $endtime";
echo "---loop $i total cost time:$((end_seconds - start_seconds)) s";
done
etime=$(date +'%Y-%m-%d %H:%M:%S');
s_seconds=$(date -d "$stime" +%s);
e_seconds=$(date -d "$etime" +%s);
echo "---run k230 smoke test end time: $etime";
echo "---run k230 smoke test total cost time:$((e_seconds - s_seconds)) s";
echo "---finished run k230 smoke test in loop $i";
- echo "----------Run Smoke Test pass----------"
daily_test:
- echo "----------Run Daily Test start----------"
- test -d bin || mkdir ./bin
- test -f ./bin/airobot && rm -rf ./bin/airobot
- wget -qc https://ai.b-bug.org/k230/test_resources/ci/tools/airobot -O ./bin/airobot
- chmod +x ./bin/airobot
- echo "---get daily test scripts"
- git clone ${TEST_SCRIPTS_REPO} k230_testscripts || exit 1
- cd k230_testscripts || exit 1
- git fetch origin dev || { sleep 30; git fetch origin dev || { sleep 30; git fetch origin dev || exit 1; } }
- git checkout dev || exit 1
- cd ../ || exit 1
- wget -qc https://ai.b-bug.org/k230/test_resources/ci/testscripts/k230_linux_sdk_daily_test.sh -O ./k230_linux_sdk_daily_test.sh
- chmod +x ./k230_linux_sdk_daily_test.sh
- |
echo "---start to run k230 daily test in for loop";
stime=$(date +'%Y-%m-%d %H:%M:%S');
echo "---run k230 daily test start time: $stime";
test_cmd="./k230_linux_sdk_daily_test.sh $NFS_CASE_FOLDER/${DOMAIN}.yml";
for i in {1..3}; do
if [ $i -eq 2 ];
then
echo "ERROR: Max retries reached with run k230 daily test";
exit 1;
fi
starttime=$(date +'%Y-%m-%d %H:%M:%S');
echo "---loop $i start time: $starttime";
echo "---start to run k230 daily test in loop $i---";
if eval $test_cmd;
then
echo "---loop $i run k230 daily test pass---";
break;
else
echo "ERROR:loop $i run k230 daily test failed, ignore Error and try again...";
echo "---start to rerun in next loop...";
sleep 3;
fi
endtime=$(date +'%Y-%m-%d %H:%M:%S');
start_seconds=$(date -d "$starttime" +%s);
end_seconds=$(date -d "$endtime" +%s);
echo "---loop $i end time: $endtime";
echo "---loop $i total cost time:$((end_seconds - start_seconds)) s";
done
etime=$(date +'%Y-%m-%d %H:%M:%S');
s_seconds=$(date -d "$stime" +%s);
e_seconds=$(date -d "$etime" +%s);
echo "---run k230 daily test end time: $etime";
echo "---run k230 daily test total cost time:$((e_seconds - s_seconds)) s";
echo "---finished run k230 daily test in loop $i";
- echo "----------Run Daily Test pass----------"
# download dir publish with tag
download_dir_release:
stage: release
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG =~ /^v\d+\.\d+.*$/
extends:
- .release_download_dir
# sdk zip and image publish with tag
release_image_publish:
stage: release
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG =~ /^v\d+\.\d+.*$/
parallel:
matrix:
- CONF:
- k230_canmv_defconfig
- k230d_canmv_defconfig
- BPI-CanMV-K230D-Zero_defconfig
extends:
- .sync_release_image
# main branch
main_release:
stage: release
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"
variables:
BRANCH: main
extends:
- .gitlab_to_github_gitee
# tag push
tag_release:
stage: release
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG =~ /^v\d+\.\d+.*$/
variables:
BRANCH: main
extends:
- .gitlab_to_github_gitee
# schedule daily build sync
gitlab_to_github_gitee:
stage: release
rules:
# daily build
- if: $CI_PIPELINE_SOURCE == "schedule"
# merge release
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "dev"
variables:
BRANCH: dev
extends:
- .gitlab_to_github_gitee
# manual sync
manual_sync:
stage: release
rules:
- if: '$CI_PIPELINE_SOURCE == "web"'
when: always
variables:
BRANCH: dev
extends:
- .gitlab_to_github_gitee
# github webhook trigger sync
github_to_gitlab:
stage: release
rules:
# trigger with args
- if: '$CI_PIPELINE_SOURCE == "trigger" && $GITHUB_PUSH == "true"'
# trigger without args
- if: '$CI_PIPELINE_SOURCE == "trigger"'
variables:
BRANCH: dev
extends:
- .github_to_gitlab_gitee
# build setup for all jobs
build_setup:
stage: build_setup
rules:
# MR job
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
# release job
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG =~ /^v\d+\.\d+.*$/
# pre-release job
- if: $CI_PIPELINE_SOURCE == "web"
# daily build
- if: $CI_PIPELINE_SOURCE == "schedule"
timeout: 5m
script:
- echo "build env setup"
- *get_job_type
- *latest_version
- *generate_version
- echo "JOB_TYPE=${JOB_TYPE}" >> build.env
- echo "DST_BASE=${DST_BASE}" >> build.env
- echo "SUB_BASE=${new_ver}" >> build.env
artifacts:
reports:
dotenv: build.env
build-image:
stage: build_src
needs: [build_setup]
parallel:
matrix:
- CONF:
- k230_canmv_defconfig
- k230d_canmv_defconfig
- BPI-CanMV-K230D-Zero_defconfig
variables:
DST_BASE: /data1/k230/gitlab-ci/images/${CI_PROJECT_NAME}
SRC_DIR: ./output/${CONF}/images
rules:
# MR open
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
# release job
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG =~ /^v\d+\.\d+.*$/
# pre-release job
- if: $CI_PIPELINE_SOURCE == "web" && $CI_COMMIT_TAG =~ /^v\d+\.\d+.*$/
# manual job
- if: $CI_PIPELINE_SOURCE == "web" && $CI_COMMIT_TAG !~ /^v\d+\.\d+.*$/
# daily build
- if: $CI_PIPELINE_SOURCE == "schedule"