blob: ad5d4e8141c98f7a77190023ef43b41794696a9f [file] [log] [blame]
Paul Sokolovskydedc4832022-01-17 23:26:30 +03001#!/bin/bash
2
3set -ex
4
5echo ""
6echo "########################################################################"
7echo " Gerrit Environment"
8env |grep '^GERRIT'
9echo "########################################################################"
10
Paul Sokolovskyccdd8542022-11-11 17:53:32 +030011# For dpkg-architecture call below
12sudo apt-get -y -qq install --no-install-recommends dpkg-dev
13
Paul Sokolovsky8364b0d2022-11-11 12:35:21 +030014if ! type aws
15then
16 sudo apt-get -y -qq update
17 sudo apt-get -y -qq install --no-install-recommends unzip
18 curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
19 unzip awscliv2.zip
20 sudo ./aws/install
21fi
22
Paul Sokolovskydedc4832022-01-17 23:26:30 +030023rm -f ${WORKSPACE}/log
24cd dockerfiles/
25
Paul Sokolovsky8364b0d2022-11-11 12:35:21 +030026aws configure list
Paul Sokolovskyc0170002022-11-11 17:00:43 +030027aws s3 cp --recursive s3://trustedfirmware-private/ .
Paul Sokolovsky8364b0d2022-11-11 12:35:21 +030028
Paul Sokolovskydedc4832022-01-17 23:26:30 +030029git_previous_commit=$(git rev-parse HEAD~1)
30git_commit=$(git rev-parse HEAD)
31files=$(git diff --name-only ${git_previous_commit} ${git_commit})
32echo Changes in: ${files}
33changed_dirs=$(dirname ${files}|sort -u)
34
35update_images=""
36for dir in ${changed_dirs}; do
37 # Find the closest directory with build.sh. This is, primarily,
38 # to handle changes to tcwg-base/tcwg-build/tcwg-builslave/* directories.
39 while [ ! -e ${dir}/build.sh -a ! -e ${dir}/.git ]; do
40 dir=$(dirname ${dir})
41 done
42 # Add this and all dependant images in the update.
43 dir_basename=$(basename ${dir})
44 case "${dir_basename}" in
45 "tcwg-"*)
46 # ${dir} is one of generic tcwg-base/* directories. Add dependent
47 # images to the list.
48 update_images="${update_images} $(dirname $(find . -path "*-${dir_basename}*/build.sh" | sed -e "s#^\./##g"))"
49 ;;
50 ".")
51 continue
52 ;;
53 *)
54 update_images="${update_images} $(dirname $(find ${dir} -name build.sh))"
55 ;;
56 esac
57done
58update_images="$(echo "${update_images}" | tr " " "\n" | sort -u)"
59
60host_arch=$(dpkg-architecture -qDEB_HOST_ARCH)
61
62for image in ${update_images}; do
63 (
64 cd ${image}
65 image_arch=$(basename ${PWD} | cut -f2 -d '-')
66 skip="skip"
67 if [ -f gerrit-branches ]; then
68 # Build only from branches mentioned in gerrit-branches
69 if grep -q "^${GERRIT_BRANCH}\$" gerrit-branches; then
70 skip="no"
71 fi
72 elif [ x"${GERRIT_BRANCH}" = x"master" ]; then
73 # No gerrit-branch file, so build only from "master" branch.
74 skip="no"
75 fi
76 case "${skip}:${host_arch}:${image_arch}" in
77 "skip:"*)
78 echo "Skipping: don't need to build ${image} on branch ${GERRIT_BRANCH}"
79 ;;
80 "no:amd64:amd64"|"no:amd64:i386"|"no:arm64:arm64"|"no:armhf:armhf")
81 echo "=== Start build: ${image} ==="
82 bash -x ./build.sh || echo "=== FAIL: ${image} ===" >> ${WORKSPACE}/log
83 ;;
84 *)
85 echo "Skipping: can't build for ${image_arch} on ${host_arch}"
86 ;;
87 esac
88 )||echo $image failed >> ${WORKSPACE}/log
89done
90