-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathbuild-tests.sh
executable file
·165 lines (147 loc) · 4.33 KB
/
build-tests.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
#!/bin/bash
# git clone https://github.com/OSInside/kiwi.git
# Simple build test script to build the integration test
# images from a given test directory. The host to run this
# command requires the following tools:
#
# - tree
# - git
# - xmllint
# - podman
# - pip
#
# And requires the installation of the kiwi box plugin
#
# $ pip install --upgrade kiwi-boxed-plugin
#
set -e
ARGUMENT_LIST=(
"test-dir:"
"test-name:"
"box-name:"
"vm"
)
function usage() {
echo "usage: build-tests --test-dir <dir>"
echo " --test-dir <dir>"
echo " Some test dir name, e.g. build-tests/x86/tumbleweed/"
echo " --test-name <name>"
echo " some test name, e.g. test-image-disk"
echo " --box-name <name>"
echo " name of the box to use for the build, default: universal"
echo " --vm"
echo " build in a virtual machine instead of a container"
}
if ! opts=$(getopt \
--longoptions "$(printf "%s," "${ARGUMENT_LIST[@]}")" \
--name "$(basename "$0")" \
--options "" \
-- "$@"
); then
usage
exit 0
fi
eval set --"${opts}"
while [[ $# -gt 0 ]]; do
case "$1" in
--test-dir)
argTestDir=$2
shift 2
;;
--test-name)
argTestName=$2
shift 2
;;
--box-name)
argBoxName=$2
shift 2
;;
--vm)
argVM=1
shift
;;
*)
break
;;
esac
done
if [ ! "${argTestDir}" ];then
usage
exit 1
fi
if [ ! -e "${argTestDir}"/.repos ];then
echo "No .repos information for specified test dir"
exit 1
fi
boxname=universal
if [ "${argBoxName}" ];then
boxname="${argBoxName}"
fi
function create_repo_list() {
local build_dir=$1
if [ -s "${build_dir}"/.repos ];then
local repo_options="--ignore-repos"
while read -r repo;do
repo_options="${repo_options} --add-repo ${repo}"
done < "${build_dir}"/.repos
echo "${repo_options}"
fi
}
function create_build_commands() {
local build_dir=$1
local test_name=$2
build_commands=()
for image in "${build_dir}"/*;do
test -e "${image}/appliance.kiwi" || continue
test -e "${image}/.skip_boxbuild_container" && continue
base_image=$(basename "${image}")
if [ -n "${test_name}" ] && [ ! "${test_name}" = "${base_image}" ];then
continue
fi
build_command="kiwi-ng --debug"
has_profiles=false
repo_options=$(create_repo_list "${build_dir}")
box_options="system boxbuild --box ${boxname}"
if [ ! "${argVM}" = 1 ];then
box_options="${box_options} --container"
fi
for profile in $(
xmllint --xpath "//image/profiles/profile/@name" \
"${image}/appliance.kiwi" 2>/dev/null | cut -f2 -d\"
);do
has_profiles=true
target_dir="build_results/${base_image}/${profile}"
build_command="${build_command} --profile ${profile}"
build_command="${build_command} ${box_options} --"
build_command="${build_command} --description $image"
build_command="${build_command} ${repo_options}"
build_command="${build_command} --target-dir ${target_dir}"
echo "${build_command}" \
> "build_results/${base_image}-${profile}.build"
build_commands+=( "${build_command}" )
build_command="kiwi-ng --debug"
done
if [ "${has_profiles}" = "false" ];then
target_dir="build_results/${base_image}"
build_command="${build_command} ${box_options} --"
build_command="${build_command} --description $image"
build_command="${build_command} ${repo_options}"
build_command="${build_command} --target-dir ${target_dir}"
echo "${build_command}" \
> "build_results/${base_image}.build"
build_commands+=( "${build_command}" )
fi
done
}
# create results directory
mkdir -p build_results
# build command list
create_build_commands "${argTestDir}" "${argTestName}"
# build them in a row
for build in "${build_commands[@]}";do
${build}
sudo rm -rf build_results/*/*/build/
sudo rm -rf build_results/*/build/
done
# show result tree
test -d build_results && tree -L 3 build_results