blob: dfb0ce0fbdca76360b0d5b48ac78a653693c3ebb [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
Saheer Babu793e0142025-08-15 17:23:39 +010032host_arch=$(dpkg-architecture -qDEB_HOST_ARCH)
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030033
34if ! type aws
35then
Saheer Babuff8bf092025-08-15 16:43:26 +010036 sudo yum update -y -q
37 sudo yum install unzip -y -q
Saheer Babu793e0142025-08-15 17:23:39 +010038 arch=$(uname -m)
39 curl "https://awscli.amazonaws.com/awscli-exe-linux-${arch}.zip" -o "awscliv2.zip"
Paul Sokolovsky0810ea22022-11-11 22:23:41 +030040 unzip -q awscliv2.zip
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030041 sudo ./aws/install
42fi
43
Riku Voipiob8ffb562020-10-12 11:44:40 +030044rm -f ${WORKSPACE}/log
Benjamin Copelandc78807d2019-04-02 08:54:42 +010045cd dockerfiles/
46
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030047aws configure list
Saheer Babu734d2ad2024-12-19 09:38:47 +000048aws s3 cp --recursive s3://openci-trustedfirmware-private-${INFRA_ENV}/armclang/ .
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030049find .
50
51df -h
52
Benjamin Copelandc78807d2019-04-02 08:54:42 +010053git_previous_commit=$(git rev-parse HEAD~1)
54git_commit=$(git rev-parse HEAD)
55files=$(git diff --name-only ${git_previous_commit} ${git_commit})
56echo Changes in: ${files}
Riku Voipiob8ffb562020-10-12 11:44:40 +030057changed_dirs=$(dirname ${files}|sort -u)
Benjamin Copelandc78807d2019-04-02 08:54:42 +010058
59update_images=""
60for dir in ${changed_dirs}; do
61 # Find the closest directory with build.sh. This is, primarily,
62 # to handle changes to tcwg-base/tcwg-build/tcwg-builslave/* directories.
63 while [ ! -e ${dir}/build.sh -a ! -e ${dir}/.git ]; do
64 dir=$(dirname ${dir})
65 done
66 # Add this and all dependant images in the update.
67 dir_basename=$(basename ${dir})
68 case "${dir_basename}" in
69 "tcwg-"*)
70 # ${dir} is one of generic tcwg-base/* directories. Add dependent
71 # images to the list.
72 update_images="${update_images} $(dirname $(find . -path "*-${dir_basename}*/build.sh" | sed -e "s#^\./##g"))"
73 ;;
Riku Voipiob8ffb562020-10-12 11:44:40 +030074 ".")
75 continue
76 ;;
Benjamin Copelandc78807d2019-04-02 08:54:42 +010077 *)
78 update_images="${update_images} $(dirname $(find ${dir} -name build.sh))"
79 ;;
80 esac
81done
82update_images="$(echo "${update_images}" | tr " " "\n" | sort -u)"
83
Saheer Babu793e0142025-08-15 17:23:39 +010084
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
Saheer Babuaa6f8e92025-08-15 17:14:52 +0100101 "skip:"*)
102 echo "Skipping: don't need to build ${image} on branch ${GERRIT_BRANCH}"
103 ;;
Benjamin Copelandc78807d2019-04-02 08:54:42 +0100104 "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