forked from Unireverse/mlu-ops-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci.sh
89 lines (66 loc) · 2.05 KB
/
ci.sh
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
# /bin/bash
# get PR id
PR_string=$(echo $GITHUB_REF | grep -Eo "/[0-9]*/")
pr_id=(${PR_string//// })
# generate time stamp
current=`date "+%Y-%m-%d %H:%M:%S"`
timeStamp=`date -d "$current" +%s`
currentTimeStamp=$((timeStamp*1000+10#`date "+%N"`/1000000))
# temporally set to mlu370
card_type="MLU370-S4"
# default repo name
repo_name="mlu-ops-dev"
# repo ci root path
repo_root="/github_ci/${repo_name}_ci/"
if [ ! -d $repo_root ];then
mkdir $repo_root
fi
# repo ci requests path
requests_path="$repo_root/requests"
if [ ! -d $requests_path ];then
mkdir $requests_path
fi
# gen name of this ci
request_name="${repo_name}_${pr_id}_${currentTimeStamp}_${card_type}"
# gen file and dir for this request
request_root="$repo_root/$request_name/"
sub_logs_path="$request_root/sub_logs/"
# echo "${repo_root}"
# echo "${requests_path}"
# echo "${request_root}"
if [ ! -d $request_root ];then
mkdir $request_root
fi
if [ ! -d $sub_logs_path ];then
mkdir $sub_logs_path
fi
echo "working" > "$request_root/status"
chmod o+w "$request_root/status"
if [ ! -f "$request_root/log" ];then
touch "$request_root/log"
fi
chmod o+w "$request_root/log"
if [ ! -f "$request_root/log_list" ];then
touch "$request_root/log_list"
fi
chmod o+w "$request_root/log_list"
# gen request file.
echo "${repo_name},${pr_id},${currentTimeStamp},${card_type}" > "$requests_path/${request_name}"
# change dir group for server and client, or when server/client try to delete request, ftp may raise error.
chgrp -R ftpuser $request_root
chgrp -R ftpuser $requests_path
# start script
python3 file_guard.py "$request_root/status" "$request_root/log" &
python3 combine_log.py "$request_root/log" "$request_root/log_list" "$request_root/sub_logs" "$request_root/status" &
wait
# status=$(cat ${request_root}/status)
status=$( head -n +1 ${request_root}/status )
if [ "$status" != "success" ];then
return_info=$( sed -n 2p ${request_root}/status )
echo "${return_info}"
exit -1
else
return_info=$( sed -n 2p ${request_root}/status )
echo "${return_info}"
exit 0
fi