Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # |
Mikael Olsson | fb99d0a | 2023-03-09 14:58:48 +0100 | [diff] [blame] | 3 | # Copyright (c) 2021-2023 Arm Limited. All rights reserved. |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 4 | # |
| 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 Kay | b039286 | 2022-12-23 13:48:01 +0000 | [diff] [blame] | 28 | set -ex |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 29 | |
| 30 | # Global defaults |
Harrison Mutai | 160a70a | 2025-06-13 15:14:40 +0000 | [diff] [blame] | 31 | CLONE_REPOS=${CLONE_REPOS:-trusted-firmware-a,tf-a-ci-scripts,tf-rmm,spm} |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 32 | REFSPEC_MASTER="refs/heads/master" |
Manish V Badarkhe | b75a15e | 2025-04-11 09:16:55 +0100 | [diff] [blame] | 33 | REFSPEC_MAIN="refs/heads/main" |
Manish V Badarkhe | 7415ae5 | 2024-10-16 08:30:06 +0100 | [diff] [blame] | 34 | REFSPEC_TF_M_TESTS="refs/heads/tfa_ci_dep_revision" |
| 35 | REFSPEC_TF_M_EXTRAS="refs/heads/tfa_ci_dep_revision" |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 36 | GIT_REPO="https://git.trustedfirmware.org" |
| 37 | GERRIT_HOST="https://review.trustedfirmware.org" |
Leonardo Sandoval | 49a18a4 | 2021-09-26 19:48:53 -0500 | [diff] [blame] | 38 | GIT_CLONE_PARAMS="" |
Paul Sokolovsky | d6b7619 | 2023-06-20 16:18:35 +0300 | [diff] [blame] | 39 | SSH_PARAMS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o PubkeyAcceptedKeyTypes=+ssh-rsa -p 29418 -i ${CI_BOT_KEY}" |
Arthur She | 3eb254e | 2022-09-18 20:41:03 -0700 | [diff] [blame] | 40 | GERRIT_QUERY_PARAMS="--format=JSON --patch-sets --current-patch-set status:open" |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 41 | |
| 42 | # Defaults Projects |
Arthur She | 3eb254e | 2022-09-18 20:41:03 -0700 | [diff] [blame] | 43 | TF_GERRIT_PROJECT="${TF_GERRIT_PROJECT:-TF-A/trusted-firmware-a}" |
Jimmy Brisson | 2fbc06c | 2023-06-09 08:49:09 -0500 | [diff] [blame] | 44 | TF_M_TESTS_GERRIT_PROJECT="${TF_M_TESTS_GERRIT_PROJECT:-TF-M/tf-m-tests}" |
| 45 | TF_M_EXTRAS_GERRIT_PROJECT="${TF_M_EXTRAS_GERRIT_PROJECT:-TF-M/tf-m-extras}" |
Arthur She | 3eb254e | 2022-09-18 20:41:03 -0700 | [diff] [blame] | 46 | TFTF_GERRIT_PROJECT="${TFTF_GERRIT_PROJECT:-TF-A/tf-a-tests}" |
Daniel Boulby | 9dbe6f1 | 2023-11-30 15:29:10 +0000 | [diff] [blame] | 47 | SPM_GERRIT_PROJECT="${SPM_GERRIT_PROJECT:-hafnium/hafnium}" |
Manish V Badarkhe | aa6c48f | 2025-04-09 14:03:26 +0100 | [diff] [blame] | 48 | RMM_GERRIT_PROJECT="${RMM_GERRIT_PROJECT:-TF-RMM/tf-rmm}" |
Arthur She | 3eb254e | 2022-09-18 20:41:03 -0700 | [diff] [blame] | 49 | CI_GERRIT_PROJECT="${CI_GERRIT_PROJECT:-ci/tf-a-ci-scripts}" |
Tomás González | 45c0500 | 2025-06-19 13:16:52 +0100 | [diff] [blame] | 50 | RF_GERRIT_PROJECT="${RF_GERRIT_PROJECT:-RF-A/rusted-firmware-a}" |
Tomás González | 54d9801 | 2025-06-09 16:54:23 +0100 | [diff] [blame] | 51 | ARM_FFA_GERRIT_PROJECT="${ARM_FFA_GERRIT_PROJECT:-rust-spmc/arm-ffa}" |
| 52 | ARM_PL011_UART_GERRIT_PROJECT="${ARM_PL011_UART_GERRIT_PROJECT:-rust-spmc/arm-pl011-uart}" |
| 53 | ARM_PSCI_GERRIT_PROJECT="${ARM_PSCI_GERRIT_PROJECT:-rust-spmc/arm-psci}" |
Tomás González | db6efeb | 2025-06-16 15:03:48 +0100 | [diff] [blame] | 54 | ARM_FVP_BASE_PAC_GERRIT_PROJECT="${ARM_FVP_BASE_PAC_GERRIT_PROJECT:-rust-spmc/arm-fvp-base-pac}" |
| 55 | ARM_SP805_GERRIT_PROJECT="${ARM_SP805_GERRIT_PROJECT:-rust-spmc/arm-sp805}" |
| 56 | ARM_XLAT_GERRIT_PROJECT="${ARM_XLAT_GERRIT_PROJECT:-rust-spmc/arm-xlat}" |
| 57 | ARM_FW_DEV_GUIDE_GERRIT_PROJECT="${ARM_FW_DEV_GUIDE_GERRIT_PROJECT:-rust-spmc/firmware-development-guide}" |
Arthur She | 3eb254e | 2022-09-18 20:41:03 -0700 | [diff] [blame] | 58 | JOBS_PROJECT="${JOBS_PROJECT:-ci/tf-a-job-configs.git}" |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 59 | |
| 60 | # Default Reference specs |
| 61 | TF_GERRIT_REFSPEC="${TF_GERRIT_REFSPEC:-${REFSPEC_MASTER}}" |
| 62 | TFTF_GERRIT_REFSPEC="${TFTF_GERRIT_REFSPEC:-${REFSPEC_MASTER}}" |
Daniel Boulby | 9dbe6f1 | 2023-11-30 15:29:10 +0000 | [diff] [blame] | 63 | SPM_REFSPEC="${SPM_REFSPEC:-${REFSPEC_MASTER}}" |
Manish V Badarkhe | b75a15e | 2025-04-11 09:16:55 +0100 | [diff] [blame] | 64 | RMM_REFSPEC="${RMM_REFSPEC:-${REFSPEC_MAIN}}" |
Manish V Badarkhe | 7415ae5 | 2024-10-16 08:30:06 +0100 | [diff] [blame] | 65 | TF_M_TESTS_GERRIT_REFSPEC="${TF_M_TESTS_GERRIT_REFSPEC:-${REFSPEC_TF_M_TESTS}}" |
| 66 | TF_M_EXTRAS_GERRIT_REFSPEC="${TF_M_EXTRAS_GERRIT_REFSPEC:-${REFSPEC_TF_M_EXTRAS}}" |
Zelalem Aweke | e8801df | 2021-10-25 13:41:44 -0500 | [diff] [blame] | 67 | CI_REFSPEC="${CI_REFSPEC:-${REFSPEC_MASTER}}" |
Tomás González | 45c0500 | 2025-06-19 13:16:52 +0100 | [diff] [blame] | 68 | RF_GERRIT_REFSPEC="${RF_GERRIT_REFSPEC:-${REFSPEC_MAIN}}" |
Tomás González | 47336e0 | 2025-06-13 10:03:13 +0100 | [diff] [blame] | 69 | ARM_FFA_GERRIT_REFSPEC="${ARM_FFA_GERRIT_REFSPEC:-${REFSPEC_MAIN}}" |
| 70 | ARM_PL011_UART_GERRIT_REFSPEC="${ARM_PL011_UART_GERRIT_REFSPEC:-${REFSPEC_MAIN}}" |
| 71 | ARM_PSCI_GERRIT_REFSPEC="${ARM_PSCI_GERRIT_REFSPEC:-${REFSPEC_MAIN}}" |
Tomás González | 47336e0 | 2025-06-13 10:03:13 +0100 | [diff] [blame] | 72 | ARM_FVP_BASE_PAC_GERRIT_REFSPEC="${ARM_FVP_BASE_PAC_GERRIT_REFSPEC:-${REFSPEC_MAIN}}" |
| 73 | ARM_SP805_GERRIT_REFSPEC="${ARM_SP805_GERRIT_REFSPEC:-${REFSPEC_MAIN}}" |
| 74 | ARM_XLAT_GERRIT_REFSPEC="${ARM_XLAT_GERRIT_REFSPEC:-${REFSPEC_MAIN}}" |
| 75 | ARM_FW_DEV_GUIDE_GERRIT_REFSPEC="${ARM_FW_DEV_GUIDE_GERRIT_REFSPEC:-${REFSPEC_MAIN}}" |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 76 | JOBS_REFSPEC="${JOBS_REFSPEC:-${REFSPEC_MASTER}}" |
| 77 | |
Arthur She | 3eb254e | 2022-09-18 20:41:03 -0700 | [diff] [blame] | 78 | JOBS_REPO_NAME="tf-a-job-configs" |
| 79 | |
| 80 | # Array containing "<repo host>;<project>;<repo name>;<refspec>" elements |
Harrison Mutai | 160a70a | 2025-06-13 15:14:40 +0000 | [diff] [blame] | 81 | declare -A repos_map=( |
| 82 | ["tf-a-ci-scripts"]="${GERRIT_HOST};${CI_GERRIT_PROJECT};${CI_REFSPEC}" |
| 83 | ["trusted-firmware-a"]="${GERRIT_HOST};${TF_GERRIT_PROJECT};${TF_GERRIT_REFSPEC}" |
| 84 | ["tf-a-tests"]="${GERRIT_HOST};${TFTF_GERRIT_PROJECT};${TFTF_GERRIT_REFSPEC}" |
| 85 | ["spm"]="${GERRIT_HOST};${SPM_GERRIT_PROJECT};${SPM_REFSPEC}" |
| 86 | ["tf-rmm"]="${GERRIT_HOST};${RMM_GERRIT_PROJECT};${RMM_REFSPEC}" |
| 87 | ["tf-m-tests"]="${GERRIT_HOST};${TF_M_TESTS_GERRIT_PROJECT};${TF_M_TESTS_GERRIT_REFSPEC}" |
| 88 | ["tf-m-extras"]="${GERRIT_HOST};${TF_M_EXTRAS_GERRIT_PROJECT};${TF_M_EXTRAS_GERRIT_REFSPEC}" |
| 89 | ["arm-ffa"]="${GERRIT_HOST};${ARM_FFA_GERRIT_PROJECT};${ARM_FFA_GERRIT_REFSPEC}" |
| 90 | ["arm-pl011-uart"]="${GERRIT_HOST};${ARM_PL011_UART_GERRIT_PROJECT};${ARM_PL011_UART_GERRIT_REFSPEC}" |
| 91 | ["arm-psci"]="${GERRIT_HOST};${ARM_PSCI_GERRIT_PROJECT};${ARM_PSCI_GERRIT_REFSPEC}" |
| 92 | ["arm-gic"]="${GERRIT_HOST};${ARM_GIC_GERRIT_PROJECT};${ARM_GIC_GERRIT_REFSPEC}" |
| 93 | ["arm-fvp-base-pac"]="${GERRIT_HOST};${ARM_FVP_BASE_PAC_GERRIT_PROJECT};${ARM_FVP_BASE_PAC_GERRIT_REFSPEC}" |
| 94 | ["arm-sp805"]="${GERRIT_HOST};${ARM_SP805_GERRIT_PROJECT};${ARM_SP805_GERRIT_REFSPEC}" |
| 95 | ["arm-xlat"]="${GERRIT_HOST};${ARM_XLAT_GERRIT_PROJECT};${ARM_XLAT_GERRIT_REFSPEC}" |
| 96 | ["firmware-development-guide"]="${GERRIT_HOST};${ARM_FW_DEV_GUIDE_GERRIT_PROJECT};${ARM_FW_DEV_GUIDE_REFSPEC}" |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 97 | ) |
| 98 | |
Tomás González | 45c0500 | 2025-06-19 13:16:52 +0100 | [diff] [blame] | 99 | |
Harrison Mutai | 160a70a | 2025-06-13 15:14:40 +0000 | [diff] [blame] | 100 | test_desc="${test_desc:-$TEST_DESC}" |
| 101 | if [ -n "${test_desc}" ]; then |
| 102 | build_config="$(echo "${test_desc%%:*}" | cut -d'%' -f3)" |
| 103 | # Read config fields into array safely |
| 104 | IFS=',' read -ra config_fields <<< "$build_config" |
| 105 | |
| 106 | declare -A build_configs=( |
| 107 | ["trusted-firmware-a"]="${config_fields[0]}" |
| 108 | ["tf-a-tests"]="${config_fields[1]}" |
| 109 | ["spm"]="${config_fields[4]}" |
| 110 | ["tf-rmm"]="${config_fields[5]}" |
| 111 | ) |
| 112 | fi |
| 113 | |
Paul Sokolovsky | 9b2a5de | 2023-12-18 18:25:43 +0300 | [diff] [blame] | 114 | df -h |
| 115 | |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 116 | # Take into consideration non-CI runs where SHARE_FOLDER variable |
| 117 | # may not be present |
| 118 | if [ -z "${SHARE_FOLDER}" ]; then |
| 119 | # Default Jenkins values |
| 120 | SHARE_VOLUME="${SHARE_VOLUME:-$PWD}" |
| 121 | JOB_NAME="${JOB_NAME:-local}" |
| 122 | BUILD_NUMBER="${BUILD_NUMBER:-0}" |
| 123 | SHARE_FOLDER=${SHARE_VOLUME}/${JOB_NAME}/${BUILD_NUMBER} |
| 124 | fi |
| 125 | |
Arthur She | 3eb254e | 2022-09-18 20:41:03 -0700 | [diff] [blame] | 126 | # Clone JOBS_PROJECT first, since we need a helper script there |
| 127 | if [ ! -d ${SHARE_FOLDER}/${JOBS_REPO_NAME} ]; then |
| 128 | git clone ${GIT_CLONE_PARAMS} ${GIT_REPO}/${JOBS_PROJECT} ${SHARE_FOLDER}/${JOBS_REPO_NAME} |
| 129 | cd ${SHARE_FOLDER}/${JOBS_REPO_NAME} |
| 130 | git fetch origin ${JOBS_REFSPEC} |
Arthur She | b4130f6 | 2025-02-08 20:58:14 -0800 | [diff] [blame] | 131 | git checkout FETCH_HEAD |
Arthur She | 3eb254e | 2022-09-18 20:41:03 -0700 | [diff] [blame] | 132 | else |
| 133 | cd ${SHARE_FOLDER}/${JOBS_REPO_NAME} |
| 134 | fi |
| 135 | git log -1 |
| 136 | cd $OLDPWD |
| 137 | cp -a -f ${SHARE_FOLDER}/${JOBS_REPO_NAME} ${PWD}/${JOBS_REPO_NAME} |
| 138 | |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 139 | # clone git repos |
Harrison Mutai | 160a70a | 2025-06-13 15:14:40 +0000 | [diff] [blame] | 140 | for repo in ${!repos_map[@]}; do |
| 141 | if [[ -v build_configs["$repo"] ]]; then |
| 142 | val="${build_configs[$repo]}" |
| 143 | if [[ -z "$val" || "$val" == *"nil"* ]]; then |
| 144 | continue |
| 145 | fi |
| 146 | fi |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 147 | |
| 148 | # parse the repo elements |
Harrison Mutai | 160a70a | 2025-06-13 15:14:40 +0000 | [diff] [blame] | 149 | IFS=';' read -r REPO_HOST REPO_PROJECT REPO_DEFAULT_REFSPEC <<< "${repos_map[${repo}]}" |
| 150 | |
| 151 | REPO_NAME="$repo" |
Arthur She | 3eb254e | 2022-09-18 20:41:03 -0700 | [diff] [blame] | 152 | REPO_URL="${REPO_HOST}/${REPO_PROJECT}" |
| 153 | REPO_REFSPEC="${REPO_DEFAULT_REFSPEC}" |
Zachary Leaf | 99dcb2b | 2024-10-15 14:55:50 +0100 | [diff] [blame] | 154 | REPO_SSH_URL="ssh://${CI_BOT_USERNAME}@${REPO_HOST#https://}:29418/${REPO_PROJECT}" |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 155 | |
Zachary Leaf | 8131640 | 2024-10-15 14:58:40 +0100 | [diff] [blame] | 156 | # if a list of repos is provided via the CLONE_REPOS build param, only clone |
| 157 | # those in the list - otherwise all are cloned by default |
| 158 | if [[ -n "${CLONE_REPOS}" && "${CLONE_REPOS}" != *"${REPO_NAME}"* ]]; then |
| 159 | continue |
| 160 | fi |
| 161 | |
Arthur She | 3eb254e | 2022-09-18 20:41:03 -0700 | [diff] [blame] | 162 | # clone and checkout in case it does not exist |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 163 | if [ ! -d ${SHARE_FOLDER}/${REPO_NAME} ]; then |
Tomás González | 45c0500 | 2025-06-19 13:16:52 +0100 | [diff] [blame] | 164 | if [[ ${FETCH_SSH} ]]; then |
| 165 | GIT_SSH_COMMAND="ssh ${SSH_PARAMS}" git clone ${GIT_CLONE_PARAMS} ${REPO_SSH_URL} ${SHARE_FOLDER}/${REPO_NAME} \ |
Harrison Mutai | 6cd767f | 2025-06-11 15:01:23 +0000 | [diff] [blame] | 166 | --depth 1 --recurse-submodules --shallow-submodules |
Tomás González | 45c0500 | 2025-06-19 13:16:52 +0100 | [diff] [blame] | 167 | else |
| 168 | git clone ${GIT_CLONE_PARAMS} ${REPO_URL} ${SHARE_FOLDER}/${REPO_NAME} \ |
| 169 | --depth 1 --recurse-submodules --shallow-submodules |
| 170 | fi |
| 171 | |
Mikael Olsson | fb99d0a | 2023-03-09 14:58:48 +0100 | [diff] [blame] | 172 | # If the Gerrit review that triggered the CI had a topic, it will be used to synchronize the other repositories |
| 173 | if [ -n "${GERRIT_TOPIC}" -a "${REPO_HOST}" = "${GERRIT_HOST}" -a "${GERRIT_PROJECT}" != "${REPO_PROJECT}" ]; then |
Arthur She | 3eb254e | 2022-09-18 20:41:03 -0700 | [diff] [blame] | 174 | echo "Got Gerrit Topic: ${GERRIT_TOPIC}" |
| 175 | REPO_REFSPEC="$(ssh ${SSH_PARAMS} ${CI_BOT_USERNAME}@${REPO_HOST#https://} gerrit query ${GERRIT_QUERY_PARAMS} \ |
Paul Sokolovsky | 65bc87b | 2023-06-20 16:00:36 +0300 | [diff] [blame] | 176 | project:${REPO_PROJECT} topic:${GERRIT_TOPIC} | ${SHARE_FOLDER}/${JOBS_REPO_NAME}/scripts/parse_refspec.py)" |
Arthur She | 3eb254e | 2022-09-18 20:41:03 -0700 | [diff] [blame] | 177 | if [ -z "${REPO_REFSPEC}" ]; then |
| 178 | REPO_REFSPEC="${REPO_DEFAULT_REFSPEC}" |
| 179 | echo "Roll back to \"${REPO_REFSPEC}\" for \"${REPO_PROJECT}\"" |
| 180 | fi |
| 181 | echo "Checkout refspec \"${REPO_REFSPEC}\" from repository \"${REPO_NAME}\"" |
| 182 | fi |
| 183 | |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 184 | # fetch and checkout the corresponding refspec |
| 185 | cd ${SHARE_FOLDER}/${REPO_NAME} |
Zachary Leaf | 99dcb2b | 2024-10-15 14:55:50 +0100 | [diff] [blame] | 186 | |
| 187 | if [[ ${FETCH_SSH} ]]; then |
| 188 | GIT_SSH_COMMAND="ssh ${SSH_PARAMS}" git fetch ${REPO_SSH_URL} ${REPO_REFSPEC} |
| 189 | else |
| 190 | git fetch ${REPO_URL} ${REPO_REFSPEC} |
| 191 | fi |
| 192 | |
Harrison Mutai | 6cd767f | 2025-06-11 15:01:23 +0000 | [diff] [blame] | 193 | git checkout --recurse-submodules FETCH_HEAD |
Paul Sokolovsky | b41ac9e | 2022-10-14 19:23:26 +0300 | [diff] [blame] | 194 | echo "Freshly cloned ${REPO_URL} (refspec ${REPO_REFSPEC}):" |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 195 | git log -1 |
| 196 | cd $OLDPWD |
| 197 | |
| 198 | else |
| 199 | # otherwise just show the head's log |
| 200 | cd ${SHARE_FOLDER}/${REPO_NAME} |
Paul Sokolovsky | b41ac9e | 2022-10-14 19:23:26 +0300 | [diff] [blame] | 201 | echo "Using existing shared folder checkout for ${REPO_URL}:" |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 202 | git log -1 |
| 203 | cd $OLDPWD |
| 204 | fi |
| 205 | |
| 206 | # copy repository into pwd dir (workspace in CI), so each job would work |
| 207 | # on its own workspace |
| 208 | cp -a -f ${SHARE_FOLDER}/${REPO_NAME} ${PWD}/${REPO_NAME} |
| 209 | |
| 210 | done |