blob: c872ab7fc029a92f5eafcf2d40b9b8d4b583c4a3 [file] [log] [blame]
Leonardo Sandovald1b6b5a2021-09-13 12:06:26 -05001#!/usr/bin/env bash
2#
Mikael Olssonfb99d0a2023-03-09 14:58:48 +01003# Copyright (c) 2021-2023 Arm Limited. All rights reserved.
Leonardo Sandovald1b6b5a2021-09-13 12:06:26 -05004#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7# Clones and checkout TF-A related repositories in case these are not present
8# under SHARE_FOLDER, otherwise copy the share repositories into current folder
9# (workspace)
10
11# The way it works is simple: the top level job sets the SHARE_FOLDER
12# parameter based on its name and number on top of the share
13# volume (/srv/shared/<job name>/<job number>) then it calls the clone
14# script (clone.sh), which in turn it fetches the repositories mentioned
15# above. Jobs triggered on behalf of the latter, share the same
16# SHARE_FOLDER value, and these in turn also call the clone script, but
17# in this case, the script detects that the folder is already populated so
18# its role is to simply copy the repositories into the job's
19# workspace. As seen, all jobs work with repositories on their own
20# workspace, which are just copies of the share folder, so there is no
21# change of a race condition, i.e every job works with its own copy. The
22# worst case scenario is where the down-level job, tf-a-builder, uses its
23# default SHARE_FOLDER value, in this case, it would simply clone its
24# own repositories without reusing any file however the current approach
25# prevents the latter unless the job is triggered manually from the
26# builder job itself.
27
Chris Kayb0392862022-12-23 13:48:01 +000028set -ex
Leonardo Sandovald1b6b5a2021-09-13 12:06:26 -050029
30# Global defaults
31REFSPEC_MASTER="refs/heads/master"
Manish V Badarkheb75a15e2025-04-11 09:16:55 +010032REFSPEC_MAIN="refs/heads/main"
Manish V Badarkhe7415ae52024-10-16 08:30:06 +010033REFSPEC_TF_M_TESTS="refs/heads/tfa_ci_dep_revision"
34REFSPEC_TF_M_EXTRAS="refs/heads/tfa_ci_dep_revision"
Leonardo Sandovald1b6b5a2021-09-13 12:06:26 -050035GIT_REPO="https://git.trustedfirmware.org"
36GERRIT_HOST="https://review.trustedfirmware.org"
Leonardo Sandoval49a18a42021-09-26 19:48:53 -050037GIT_CLONE_PARAMS=""
Paul Sokolovskyd6b76192023-06-20 16:18:35 +030038SSH_PARAMS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o PubkeyAcceptedKeyTypes=+ssh-rsa -p 29418 -i ${CI_BOT_KEY}"
Arthur She3eb254e2022-09-18 20:41:03 -070039GERRIT_QUERY_PARAMS="--format=JSON --patch-sets --current-patch-set status:open"
Leonardo Sandovald1b6b5a2021-09-13 12:06:26 -050040
41# Defaults Projects
Arthur She3eb254e2022-09-18 20:41:03 -070042TF_GERRIT_PROJECT="${TF_GERRIT_PROJECT:-TF-A/trusted-firmware-a}"
Jimmy Brisson2fbc06c2023-06-09 08:49:09 -050043TF_M_TESTS_GERRIT_PROJECT="${TF_M_TESTS_GERRIT_PROJECT:-TF-M/tf-m-tests}"
44TF_M_EXTRAS_GERRIT_PROJECT="${TF_M_EXTRAS_GERRIT_PROJECT:-TF-M/tf-m-extras}"
Arthur She3eb254e2022-09-18 20:41:03 -070045TFTF_GERRIT_PROJECT="${TFTF_GERRIT_PROJECT:-TF-A/tf-a-tests}"
Daniel Boulby9dbe6f12023-11-30 15:29:10 +000046SPM_GERRIT_PROJECT="${SPM_GERRIT_PROJECT:-hafnium/hafnium}"
Manish V Badarkheaa6c48f2025-04-09 14:03:26 +010047RMM_GERRIT_PROJECT="${RMM_GERRIT_PROJECT:-TF-RMM/tf-rmm}"
Arthur She3eb254e2022-09-18 20:41:03 -070048CI_GERRIT_PROJECT="${CI_GERRIT_PROJECT:-ci/tf-a-ci-scripts}"
Tomás González54d98012025-06-09 16:54:23 +010049ARM_FFA_GERRIT_PROJECT="${ARM_FFA_GERRIT_PROJECT:-rust-spmc/arm-ffa}"
50ARM_PL011_UART_GERRIT_PROJECT="${ARM_PL011_UART_GERRIT_PROJECT:-rust-spmc/arm-pl011-uart}"
51ARM_PSCI_GERRIT_PROJECT="${ARM_PSCI_GERRIT_PROJECT:-rust-spmc/arm-psci}"
Tomás Gonzálezdb6efeb2025-06-16 15:03:48 +010052ARM_FVP_BASE_PAC_GERRIT_PROJECT="${ARM_FVP_BASE_PAC_GERRIT_PROJECT:-rust-spmc/arm-fvp-base-pac}"
53ARM_SP805_GERRIT_PROJECT="${ARM_SP805_GERRIT_PROJECT:-rust-spmc/arm-sp805}"
54ARM_XLAT_GERRIT_PROJECT="${ARM_XLAT_GERRIT_PROJECT:-rust-spmc/arm-xlat}"
55ARM_FW_DEV_GUIDE_GERRIT_PROJECT="${ARM_FW_DEV_GUIDE_GERRIT_PROJECT:-rust-spmc/firmware-development-guide}"
Arthur She3eb254e2022-09-18 20:41:03 -070056JOBS_PROJECT="${JOBS_PROJECT:-ci/tf-a-job-configs.git}"
Leonardo Sandovald1b6b5a2021-09-13 12:06:26 -050057
58# Default Reference specs
59TF_GERRIT_REFSPEC="${TF_GERRIT_REFSPEC:-${REFSPEC_MASTER}}"
60TFTF_GERRIT_REFSPEC="${TFTF_GERRIT_REFSPEC:-${REFSPEC_MASTER}}"
Daniel Boulby9dbe6f12023-11-30 15:29:10 +000061SPM_REFSPEC="${SPM_REFSPEC:-${REFSPEC_MASTER}}"
Manish V Badarkheb75a15e2025-04-11 09:16:55 +010062RMM_REFSPEC="${RMM_REFSPEC:-${REFSPEC_MAIN}}"
Manish V Badarkhe7415ae52024-10-16 08:30:06 +010063TF_M_TESTS_GERRIT_REFSPEC="${TF_M_TESTS_GERRIT_REFSPEC:-${REFSPEC_TF_M_TESTS}}"
64TF_M_EXTRAS_GERRIT_REFSPEC="${TF_M_EXTRAS_GERRIT_REFSPEC:-${REFSPEC_TF_M_EXTRAS}}"
Zelalem Awekee8801df2021-10-25 13:41:44 -050065CI_REFSPEC="${CI_REFSPEC:-${REFSPEC_MASTER}}"
Tomás González47336e02025-06-13 10:03:13 +010066ARM_FFA_GERRIT_REFSPEC="${ARM_FFA_GERRIT_REFSPEC:-${REFSPEC_MAIN}}"
67ARM_PL011_UART_GERRIT_REFSPEC="${ARM_PL011_UART_GERRIT_REFSPEC:-${REFSPEC_MAIN}}"
68ARM_PSCI_GERRIT_REFSPEC="${ARM_PSCI_GERRIT_REFSPEC:-${REFSPEC_MAIN}}"
Tomás González47336e02025-06-13 10:03:13 +010069ARM_FVP_BASE_PAC_GERRIT_REFSPEC="${ARM_FVP_BASE_PAC_GERRIT_REFSPEC:-${REFSPEC_MAIN}}"
70ARM_SP805_GERRIT_REFSPEC="${ARM_SP805_GERRIT_REFSPEC:-${REFSPEC_MAIN}}"
71ARM_XLAT_GERRIT_REFSPEC="${ARM_XLAT_GERRIT_REFSPEC:-${REFSPEC_MAIN}}"
72ARM_FW_DEV_GUIDE_GERRIT_REFSPEC="${ARM_FW_DEV_GUIDE_GERRIT_REFSPEC:-${REFSPEC_MAIN}}"
Leonardo Sandovald1b6b5a2021-09-13 12:06:26 -050073JOBS_REFSPEC="${JOBS_REFSPEC:-${REFSPEC_MASTER}}"
74
Arthur She3eb254e2022-09-18 20:41:03 -070075JOBS_REPO_NAME="tf-a-job-configs"
76
77# Array containing "<repo host>;<project>;<repo name>;<refspec>" elements
Leonardo Sandovald1b6b5a2021-09-13 12:06:26 -050078repos=(
Arthur She3eb254e2022-09-18 20:41:03 -070079 "${GERRIT_HOST};${CI_GERRIT_PROJECT};tf-a-ci-scripts;${CI_REFSPEC}"
80 "${GERRIT_HOST};${TF_GERRIT_PROJECT};trusted-firmware-a;${TF_GERRIT_REFSPEC}"
81 "${GERRIT_HOST};${TFTF_GERRIT_PROJECT};tf-a-tests;${TFTF_GERRIT_REFSPEC}"
Daniel Boulbyc61b6cd2023-12-01 11:06:45 +000082 "${GERRIT_HOST};${SPM_GERRIT_PROJECT};spm;${SPM_REFSPEC}"
Manish V Badarkheaa6c48f2025-04-09 14:03:26 +010083 "${GERRIT_HOST};${RMM_GERRIT_PROJECT};tf-rmm;${RMM_REFSPEC}"
Jimmy Brissone4486ec2023-06-07 09:20:27 -050084 "${GERRIT_HOST};${TF_M_TESTS_GERRIT_PROJECT};tf-m-tests;${TF_M_TESTS_GERRIT_REFSPEC}"
85 "${GERRIT_HOST};${TF_M_EXTRAS_GERRIT_PROJECT};tf-m-extras;${TF_M_EXTRAS_GERRIT_REFSPEC}"
Tomás González47336e02025-06-13 10:03:13 +010086 "${GERRIT_HOST};${ARM_FFA_GERRIT_PROJECT};arm-ffa;${ARM_FFA_GERRIT_REFSPEC}"
87 "${GERRIT_HOST};${ARM_PL011_UART_GERRIT_PROJECT};arm-pl011-uart;${ARM_PL011_UART_GERRIT_REFSPEC}"
88 "${GERRIT_HOST};${ARM_PSCI_GERRIT_PROJECT};arm-psci;${ARM_PSCI_GERRIT_REFSPEC}"
Tomás González47336e02025-06-13 10:03:13 +010089 "${GERRIT_HOST};${ARM_FVP_BASE_PAC_GERRIT_PROJECT};arm-fvp-base-pac;${ARM_FVP_BASE_PAC_GERRIT_REFSPEC}"
90 "${GERRIT_HOST};${ARM_SP805_GERRIT_PROJECT};arm-sp805;${ARM_SP805_GERRIT_REFSPEC}"
91 "${GERRIT_HOST};${ARM_XLAT_GERRIT_PROJECT};arm-xlat;${ARM_XLAT_GERRIT_REFSPEC}"
Tomás González54d98012025-06-09 16:54:23 +010092 "${GERRIT_HOST};${ARM_FW_DEV_GUIDE_GERRIT_PROJECT};firmware-development-guide;${ARM_FW_DEV_GUIDE_REFSPEC}"
Leonardo Sandovald1b6b5a2021-09-13 12:06:26 -050093)
94
Paul Sokolovsky9b2a5de2023-12-18 18:25:43 +030095df -h
96
Leonardo Sandovald1b6b5a2021-09-13 12:06:26 -050097# Take into consideration non-CI runs where SHARE_FOLDER variable
98# may not be present
99if [ -z "${SHARE_FOLDER}" ]; then
100 # Default Jenkins values
101 SHARE_VOLUME="${SHARE_VOLUME:-$PWD}"
102 JOB_NAME="${JOB_NAME:-local}"
103 BUILD_NUMBER="${BUILD_NUMBER:-0}"
104 SHARE_FOLDER=${SHARE_VOLUME}/${JOB_NAME}/${BUILD_NUMBER}
105fi
106
Arthur She3eb254e2022-09-18 20:41:03 -0700107# Clone JOBS_PROJECT first, since we need a helper script there
108if [ ! -d ${SHARE_FOLDER}/${JOBS_REPO_NAME} ]; then
109 git clone ${GIT_CLONE_PARAMS} ${GIT_REPO}/${JOBS_PROJECT} ${SHARE_FOLDER}/${JOBS_REPO_NAME}
110 cd ${SHARE_FOLDER}/${JOBS_REPO_NAME}
111 git fetch origin ${JOBS_REFSPEC}
Arthur Sheb4130f62025-02-08 20:58:14 -0800112 git checkout FETCH_HEAD
Arthur She3eb254e2022-09-18 20:41:03 -0700113else
114 cd ${SHARE_FOLDER}/${JOBS_REPO_NAME}
115fi
116git log -1
117cd $OLDPWD
118cp -a -f ${SHARE_FOLDER}/${JOBS_REPO_NAME} ${PWD}/${JOBS_REPO_NAME}
119
Leonardo Sandovald1b6b5a2021-09-13 12:06:26 -0500120# clone git repos
121for repo in ${repos[@]}; do
122
123 # parse the repo elements
Arthur She3eb254e2022-09-18 20:41:03 -0700124 REPO_HOST="$(echo "${repo}" | awk -F ';' '{print $1}')"
125 REPO_PROJECT="$(echo "${repo}" | awk -F ';' '{print $2}')"
126 REPO_NAME="$(echo "${repo}" | awk -F ';' '{print $3}')"
127 REPO_DEFAULT_REFSPEC="$(echo "${repo}" | awk -F ';' '{print $4}')"
128 REPO_URL="${REPO_HOST}/${REPO_PROJECT}"
129 REPO_REFSPEC="${REPO_DEFAULT_REFSPEC}"
Zachary Leaf99dcb2b2024-10-15 14:55:50 +0100130 REPO_SSH_URL="ssh://${CI_BOT_USERNAME}@${REPO_HOST#https://}:29418/${REPO_PROJECT}"
Leonardo Sandovald1b6b5a2021-09-13 12:06:26 -0500131
Zachary Leaf81316402024-10-15 14:58:40 +0100132 # if a list of repos is provided via the CLONE_REPOS build param, only clone
133 # those in the list - otherwise all are cloned by default
134 if [[ -n "${CLONE_REPOS}" && "${CLONE_REPOS}" != *"${REPO_NAME}"* ]]; then
135 continue
136 fi
137
Arthur She3eb254e2022-09-18 20:41:03 -0700138 # clone and checkout in case it does not exist
Leonardo Sandovald1b6b5a2021-09-13 12:06:26 -0500139 if [ ! -d ${SHARE_FOLDER}/${REPO_NAME} ]; then
Harrison Mutai6cd767f2025-06-11 15:01:23 +0000140 git clone ${GIT_CLONE_PARAMS} ${REPO_URL} ${SHARE_FOLDER}/${REPO_NAME} \
141 --depth 1 --recurse-submodules --shallow-submodules
Mikael Olssonfb99d0a2023-03-09 14:58:48 +0100142 # If the Gerrit review that triggered the CI had a topic, it will be used to synchronize the other repositories
143 if [ -n "${GERRIT_TOPIC}" -a "${REPO_HOST}" = "${GERRIT_HOST}" -a "${GERRIT_PROJECT}" != "${REPO_PROJECT}" ]; then
Arthur She3eb254e2022-09-18 20:41:03 -0700144 echo "Got Gerrit Topic: ${GERRIT_TOPIC}"
145 REPO_REFSPEC="$(ssh ${SSH_PARAMS} ${CI_BOT_USERNAME}@${REPO_HOST#https://} gerrit query ${GERRIT_QUERY_PARAMS} \
Paul Sokolovsky65bc87b2023-06-20 16:00:36 +0300146 project:${REPO_PROJECT} topic:${GERRIT_TOPIC} | ${SHARE_FOLDER}/${JOBS_REPO_NAME}/scripts/parse_refspec.py)"
Arthur She3eb254e2022-09-18 20:41:03 -0700147 if [ -z "${REPO_REFSPEC}" ]; then
148 REPO_REFSPEC="${REPO_DEFAULT_REFSPEC}"
149 echo "Roll back to \"${REPO_REFSPEC}\" for \"${REPO_PROJECT}\""
150 fi
151 echo "Checkout refspec \"${REPO_REFSPEC}\" from repository \"${REPO_NAME}\""
152 fi
153
Leonardo Sandovald1b6b5a2021-09-13 12:06:26 -0500154 # fetch and checkout the corresponding refspec
155 cd ${SHARE_FOLDER}/${REPO_NAME}
Zachary Leaf99dcb2b2024-10-15 14:55:50 +0100156
157 if [[ ${FETCH_SSH} ]]; then
158 GIT_SSH_COMMAND="ssh ${SSH_PARAMS}" git fetch ${REPO_SSH_URL} ${REPO_REFSPEC}
159 else
160 git fetch ${REPO_URL} ${REPO_REFSPEC}
161 fi
162
Harrison Mutai6cd767f2025-06-11 15:01:23 +0000163 git checkout --recurse-submodules FETCH_HEAD
Paul Sokolovskyb41ac9e2022-10-14 19:23:26 +0300164 echo "Freshly cloned ${REPO_URL} (refspec ${REPO_REFSPEC}):"
Leonardo Sandovald1b6b5a2021-09-13 12:06:26 -0500165 git log -1
166 cd $OLDPWD
167
168 else
169 # otherwise just show the head's log
170 cd ${SHARE_FOLDER}/${REPO_NAME}
Paul Sokolovskyb41ac9e2022-10-14 19:23:26 +0300171 echo "Using existing shared folder checkout for ${REPO_URL}:"
Leonardo Sandovald1b6b5a2021-09-13 12:06:26 -0500172 git log -1
173 cd $OLDPWD
174 fi
175
176 # copy repository into pwd dir (workspace in CI), so each job would work
177 # on its own workspace
178 cp -a -f ${SHARE_FOLDER}/${REPO_NAME} ${PWD}/${REPO_NAME}
179
180done