-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
jenkins_ci.sh
executable file
·175 lines (144 loc) · 4.31 KB
/
jenkins_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
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
#!/bin/bash
SHOW_INFO=1
SHOW_ERROR=1
## utility functions
# use this function for info output
_info()
{
[ $SHOW_INFO -eq 1 ] && echo "INFO: ${@}"
}
# use this function for error output ex: _error
_error()
{
[ $SHOW_ERROR -eq 1 ] && echo "ERROR: ${@}"
}
configure_monorepo_watcher() {
echo "config/kernel" > family.watch
echo "config/sources" >> family.watch
echo "patch/kernel" >> family.watch
echo "patch/u-boot" >> family.watch
echo "config/boards" > board.watch
echo "config/bootscripts" >> board.watch
}
translate_family() {
local family=$1
local common_family=${family}
case $family in
meson-g12b) common_family="meson64"
;;
meson-gxbb) common_family="meson64"
;;
mesgon-gxl) common_family="meson64"
;;
sun4i) common_family="sunxi"
;;
sun5i) common_family="sunxi"
;;
sun6i) common_family="sunxi"
;;
sun7i) common_family="sunxi"
;;
sun8i) common_family="sunxi"
;;
sun9i) common_family="sunxi"
;;
sun50iw1) common_family="sunxi64"
;;
sun50iw2) common_family="sunxi64"
;;
sun50iw6) common_family="sunxi64"
;;
esac
echo "${common_family}"
}
generate_board_table() {
config_dir=build/config/boards
# files=$(ls ${config_dir}/*.conf ${config_dir}/*.wip ${config_dir}/*.csc)
files=$(ls ${config_dir}/*.conf)
rm -f board_table.csv
for file in ${files}; do
source ${file}
board=$(basename ${file}|cut -d '.' -f1)
support_level=$(basename ${file}|cut -d'.' -f2)
common_family=$(translate_family ${BOARDFAMILY})
echo "${BOARDFAMILY},${common_family},${BOARD_NAME},${board},${support_level}" >> board_table.csv
done
}
load_board_table() {
#BOARD_TABLE=$(cat ../board_table.csv|sort -r)
readarray BOARD_TABLE < board_table.csv
}
##adopted from https://github.com/slimm609/monorepo-gitwatcher
detect_git_changes() {
local watch_files=${1}
oldIFS=${IFS}
IFS=$'\r\n' GLOBIGNORE='*' command eval 'IGNORE_FILES=($(cat $watch_files))'
IFS=${oldIFS}
folders=$(git diff --name-only ${GIT_COMMIT} ${GIT_PREVIOUS_COMMIT} | sort -u | uniq)
changed_components=${folders}
for component in ${changed_components}; do
for file in ${IGNORE_FILES[@]}; do
if echo ${component} | grep -q ${file}; then
echo "${component} has changed"
fi
done
done
}
get_files_changed() {
## these var values needed by detectGitChanges.sh
echo "GIT_COMMIT=${GIT_COMMIT}"
echo "GIT_PREVIOUS_COMMIT=${GIT_PREVIOUS_COMMIT}"
family_changed="$(detect_git_changes ../family.watch)"
board_changed="$(detect_git_changes ../board.watch)"
}
get_build_target() {
current_score=0
board_score=0
# reverse sort improves grep accuracy
IFS=$'\n'
for row in ${BOARD_TABLE[@]}; do
_info "board row ${row[@]}"
family=$(echo $row|cut -d',' -f1)
board=$(echo $row|cut -d',' -f4)
for family_row in ${family_changed}; do
current_score=$(echo $family_row | fgrep -o -e ${family} -e $(translate_family ${family})|wc -c)
_info "score: ${current_score} | family_row: ${family_row}"
if [[ $current_score -gt $board_score ]]; then
board_score=$current_score
ARMBIAN_BOARD=${board}
_info "ARMBIAN_BOARD=${board}"
for branch in current edge legacy; do
if echo $family_row |fgrep -q $branch; then
_info "ARMBIAN_BRANCH=${branch}"
ARMBIAN_BRANCH=${branch}
fi
done
# break 2
fi
done
for board_row in ${board_changed}; do
current_score=$(echo $board_row | fgrep -o ${board}|wc -c)
_info "score: ${current_score} | board_row: ${board_row}"
if [[ $current_score -gt $board_score ]]; then
ARMBIAN_BOARD=${board}
_info "ARMBIAN_BOARD=${board}"
fi
done
done
_info "${ARMBIAN_BOARD} ${ARMBIAN_BRANCH} selected"
}
## ex: get_families_with_kernel_branch linux-5.6.y
get_families_with_kernel_branch() {
local kernel_branch=${1}
for match in $(grep -R BRANCH config/* | grep ${kernel_branch} | grep families |awk '{print $1}' |tr -d ':'); do
basename $match | awk -F[_\.] '{print $1}'
done
}
build_kernel() {
local build_config=${1}
./compile.sh ${build_config} BOARD=${ARMBIAN_BOARD} BRANCH=${ARMBIAN_BRANCH}
}
build_image() {
local build_config=${1}
./compile.sh ${build_config} BOARD=${ARMBIAN_BOARD} BRANCH=${ARMBIAN_BRANCH} RELEASE=${ARMBIAN_RELEASE}
}