blob: 1cec1231019d6bbb179d0a5ebdebe53c9887b50e [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
28 sudo yum update -y
29 sudo yum install dpkg-dev -y
30fi
Saheer Babue3544f12025-08-15 12:56:04 +010031
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030032
33if ! type aws
34then
Saheer Babu7ed3dfc2025-08-15 13:00:19 +010035 sudo yum update -y
36 sudo yum install unzip -y
37 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 Babuaf5ef8d2025-08-15 15:27:20 +010082uname -a
83sleep 600
Saheer Babu8e44cb22025-08-15 15:31:29 +010084host_arch=$(dpkg-architecture -qDEB_HOST_ARCH)
Benjamin Copelandc78807d2019-04-02 08:54:42 +010085
86for image in ${update_images}; do
87 (
88 cd ${image}
89 image_arch=$(basename ${PWD} | cut -f2 -d '-')
90 skip="skip"
91 if [ -f gerrit-branches ]; then
92 # Build only from branches mentioned in gerrit-branches
93 if grep -q "^${GERRIT_BRANCH}\$" gerrit-branches; then
94 skip="no"
95 fi
96 elif [ x"${GERRIT_BRANCH}" = x"master" ]; then
97 # No gerrit-branch file, so build only from "master" branch.
98 skip="no"
99 fi
100 case "${skip}:${host_arch}:${image_arch}" in
101 "skip:"*)
102 echo "Skipping: don't need to build ${image} on branch ${GERRIT_BRANCH}"
103 ;;
104 "no:amd64:amd64"|"no:amd64:i386"|"no:arm64:arm64"|"no:armhf:armhf")
105 echo "=== Start build: ${image} ==="
Paul Sokolovsky9c6dc902022-01-17 22:55:27 +0300106 bash -x ./build.sh || echo "=== FAIL: ${image} ===" >> ${WORKSPACE}/log
Benjamin Copelandc78807d2019-04-02 08:54:42 +0100107 ;;
108 *)
109 echo "Skipping: can't build for ${image_arch} on ${host_arch}"
110 ;;
111 esac
Benjamin Copelandc78807d2019-04-02 08:54:42 +0100112 )||echo $image failed >> ${WORKSPACE}/log
113done
114