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 |
| 31 | REFSPEC_MASTER="refs/heads/master" |
Manish V Badarkhe | b75a15e | 2025-04-11 09:16:55 +0100 | [diff] [blame] | 32 | REFSPEC_MAIN="refs/heads/main" |
Manish V Badarkhe | 7415ae5 | 2024-10-16 08:30:06 +0100 | [diff] [blame] | 33 | REFSPEC_TF_M_TESTS="refs/heads/tfa_ci_dep_revision" |
| 34 | REFSPEC_TF_M_EXTRAS="refs/heads/tfa_ci_dep_revision" |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 35 | GIT_REPO="https://git.trustedfirmware.org" |
| 36 | GERRIT_HOST="https://review.trustedfirmware.org" |
Leonardo Sandoval | 49a18a4 | 2021-09-26 19:48:53 -0500 | [diff] [blame] | 37 | GIT_CLONE_PARAMS="" |
Paul Sokolovsky | d6b7619 | 2023-06-20 16:18:35 +0300 | [diff] [blame] | 38 | 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] | 39 | GERRIT_QUERY_PARAMS="--format=JSON --patch-sets --current-patch-set status:open" |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 40 | |
| 41 | # Defaults Projects |
Saheer Babu | fd52422 | 2025-01-21 23:42:41 +0000 | [diff] [blame^] | 42 | TF_GERRIT_PROJECT="${TF_GERRIT_PROJECT:-next/TF-A/trusted-firmware-a}" |
Jimmy Brisson | 2fbc06c | 2023-06-09 08:49:09 -0500 | [diff] [blame] | 43 | TF_M_TESTS_GERRIT_PROJECT="${TF_M_TESTS_GERRIT_PROJECT:-TF-M/tf-m-tests}" |
| 44 | TF_M_EXTRAS_GERRIT_PROJECT="${TF_M_EXTRAS_GERRIT_PROJECT:-TF-M/tf-m-extras}" |
Saheer Babu | fd52422 | 2025-01-21 23:42:41 +0000 | [diff] [blame^] | 45 | TFTF_GERRIT_PROJECT="${TFTF_GERRIT_PROJECT:-next/TF-A/tf-a-tests}" |
Daniel Boulby | 9dbe6f1 | 2023-11-30 15:29:10 +0000 | [diff] [blame] | 46 | SPM_GERRIT_PROJECT="${SPM_GERRIT_PROJECT:-hafnium/hafnium}" |
Manish V Badarkhe | aa6c48f | 2025-04-09 14:03:26 +0100 | [diff] [blame] | 47 | RMM_GERRIT_PROJECT="${RMM_GERRIT_PROJECT:-TF-RMM/tf-rmm}" |
Arthur She | 3eb254e | 2022-09-18 20:41:03 -0700 | [diff] [blame] | 48 | CI_GERRIT_PROJECT="${CI_GERRIT_PROJECT:-ci/tf-a-ci-scripts}" |
| 49 | JOBS_PROJECT="${JOBS_PROJECT:-ci/tf-a-job-configs.git}" |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 50 | |
| 51 | # Default Reference specs |
| 52 | TF_GERRIT_REFSPEC="${TF_GERRIT_REFSPEC:-${REFSPEC_MASTER}}" |
| 53 | TFTF_GERRIT_REFSPEC="${TFTF_GERRIT_REFSPEC:-${REFSPEC_MASTER}}" |
Daniel Boulby | 9dbe6f1 | 2023-11-30 15:29:10 +0000 | [diff] [blame] | 54 | SPM_REFSPEC="${SPM_REFSPEC:-${REFSPEC_MASTER}}" |
Manish V Badarkhe | b75a15e | 2025-04-11 09:16:55 +0100 | [diff] [blame] | 55 | RMM_REFSPEC="${RMM_REFSPEC:-${REFSPEC_MAIN}}" |
Manish V Badarkhe | 7415ae5 | 2024-10-16 08:30:06 +0100 | [diff] [blame] | 56 | TF_M_TESTS_GERRIT_REFSPEC="${TF_M_TESTS_GERRIT_REFSPEC:-${REFSPEC_TF_M_TESTS}}" |
| 57 | 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] | 58 | CI_REFSPEC="${CI_REFSPEC:-${REFSPEC_MASTER}}" |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 59 | JOBS_REFSPEC="${JOBS_REFSPEC:-${REFSPEC_MASTER}}" |
| 60 | |
Arthur She | 3eb254e | 2022-09-18 20:41:03 -0700 | [diff] [blame] | 61 | JOBS_REPO_NAME="tf-a-job-configs" |
| 62 | |
| 63 | # Array containing "<repo host>;<project>;<repo name>;<refspec>" elements |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 64 | repos=( |
Arthur She | 3eb254e | 2022-09-18 20:41:03 -0700 | [diff] [blame] | 65 | "${GERRIT_HOST};${CI_GERRIT_PROJECT};tf-a-ci-scripts;${CI_REFSPEC}" |
| 66 | "${GERRIT_HOST};${TF_GERRIT_PROJECT};trusted-firmware-a;${TF_GERRIT_REFSPEC}" |
| 67 | "${GERRIT_HOST};${TFTF_GERRIT_PROJECT};tf-a-tests;${TFTF_GERRIT_REFSPEC}" |
Daniel Boulby | c61b6cd | 2023-12-01 11:06:45 +0000 | [diff] [blame] | 68 | "${GERRIT_HOST};${SPM_GERRIT_PROJECT};spm;${SPM_REFSPEC}" |
Manish V Badarkhe | aa6c48f | 2025-04-09 14:03:26 +0100 | [diff] [blame] | 69 | "${GERRIT_HOST};${RMM_GERRIT_PROJECT};tf-rmm;${RMM_REFSPEC}" |
Jimmy Brisson | e4486ec | 2023-06-07 09:20:27 -0500 | [diff] [blame] | 70 | "${GERRIT_HOST};${TF_M_TESTS_GERRIT_PROJECT};tf-m-tests;${TF_M_TESTS_GERRIT_REFSPEC}" |
| 71 | "${GERRIT_HOST};${TF_M_EXTRAS_GERRIT_PROJECT};tf-m-extras;${TF_M_EXTRAS_GERRIT_REFSPEC}" |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 72 | ) |
| 73 | |
Paul Sokolovsky | 9b2a5de | 2023-12-18 18:25:43 +0300 | [diff] [blame] | 74 | df -h |
| 75 | |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 76 | # Take into consideration non-CI runs where SHARE_FOLDER variable |
| 77 | # may not be present |
| 78 | if [ -z "${SHARE_FOLDER}" ]; then |
| 79 | # Default Jenkins values |
| 80 | SHARE_VOLUME="${SHARE_VOLUME:-$PWD}" |
| 81 | JOB_NAME="${JOB_NAME:-local}" |
| 82 | BUILD_NUMBER="${BUILD_NUMBER:-0}" |
| 83 | SHARE_FOLDER=${SHARE_VOLUME}/${JOB_NAME}/${BUILD_NUMBER} |
| 84 | fi |
| 85 | |
Arthur She | 3eb254e | 2022-09-18 20:41:03 -0700 | [diff] [blame] | 86 | # Clone JOBS_PROJECT first, since we need a helper script there |
| 87 | if [ ! -d ${SHARE_FOLDER}/${JOBS_REPO_NAME} ]; then |
| 88 | git clone ${GIT_CLONE_PARAMS} ${GIT_REPO}/${JOBS_PROJECT} ${SHARE_FOLDER}/${JOBS_REPO_NAME} |
| 89 | cd ${SHARE_FOLDER}/${JOBS_REPO_NAME} |
| 90 | git fetch origin ${JOBS_REFSPEC} |
Arthur She | b4130f6 | 2025-02-08 20:58:14 -0800 | [diff] [blame] | 91 | git checkout FETCH_HEAD |
Arthur She | 3eb254e | 2022-09-18 20:41:03 -0700 | [diff] [blame] | 92 | else |
| 93 | cd ${SHARE_FOLDER}/${JOBS_REPO_NAME} |
| 94 | fi |
| 95 | git log -1 |
| 96 | cd $OLDPWD |
| 97 | cp -a -f ${SHARE_FOLDER}/${JOBS_REPO_NAME} ${PWD}/${JOBS_REPO_NAME} |
| 98 | |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 99 | # clone git repos |
| 100 | for repo in ${repos[@]}; do |
| 101 | |
| 102 | # parse the repo elements |
Arthur She | 3eb254e | 2022-09-18 20:41:03 -0700 | [diff] [blame] | 103 | REPO_HOST="$(echo "${repo}" | awk -F ';' '{print $1}')" |
| 104 | REPO_PROJECT="$(echo "${repo}" | awk -F ';' '{print $2}')" |
| 105 | REPO_NAME="$(echo "${repo}" | awk -F ';' '{print $3}')" |
| 106 | REPO_DEFAULT_REFSPEC="$(echo "${repo}" | awk -F ';' '{print $4}')" |
| 107 | REPO_URL="${REPO_HOST}/${REPO_PROJECT}" |
| 108 | REPO_REFSPEC="${REPO_DEFAULT_REFSPEC}" |
Zachary Leaf | 99dcb2b | 2024-10-15 14:55:50 +0100 | [diff] [blame] | 109 | 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] | 110 | |
Zachary Leaf | 8131640 | 2024-10-15 14:58:40 +0100 | [diff] [blame] | 111 | # if a list of repos is provided via the CLONE_REPOS build param, only clone |
| 112 | # those in the list - otherwise all are cloned by default |
| 113 | if [[ -n "${CLONE_REPOS}" && "${CLONE_REPOS}" != *"${REPO_NAME}"* ]]; then |
| 114 | continue |
| 115 | fi |
| 116 | |
Arthur She | 3eb254e | 2022-09-18 20:41:03 -0700 | [diff] [blame] | 117 | # clone and checkout in case it does not exist |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 118 | if [ ! -d ${SHARE_FOLDER}/${REPO_NAME} ]; then |
| 119 | git clone ${GIT_CLONE_PARAMS} ${REPO_URL} ${SHARE_FOLDER}/${REPO_NAME} |
| 120 | |
Mikael Olsson | fb99d0a | 2023-03-09 14:58:48 +0100 | [diff] [blame] | 121 | # If the Gerrit review that triggered the CI had a topic, it will be used to synchronize the other repositories |
| 122 | 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] | 123 | echo "Got Gerrit Topic: ${GERRIT_TOPIC}" |
| 124 | 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] | 125 | 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] | 126 | if [ -z "${REPO_REFSPEC}" ]; then |
| 127 | REPO_REFSPEC="${REPO_DEFAULT_REFSPEC}" |
| 128 | echo "Roll back to \"${REPO_REFSPEC}\" for \"${REPO_PROJECT}\"" |
| 129 | fi |
| 130 | echo "Checkout refspec \"${REPO_REFSPEC}\" from repository \"${REPO_NAME}\"" |
| 131 | fi |
| 132 | |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 133 | # fetch and checkout the corresponding refspec |
| 134 | cd ${SHARE_FOLDER}/${REPO_NAME} |
Zachary Leaf | 99dcb2b | 2024-10-15 14:55:50 +0100 | [diff] [blame] | 135 | |
| 136 | if [[ ${FETCH_SSH} ]]; then |
| 137 | GIT_SSH_COMMAND="ssh ${SSH_PARAMS}" git fetch ${REPO_SSH_URL} ${REPO_REFSPEC} |
| 138 | else |
| 139 | git fetch ${REPO_URL} ${REPO_REFSPEC} |
| 140 | fi |
| 141 | |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 142 | git checkout FETCH_HEAD |
Paul Sokolovsky | b41ac9e | 2022-10-14 19:23:26 +0300 | [diff] [blame] | 143 | echo "Freshly cloned ${REPO_URL} (refspec ${REPO_REFSPEC}):" |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 144 | git log -1 |
| 145 | cd $OLDPWD |
| 146 | |
| 147 | else |
| 148 | # otherwise just show the head's log |
| 149 | cd ${SHARE_FOLDER}/${REPO_NAME} |
Paul Sokolovsky | b41ac9e | 2022-10-14 19:23:26 +0300 | [diff] [blame] | 150 | echo "Using existing shared folder checkout for ${REPO_URL}:" |
Leonardo Sandoval | d1b6b5a | 2021-09-13 12:06:26 -0500 | [diff] [blame] | 151 | git log -1 |
| 152 | cd $OLDPWD |
| 153 | fi |
| 154 | |
| 155 | # copy repository into pwd dir (workspace in CI), so each job would work |
| 156 | # on its own workspace |
| 157 | cp -a -f ${SHARE_FOLDER}/${REPO_NAME} ${PWD}/${REPO_NAME} |
| 158 | |
| 159 | done |