Leonardo Sandoval | 7090b2c | 2021-09-17 13:20:44 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # |
Bence Balogh | 79fda44 | 2022-10-14 18:01:37 +0200 | [diff] [blame] | 3 | # Copyright (c) 2021-2022 Arm Limited. All rights reserved. |
Leonardo Sandoval | 7090b2c | 2021-09-17 13:20:44 -0500 | [diff] [blame] | 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | # Clones and checkout TF-M related repositories in case these are not present |
| 8 | # under SHARE_FOLDER, otherwise copy the share repositories into current folder |
| 9 | # (workspace) |
| 10 | |
| 11 | # |
| 12 | # The way it works is simple: the top level job sets the SHARE_FOLDER |
| 13 | # parameter based on its name and number on top of the share |
| 14 | # volume (/srv/shared/<job name>/<job number>) then it calls the clone |
| 15 | # script (clone.sh), which in turn it fetches the repositories mentioned |
| 16 | # above. Jobs triggered on behalf of the latter, share the same |
| 17 | # SHARE_FOLDER value, and these in turn also call the clone script, but |
| 18 | # in this case, the script detects that the folder is already populated so |
| 19 | # its role is to simply copy the repositories into the job's |
| 20 | # workspace. As seen, all jobs work with repositories on their own |
| 21 | # workspace, which are just copies of the share folder, so there is no |
| 22 | # change of a race condition, i.e every job works with its own copy. The |
| 23 | # worst case scenario is where the down-level job, |
| 24 | # i.e. tf-m-build-config, uses its default SHARE_FOLDER value, in this |
| 25 | # case, it would simply clone its own repositories without reusing any |
| 26 | # file however the current approach prevents the latter unless the job |
| 27 | # is triggered manually from the buider job itself. |
| 28 | # |
| 29 | |
Paul Sokolovsky | 0c5b5fa | 2022-11-09 17:42:20 +0300 | [diff] [blame] | 30 | set -e |
| 31 | |
Leonardo Sandoval | 7090b2c | 2021-09-17 13:20:44 -0500 | [diff] [blame] | 32 | # Global defaults |
| 33 | GIT_CLONE_PARAMS="--no-checkout" |
| 34 | |
| 35 | # Must projects |
| 36 | TFM_PROJECT="${CODE_REPO:?}" |
| 37 | TFM_REFSPEC="${GERRIT_REFSPEC:?}" |
| 38 | TFM_NAME="trusted-firmware-m" |
| 39 | |
| 40 | SCRIPTS_PROJECT="${CI_SCRIPTS_REPO:?}" |
| 41 | SCRIPTS_REFSPEC="${CI_SCRIPTS_BRANCH:?}" |
| 42 | SCRIPTS_NAME="tf-m-ci-scripts" |
| 43 | |
| 44 | # Optional projects |
| 45 | TFM_TESTS_PROJECT="${TFM_TESTS_URL:-}" |
| 46 | TFM_TESTS_REFSPEC="${TFM_TESTS_REFSPEC:-}" |
| 47 | TFM_TESTS_NAME="tf-m-tests" |
| 48 | |
Bence Balogh | 79fda44 | 2022-10-14 18:01:37 +0200 | [diff] [blame] | 49 | TFM_EXTRAS_PROJECT="${TFM_EXTRAS_URL:-}" |
| 50 | TFM_EXTRAS_REFSPEC="${TFM_EXTRAS_REFSPEC:-}" |
| 51 | TFM_EXTRAS_NAME="tf-m-extras" |
| 52 | |
| 53 | FREERTOS_KERNEL_PROJECT="${FREERTOS_KERNEL_URL:-}" |
| 54 | FREERTOS_KERNEL_REFSPEC="${FREERTOS_KERNEL_REFSPEC:-}" |
| 55 | FREERTOS_KERNEL_NAME="freertos-kernel" |
| 56 | |
Leonardo Sandoval | 7090b2c | 2021-09-17 13:20:44 -0500 | [diff] [blame] | 57 | MBEDTLS_PROJECT="${MBEDTLS_URL:-}" |
| 58 | MBEDTLS_REFSPEC="${MBEDTLS_VERSION:-}" |
| 59 | MBEDTLS_NAME="mbedtls" |
| 60 | |
| 61 | MCUBOOT_PROJECT="${MCUBOOT_URL:-}" |
| 62 | MCUBOOT_REFSPEC="${MCUBOOT_REFSPEC:-}" |
| 63 | MCUBOOT_NAME="mcuboot" |
| 64 | |
| 65 | PSA_ARCH_TESTS_PROJECT="${PSA_ARCH_TESTS_URL:-}" |
| 66 | PSA_ARCH_TESTS_REFSPEC="${PSA_ARCH_TESTS_VERSION:-}" |
| 67 | PSA_ARCH_TESTS_NAME="psa-arch-tests" |
| 68 | |
Xinyu Zhang | c7ad082 | 2022-11-23 17:54:26 +0800 | [diff] [blame] | 69 | QCBOR_PROJECT="${QCBOR_URL:-}" |
| 70 | QCBOR_REFSPEC="${QCBOR_VERSION:-}" |
| 71 | QCBOR_NAME="QCBOR" |
Xinyu Zhang | c9e44ca | 2021-12-01 14:52:50 +0800 | [diff] [blame] | 72 | |
Leonardo Sandoval | 7090b2c | 2021-09-17 13:20:44 -0500 | [diff] [blame] | 73 | # Array containing "<repo url>;"<repo name>;<refspec>" elements |
| 74 | repos=( |
| 75 | "${TFM_PROJECT};${TFM_NAME};${TFM_REFSPEC}" |
| 76 | "${TFM_TESTS_PROJECT};${TFM_TESTS_NAME};${TFM_TESTS_REFSPEC}" |
| 77 | "${SCRIPTS_PROJECT};${SCRIPTS_NAME};${SCRIPTS_REFSPEC}" |
| 78 | "${MBEDTLS_PROJECT};${MBEDTLS_NAME};${MBEDTLS_REFSPEC}" |
| 79 | "${MCUBOOT_PROJECT};${MCUBOOT_NAME};${MCUBOOT_REFSPEC}" |
| 80 | "${PSA_ARCH_TESTS_PROJECT};${PSA_ARCH_TESTS_NAME};${PSA_ARCH_TESTS_REFSPEC}" |
Xinyu Zhang | c7ad082 | 2022-11-23 17:54:26 +0800 | [diff] [blame] | 81 | "${QCBOR_PROJECT};${QCBOR_NAME};${QCBOR_REFSPEC}" |
Bence Balogh | 79fda44 | 2022-10-14 18:01:37 +0200 | [diff] [blame] | 82 | "${TFM_EXTRAS_PROJECT};${TFM_EXTRAS_NAME};${TFM_EXTRAS_REFSPEC}" |
| 83 | "${FREERTOS_KERNEL_PROJECT};${FREERTOS_KERNEL_NAME};${FREERTOS_KERNEL_REFSPEC}" |
Paul Sokolovsky | 67e72a2 | 2022-03-03 23:32:57 +0300 | [diff] [blame] | 84 | "https://review.trustedfirmware.org/ci/qa-tools;qa-tools;openci" |
Leonardo Sandoval | 7090b2c | 2021-09-17 13:20:44 -0500 | [diff] [blame] | 85 | ) |
| 86 | |
| 87 | # Take into consideration non-CI runs where SHARE_FOLDER variable |
| 88 | # may not be present |
| 89 | if [ -z "${SHARE_FOLDER}" ]; then |
| 90 | # Default Jenkins values |
| 91 | SHARE_VOLUME="${SHARE_VOLUME:-$PWD}" |
| 92 | JOB_NAME="${JOB_NAME:-local}" |
| 93 | BUILD_NUMBER="${BUILD_NUMBER:-0}" |
| 94 | SHARE_FOLDER=${SHARE_VOLUME}/${JOB_NAME}/${BUILD_NUMBER} |
| 95 | fi |
| 96 | |
Paul Sokolovsky | 62a23e3 | 2022-12-23 18:34:50 +0300 | [diff] [blame] | 97 | echo "Share Folder path: ${SHARE_FOLDER}" |
| 98 | echo |
| 99 | |
| 100 | # Don't print mouthfull "You are in 'detached HEAD' state." messages. |
| 101 | git config --global advice.detachedHead false |
Leonardo Sandoval | 7090b2c | 2021-09-17 13:20:44 -0500 | [diff] [blame] | 102 | |
| 103 | # clone git repos |
| 104 | for repo in ${repos[@]}; do |
| 105 | |
| 106 | # parse the repo elements |
| 107 | REPO_URL="$(echo "${repo}" | awk -F ';' '{print $1}')" |
| 108 | REPO_NAME="$(echo "${repo}" | awk -F ';' '{print $2}')" |
| 109 | REPO_REFSPEC="$(echo "${repo}" | awk -F ';' '{print $3}')" |
| 110 | |
| 111 | # in case repository is not define, just skip it |
| 112 | if [ -z "${REPO_URL}" ]; then |
| 113 | continue |
| 114 | fi |
| 115 | |
| 116 | # clone and checkout in case it does not exit |
| 117 | if [ ! -d ${SHARE_FOLDER}/${REPO_NAME} ]; then |
| 118 | git clone --quiet ${GIT_CLONE_PARAMS} ${REPO_URL} ${SHARE_FOLDER}/${REPO_NAME} |
| 119 | |
| 120 | # fetch and checkout the corresponding refspec |
| 121 | cd ${SHARE_FOLDER}/${REPO_NAME} |
| 122 | |
Paul Sokolovsky | 2ea00ca | 2022-11-09 17:58:22 +0300 | [diff] [blame] | 123 | git fetch ${REPO_URL} ${REPO_REFSPEC} |
| 124 | git checkout FETCH_HEAD |
Paul Sokolovsky | 62a23e3 | 2022-12-23 18:34:50 +0300 | [diff] [blame] | 125 | echo -e "Share Folder ${SHARE_FOLDER}/${REPO_NAME} $(git rev-parse --short HEAD)\n" |
Leonardo Sandoval | 7090b2c | 2021-09-17 13:20:44 -0500 | [diff] [blame] | 126 | cd $OLDPWD |
| 127 | |
| 128 | else |
| 129 | # otherwise just show the head's log |
| 130 | cd ${SHARE_FOLDER}/${REPO_NAME} |
Paul Sokolovsky | 62a23e3 | 2022-12-23 18:34:50 +0300 | [diff] [blame] | 131 | echo -e "Share Folder ${SHARE_FOLDER}/${REPO_NAME} $(git rev-parse --short HEAD)\n" |
Leonardo Sandoval | 7090b2c | 2021-09-17 13:20:44 -0500 | [diff] [blame] | 132 | cd $OLDPWD |
| 133 | fi |
| 134 | |
| 135 | # copy repository into pwd dir (workspace in CI), so each job would work |
| 136 | # on its own workspace |
| 137 | cp -a -f ${SHARE_FOLDER}/${REPO_NAME} ${WORKSPACE}/${REPO_NAME} |
| 138 | |
| 139 | done |