blob: 20d571a5a999025661f23e2dbe945451845dc297 (
plain)
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
|
#!/bin/bash
set -ex
trap cleanup_exit INT TERM EXIT
cleanup_exit()
{
rm -rf ${HOME}/.docker
}
mkdir -p ${HOME}/.docker
sed -e "s|\${DOCKER_AUTH}|${DOCKER_AUTH}|" < ${WORKSPACE}/config.json > ${HOME}/.docker/config.json
chmod 0600 ${HOME}/.docker/config.json
echo ""
echo "########################################################################"
echo " Gerrit Environment"
env |grep '^GERRIT'
echo "########################################################################"
rm -rf ${WORKSPACE}/*
git clone -b ${GERRIT_BRANCH} --depth 2 https://review.linaro.org/${GERRIT_PROJECT}
cd *
git_previous_commit=$(git rev-parse HEAD~1)
git_commit=$(git rev-parse HEAD)
files=$(git diff --name-only ${git_previous_commit} ${git_commit})
echo Changes in: ${files}
changed_dirs=$(dirname ${files})
update_images=""
for dir in ${changed_dirs}; do
# Find the closest directory with build.sh. This is, primarily,
# to handle changes to tcwg-base/tcwg-build/tcwg-builslave/* directories.
while [ ! -e ${dir}/build.sh -a ! -e ${dir}/.git ]; do
dir=$(dirname ${dir})
done
# Add this and all dependant images in the update.
dir_basename=$(basename ${dir})
case "${dir_basename}" in
"tcwg-"*)
# ${dir} is one of generic tcwg-base/* directories. Add dependent
# images to the list.
update_images="${update_images} $(dirname $(find . -path "*-${dir_basename}*/build.sh" | sed -e "s#^\./##g"))"
;;
*)
update_images="${update_images} $(dirname $(find ${dir} -name build.sh))"
;;
esac
done
update_images="$(echo "${update_images}" | tr " " "\n" | sort -u)"
host_arch=$(dpkg-architecture -qDEB_HOST_ARCH)
for image in ${update_images}; do
(
cd ${image}
image_arch=$(basename ${PWD} | cut -f2 -d '-')
skip="skip"
if [ -f gerrit-branch ]; then
# Build only from branches mentioned in gerrit-branches
if grep -q "^${GERRIT_BRANCH}\$" gerrit-branches; then
skip="no"
fi
elif [ x"${GERRIT_BRANCH}" = x"master" ]; then
# No gerrit-branch file, so build only from "master" branch.
skip="no"
fi
case "${skip}:${host_arch}:${image_arch}" in
"skip:*")
echo "Skipping: don't need to build ${image} on branch ${GERRIT_BRANCH}"
;;
"no:amd64:amd64"|"no:amd64:i386"|"no:arm64:arm64"|"no:arm64:armhf")
echo "=== Start build: ${image} ==="
./build.sh || echo "=== FAIL: ${image} ===" >> ${WORKSPACE}/log
;;
*)
echo "Skipping: can't build for ${image_arch} on ${host_arch}"
;;
esac
if [ -r .docker-tag ]; then
docker_tag=$(cat .docker-tag)
if [ x"${GERRIT_BRANCH}" != x"master" ]; then
new_tag=${docker_tag}-${GERRIT_BRANCH}
docker image tag ${docker_tag} ${new_tag}
docker_tag=${new_tag}
fi
docker push ${docker_tag}
fi
)||echo $image failed >> ${WORKSPACE}/log
done
if [ -e ${WORKSPACE}/log ]
then
echo "some images failed:"
cat ${WORKSPACE}/log
exit 1
fi
|