blob: a5b112cc627062dfd38ac07d37b40fded5cba5cb [file] [log] [blame]
Benjamin Copelandc78807d2019-04-02 08:54:42 +01001#!/bin/bash
2
3set -ex
4
Benjamin Copelandc78807d2019-04-02 08:54:42 +01005echo ""
6echo "########################################################################"
7echo " Gerrit Environment"
8env |grep '^GERRIT'
9echo "########################################################################"
10
Riku Voipiob8ffb562020-10-12 11:44:40 +030011rm -f ${WORKSPACE}/log
Benjamin Copelandc78807d2019-04-02 08:54:42 +010012cd dockerfiles/
13
14git_previous_commit=$(git rev-parse HEAD~1)
15git_commit=$(git rev-parse HEAD)
16files=$(git diff --name-only ${git_previous_commit} ${git_commit})
17echo Changes in: ${files}
Riku Voipiob8ffb562020-10-12 11:44:40 +030018changed_dirs=$(dirname ${files}|sort -u)
Benjamin Copelandc78807d2019-04-02 08:54:42 +010019
20update_images=""
21for dir in ${changed_dirs}; do
22 # Find the closest directory with build.sh. This is, primarily,
23 # to handle changes to tcwg-base/tcwg-build/tcwg-builslave/* directories.
24 while [ ! -e ${dir}/build.sh -a ! -e ${dir}/.git ]; do
25 dir=$(dirname ${dir})
26 done
27 # Add this and all dependant images in the update.
28 dir_basename=$(basename ${dir})
29 case "${dir_basename}" in
30 "tcwg-"*)
31 # ${dir} is one of generic tcwg-base/* directories. Add dependent
32 # images to the list.
33 update_images="${update_images} $(dirname $(find . -path "*-${dir_basename}*/build.sh" | sed -e "s#^\./##g"))"
34 ;;
Riku Voipiob8ffb562020-10-12 11:44:40 +030035 ".")
36 continue
37 ;;
Benjamin Copelandc78807d2019-04-02 08:54:42 +010038 *)
39 update_images="${update_images} $(dirname $(find ${dir} -name build.sh))"
40 ;;
41 esac
42done
43update_images="$(echo "${update_images}" | tr " " "\n" | sort -u)"
44
45host_arch=$(dpkg-architecture -qDEB_HOST_ARCH)
46
47for image in ${update_images}; do
48 (
49 cd ${image}
50 image_arch=$(basename ${PWD} | cut -f2 -d '-')
51 skip="skip"
52 if [ -f gerrit-branches ]; then
53 # Build only from branches mentioned in gerrit-branches
54 if grep -q "^${GERRIT_BRANCH}\$" gerrit-branches; then
55 skip="no"
56 fi
57 elif [ x"${GERRIT_BRANCH}" = x"master" ]; then
58 # No gerrit-branch file, so build only from "master" branch.
59 skip="no"
60 fi
61 case "${skip}:${host_arch}:${image_arch}" in
62 "skip:"*)
63 echo "Skipping: don't need to build ${image} on branch ${GERRIT_BRANCH}"
64 ;;
65 "no:amd64:amd64"|"no:amd64:i386"|"no:arm64:arm64"|"no:armhf:armhf")
66 echo "=== Start build: ${image} ==="
Paul Sokolovsky9c6dc902022-01-17 22:55:27 +030067 bash -x ./build.sh || echo "=== FAIL: ${image} ===" >> ${WORKSPACE}/log
Benjamin Copelandc78807d2019-04-02 08:54:42 +010068 ;;
69 *)
70 echo "Skipping: can't build for ${image_arch} on ${host_arch}"
71 ;;
72 esac
Benjamin Copelandc78807d2019-04-02 08:54:42 +010073 )||echo $image failed >> ${WORKSPACE}/log
74done
75