blob: 6ec7a0a22b75734061f8795595d9bbf7711fae5a [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 Babue3544f12025-08-15 12:56:04 +010025# # For dpkg-architecture call below
26# if ! type dpkg-architecture
27# then
28# sudo apt-get -y -qq update
29# sudo apt-get -y -qq install --no-install-recommends dpkg-dev
30# fi
31
32sleep 3600
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030033
34if ! type aws
35then
36 sudo apt-get -y -qq update
37 sudo apt-get -y -qq install --no-install-recommends unzip
38 curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
Paul Sokolovsky0810ea22022-11-11 22:23:41 +030039 unzip -q awscliv2.zip
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030040 sudo ./aws/install
41fi
42
Riku Voipiob8ffb562020-10-12 11:44:40 +030043rm -f ${WORKSPACE}/log
Benjamin Copelandc78807d2019-04-02 08:54:42 +010044cd dockerfiles/
45
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030046aws configure list
Saheer Babu734d2ad2024-12-19 09:38:47 +000047aws s3 cp --recursive s3://openci-trustedfirmware-private-${INFRA_ENV}/armclang/ .
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030048find .
49
50df -h
51
Benjamin Copelandc78807d2019-04-02 08:54:42 +010052git_previous_commit=$(git rev-parse HEAD~1)
53git_commit=$(git rev-parse HEAD)
54files=$(git diff --name-only ${git_previous_commit} ${git_commit})
55echo Changes in: ${files}
Riku Voipiob8ffb562020-10-12 11:44:40 +030056changed_dirs=$(dirname ${files}|sort -u)
Benjamin Copelandc78807d2019-04-02 08:54:42 +010057
58update_images=""
59for dir in ${changed_dirs}; do
60 # Find the closest directory with build.sh. This is, primarily,
61 # to handle changes to tcwg-base/tcwg-build/tcwg-builslave/* directories.
62 while [ ! -e ${dir}/build.sh -a ! -e ${dir}/.git ]; do
63 dir=$(dirname ${dir})
64 done
65 # Add this and all dependant images in the update.
66 dir_basename=$(basename ${dir})
67 case "${dir_basename}" in
68 "tcwg-"*)
69 # ${dir} is one of generic tcwg-base/* directories. Add dependent
70 # images to the list.
71 update_images="${update_images} $(dirname $(find . -path "*-${dir_basename}*/build.sh" | sed -e "s#^\./##g"))"
72 ;;
Riku Voipiob8ffb562020-10-12 11:44:40 +030073 ".")
74 continue
75 ;;
Benjamin Copelandc78807d2019-04-02 08:54:42 +010076 *)
77 update_images="${update_images} $(dirname $(find ${dir} -name build.sh))"
78 ;;
79 esac
80done
81update_images="$(echo "${update_images}" | tr " " "\n" | sort -u)"
82
83host_arch=$(dpkg-architecture -qDEB_HOST_ARCH)
84
85for image in ${update_images}; do
86 (
87 cd ${image}
88 image_arch=$(basename ${PWD} | cut -f2 -d '-')
89 skip="skip"
90 if [ -f gerrit-branches ]; then
91 # Build only from branches mentioned in gerrit-branches
92 if grep -q "^${GERRIT_BRANCH}\$" gerrit-branches; then
93 skip="no"
94 fi
95 elif [ x"${GERRIT_BRANCH}" = x"master" ]; then
96 # No gerrit-branch file, so build only from "master" branch.
97 skip="no"
98 fi
99 case "${skip}:${host_arch}:${image_arch}" in
100 "skip:"*)
101 echo "Skipping: don't need to build ${image} on branch ${GERRIT_BRANCH}"
102 ;;
103 "no:amd64:amd64"|"no:amd64:i386"|"no:arm64:arm64"|"no:armhf:armhf")
104 echo "=== Start build: ${image} ==="
Paul Sokolovsky9c6dc902022-01-17 22:55:27 +0300105 bash -x ./build.sh || echo "=== FAIL: ${image} ===" >> ${WORKSPACE}/log
Benjamin Copelandc78807d2019-04-02 08:54:42 +0100106 ;;
107 *)
108 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