Benjamin Copeland | c78807d | 2019-04-02 08:54:42 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -ex |
| 4 | |
Benjamin Copeland | c78807d | 2019-04-02 08:54:42 +0100 | [diff] [blame] | 5 | echo "" |
| 6 | echo "########################################################################" |
| 7 | echo " Gerrit Environment" |
| 8 | env |grep '^GERRIT' |
| 9 | echo "########################################################################" |
| 10 | |
Riku Voipio | b8ffb56 | 2020-10-12 11:44:40 +0300 | [diff] [blame] | 11 | rm -f ${WORKSPACE}/log |
Benjamin Copeland | c78807d | 2019-04-02 08:54:42 +0100 | [diff] [blame] | 12 | cd dockerfiles/ |
| 13 | |
| 14 | git_previous_commit=$(git rev-parse HEAD~1) |
| 15 | git_commit=$(git rev-parse HEAD) |
| 16 | files=$(git diff --name-only ${git_previous_commit} ${git_commit}) |
| 17 | echo Changes in: ${files} |
Riku Voipio | b8ffb56 | 2020-10-12 11:44:40 +0300 | [diff] [blame] | 18 | changed_dirs=$(dirname ${files}|sort -u) |
Benjamin Copeland | c78807d | 2019-04-02 08:54:42 +0100 | [diff] [blame] | 19 | |
| 20 | update_images="" |
| 21 | for 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 Voipio | b8ffb56 | 2020-10-12 11:44:40 +0300 | [diff] [blame] | 35 | ".") |
| 36 | continue |
| 37 | ;; |
Benjamin Copeland | c78807d | 2019-04-02 08:54:42 +0100 | [diff] [blame] | 38 | *) |
| 39 | update_images="${update_images} $(dirname $(find ${dir} -name build.sh))" |
| 40 | ;; |
| 41 | esac |
| 42 | done |
| 43 | update_images="$(echo "${update_images}" | tr " " "\n" | sort -u)" |
| 44 | |
| 45 | host_arch=$(dpkg-architecture -qDEB_HOST_ARCH) |
| 46 | |
| 47 | for 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 Sokolovsky | 9c6dc90 | 2022-01-17 22:55:27 +0300 | [diff] [blame^] | 67 | bash -x ./build.sh || echo "=== FAIL: ${image} ===" >> ${WORKSPACE}/log |
Benjamin Copeland | c78807d | 2019-04-02 08:54:42 +0100 | [diff] [blame] | 68 | ;; |
| 69 | *) |
| 70 | echo "Skipping: can't build for ${image_arch} on ${host_arch}" |
| 71 | ;; |
| 72 | esac |
Benjamin Copeland | c78807d | 2019-04-02 08:54:42 +0100 | [diff] [blame] | 73 | )||echo $image failed >> ${WORKSPACE}/log |
| 74 | done |
| 75 | |