Debian Codegraph @

build-tests.sh

raw
1 #!/bin/bash
2 # git clone https://github.com/OSInside/kiwi.git
3 # Simple build test script to build the integration test
4 # images from a given test directory. The host to run this
5 # command requires the following tools:
6 #
7 # - tree
8 # - git
9 # - xmllint
10 # - podman
11 # - pip
12 #
13 # And requires the installation of the kiwi box plugin
14 #
15 # $ pip install --upgrade kiwi-boxed-plugin
16 #
17 set -e
18
19 ARGUMENT_LIST=(
20 "test-dir:"
21 "test-name:"
22 "box-name:"
23 "vm"
24 )
25
26 function usage() {
27 echo "usage: build-tests --test-dir <dir>"
28 echo " --test-dir <dir>"
29 echo " Some test dir name, e.g. build-tests/x86/tumbleweed/"
30 echo " --test-name <name>"
31 echo " some test name, e.g. test-image-disk"
32 echo " --box-name <name>"
33 echo " name of the box to use for the build, default: universal"
34 echo " --vm"
35 echo " build in a virtual machine instead of a container"
36 }
37
38 if ! opts=$(getopt \
39 --longoptions "$(printf "%s," "${ARGUMENT_LIST[@]}")" \
40 --name "$(basename "$0")" \
41 --options "" \
42 -- "$@"
43 ); then
44 usage
45 exit 0
46 fi
47
48 eval set --"${opts}"
49
50 while [[ $# -gt 0 ]]; do
51 case "$1" in
52 --test-dir)
53 argTestDir=$2
54 shift 2
55 ;;
56
57 --test-name)
58 argTestName=$2
59 shift 2
60 ;;
61
62 --box-name)
63 argBoxName=$2
64 shift 2
65 ;;
66
67 --vm)
68 argVM=1
69 shift
70 ;;
71
72 *)
73 break
74 ;;
75 esac
76 done
77
78 if [ ! "${argTestDir}" ];then
79 usage
80 exit 1
81 fi
82
83 if [ ! -e "${argTestDir}"/.repos ];then
84 echo "No .repos information for specified test dir"
85 exit 1
86 fi
87
88 boxname=universal
89 if [ "${argBoxName}" ];then
90 boxname="${argBoxName}"
91 fi
92
93 function create_repo_list() {
94 local build_dir=$1
95 if [ -s "${build_dir}"/.repos ];then
96 local repo_options="--ignore-repos"
97 while read -r repo;do
98 repo_options="${repo_options} --add-repo ${repo}"
99 done < "${build_dir}"/.repos
100 echo "${repo_options}"
101 fi
102 }
103
104 function create_build_commands() {
105 local build_dir=$1
106 local test_name=$2
107 build_commands=()
108 for image in "${build_dir}"/*;do
109 test -e "${image}/appliance.kiwi" || continue
110 test -e "${image}/.skip_boxbuild_container" && continue
111 base_image=$(basename "${image}")
112 if [ -n "${test_name}" ] && [ ! "${test_name}" = "${base_image}" ];then
113 continue
114 fi
115 build_command="kiwi-ng --debug"
116 has_profiles=false
117 repo_options=$(create_repo_list "${build_dir}")
118 box_options="system boxbuild --box ${boxname}"
119 if [ ! "${argVM}" = 1 ];then
120 box_options="${box_options} --container"
121 fi
122 for profile in $(
123 xmllint --xpath "//image/profiles/profile/@name" \
124 "${image}/appliance.kiwi" 2>/dev/null | cut -f2 -d\"
125 );do
126 has_profiles=true
127 target_dir="build_results/${base_image}/${profile}"
128 build_command="${build_command} --profile ${profile}"
129 build_command="${build_command} ${box_options} --"
130 build_command="${build_command} --description $image"
131 build_command="${build_command} ${repo_options}"
132 build_command="${build_command} --target-dir ${target_dir}"
133 echo "${build_command}" \
134 > "build_results/${base_image}-${profile}.build"
135 build_commands+=( "${build_command}" )
136 build_command="kiwi-ng --debug"
137 done
138 if [ "${has_profiles}" = "false" ];then
139 target_dir="build_results/${base_image}"
140 build_command="${build_command} ${box_options} --"
141 build_command="${build_command} --description $image"
142 build_command="${build_command} ${repo_options}"
143 build_command="${build_command} --target-dir ${target_dir}"
144 echo "${build_command}" \
145 > "build_results/${base_image}.build"
146 build_commands+=( "${build_command}" )
147 fi
148 done
149 }
150
151 # create results directory
152 mkdir -p build_results
153
154 # build command list
155 create_build_commands "${argTestDir}" "${argTestName}"
156
157 # build them in a row
158 for build in "${build_commands[@]}";do
159 ${build}
160 sudo rm -rf build_results/*/*/build/
161 sudo rm -rf build_results/*/build/
162 done
163
164 # show result tree
165 test -d build_results && tree -L 3 build_results