blob: b0ed7be6d117028b864c1e0abc961124b737d5a6 [file] [log] [blame]
Benjamin Copelandc78807d2019-04-02 08:54:42 +01001#!/bin/bash
2
3set -ex
4
Saheer Babu85b79802025-08-15 12:53:17 +01005buildah --version
Paul Sokolovskyd7a2ea72022-11-15 17:57:56 +03006
Benjamin Copelandc78807d2019-04-02 08:54:42 +01007echo ""
8echo "########################################################################"
9echo " Gerrit Environment"
10env |grep '^GERRIT'
11echo "########################################################################"
12
Saheer Babue3544f12025-08-15 12:56:04 +010013# ON_EC2="0"
14# if [ -f /sys/hypervisor/uuid ] && grep -q ^ec2 /sys/hypervisor/uuid; then
15# ON_EC2="1"
16# fi
Paul Sokolovsky73acc7f2022-11-15 14:26:20 +030017
Saheer Babue3544f12025-08-15 12:56:04 +010018# if [ "${ON_EC2}" == "1" ]; then
19# # On EC2 instances, stop and remove unattended-upgrades service which
20# # may interfere with any apt operations below.
21# sudo systemctl stop unattended-upgrades || true
22# sudo apt-get remove -y -qq unattended-upgrades
23# fi
Paul Sokolovsky73acc7f2022-11-15 14:26:20 +030024
Saheer Babu8e44cb22025-08-15 15:31:29 +010025# For dpkg-architecture call below
26if ! type dpkg-architecture
27then
Saheer Babuff8bf092025-08-15 16:43:26 +010028 sudo yum update -y -q
29 sudo yum install dpkg-dev -y -q
Saheer Babu8e44cb22025-08-15 15:31:29 +010030fi
Saheer Babue3544f12025-08-15 12:56:04 +010031
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030032
33if ! type aws
34then
Saheer Babuff8bf092025-08-15 16:43:26 +010035 sudo yum update -y -q
36 sudo yum install unzip -y -q
Saheer Babu7ed3dfc2025-08-15 13:00:19 +010037 curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip"
Paul Sokolovsky0810ea22022-11-11 22:23:41 +030038 unzip -q awscliv2.zip
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030039 sudo ./aws/install
40fi
41
Riku Voipiob8ffb562020-10-12 11:44:40 +030042rm -f ${WORKSPACE}/log
Benjamin Copelandc78807d2019-04-02 08:54:42 +010043cd dockerfiles/
44
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030045aws configure list
Saheer Babu734d2ad2024-12-19 09:38:47 +000046aws s3 cp --recursive s3://openci-trustedfirmware-private-${INFRA_ENV}/armclang/ .
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030047find .
48
49df -h
50
Benjamin Copelandc78807d2019-04-02 08:54:42 +010051git_previous_commit=$(git rev-parse HEAD~1)
52git_commit=$(git rev-parse HEAD)
53files=$(git diff --name-only ${git_previous_commit} ${git_commit})
54echo Changes in: ${files}
Riku Voipiob8ffb562020-10-12 11:44:40 +030055changed_dirs=$(dirname ${files}|sort -u)
Benjamin Copelandc78807d2019-04-02 08:54:42 +010056
57update_images=""
58for dir in ${changed_dirs}; do
59 # Find the closest directory with build.sh. This is, primarily,
60 # to handle changes to tcwg-base/tcwg-build/tcwg-builslave/* directories.
61 while [ ! -e ${dir}/build.sh -a ! -e ${dir}/.git ]; do
62 dir=$(dirname ${dir})
63 done
64 # Add this and all dependant images in the update.
65 dir_basename=$(basename ${dir})
66 case "${dir_basename}" in
67 "tcwg-"*)
68 # ${dir} is one of generic tcwg-base/* directories. Add dependent
69 # images to the list.
70 update_images="${update_images} $(dirname $(find . -path "*-${dir_basename}*/build.sh" | sed -e "s#^\./##g"))"
71 ;;
Riku Voipiob8ffb562020-10-12 11:44:40 +030072 ".")
73 continue
74 ;;
Benjamin Copelandc78807d2019-04-02 08:54:42 +010075 *)
76 update_images="${update_images} $(dirname $(find ${dir} -name build.sh))"
77 ;;
78 esac
79done
80update_images="$(echo "${update_images}" | tr " " "\n" | sort -u)"
81
Saheer Babu8e44cb22025-08-15 15:31:29 +010082host_arch=$(dpkg-architecture -qDEB_HOST_ARCH)
Benjamin Copelandc78807d2019-04-02 08:54:42 +010083
84for image in ${update_images}; do
85 (
86 cd ${image}
87 image_arch=$(basename ${PWD} | cut -f2 -d '-')
88 skip="skip"
89 if [ -f gerrit-branches ]; then
90 # Build only from branches mentioned in gerrit-branches
91 if grep -q "^${GERRIT_BRANCH}\$" gerrit-branches; then
92 skip="no"
93 fi
94 elif [ x"${GERRIT_BRANCH}" = x"master" ]; then
95 # No gerrit-branch file, so build only from "master" branch.
96 skip="no"
97 fi
98 case "${skip}:${host_arch}:${image_arch}" in
Saheer Babu57ccae92025-08-15 15:54:07 +010099 # "skip:"*)
100 # echo "Skipping: don't need to build ${image} on branch ${GERRIT_BRANCH}"
101 # ;;
Benjamin Copelandc78807d2019-04-02 08:54:42 +0100102 "no:amd64:amd64"|"no:amd64:i386"|"no:arm64:arm64"|"no:armhf:armhf")
103 echo "=== Start build: ${image} ==="
Paul Sokolovsky9c6dc902022-01-17 22:55:27 +0300104 bash -x ./build.sh || echo "=== FAIL: ${image} ===" >> ${WORKSPACE}/log
Benjamin Copelandc78807d2019-04-02 08:54:42 +0100105 ;;
106 *)
Saheer Babu4e038822025-08-15 16:00:50 +0100107 bash -x ./build.sh || echo "=== FAIL: ${image} ===" >> ${WORKSPACE}/log
Benjamin Copelandc78807d2019-04-02 08:54:42 +0100108 echo "Skipping: can't build for ${image_arch} on ${host_arch}"
109 ;;
110 esac
Benjamin Copelandc78807d2019-04-02 08:54:42 +0100111 )||echo $image failed >> ${WORKSPACE}/log
112done
113