blob: 407883db5b8bc7f18e2a3bbff51e111264d6adb9 [file] [log] [blame]
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -05001#!/usr/bin/env bash
2#
Bence Balogh79fda442022-10-14 18:01:37 +02003# Copyright (c) 2021-2022 Arm Limited. All rights reserved.
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -05004#
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 Sokolovsky0c5b5fa2022-11-09 17:42:20 +030030set -e
31
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -050032# Global defaults
33GIT_CLONE_PARAMS="--no-checkout"
34
35# Must projects
36TFM_PROJECT="${CODE_REPO:?}"
37TFM_REFSPEC="${GERRIT_REFSPEC:?}"
38TFM_NAME="trusted-firmware-m"
39
40SCRIPTS_PROJECT="${CI_SCRIPTS_REPO:?}"
41SCRIPTS_REFSPEC="${CI_SCRIPTS_BRANCH:?}"
42SCRIPTS_NAME="tf-m-ci-scripts"
43
44# Optional projects
45TFM_TESTS_PROJECT="${TFM_TESTS_URL:-}"
46TFM_TESTS_REFSPEC="${TFM_TESTS_REFSPEC:-}"
47TFM_TESTS_NAME="tf-m-tests"
48
49MBEDTLS_PROJECT="${MBEDTLS_URL:-}"
50MBEDTLS_REFSPEC="${MBEDTLS_VERSION:-}"
51MBEDTLS_NAME="mbedtls"
52
53MCUBOOT_PROJECT="${MCUBOOT_URL:-}"
54MCUBOOT_REFSPEC="${MCUBOOT_REFSPEC:-}"
55MCUBOOT_NAME="mcuboot"
56
57PSA_ARCH_TESTS_PROJECT="${PSA_ARCH_TESTS_URL:-}"
58PSA_ARCH_TESTS_REFSPEC="${PSA_ARCH_TESTS_VERSION:-}"
59PSA_ARCH_TESTS_NAME="psa-arch-tests"
60
Xinyu Zhangc7ad0822022-11-23 17:54:26 +080061QCBOR_PROJECT="${QCBOR_URL:-}"
62QCBOR_REFSPEC="${QCBOR_VERSION:-}"
Xinyu Zhang1f21cb22023-06-26 17:56:49 +080063QCBOR_NAME="qcbor"
64
65TFM_EXTRAS_PROJECT="${TFM_EXTRAS_URL:-}"
66TFM_EXTRAS_REFSPEC="${TFM_EXTRAS_REFSPEC:-}"
67TFM_EXTRAS_NAME="tf-m-extras"
68
69QA_TOOLS_PROJECT="https://review.trustedfirmware.org/ci/qa-tools"
70QA_TOOLS_REFSPEC="openci"
71QA_TOOLS_NAME="qa-tools"
Xinyu Zhangc9e44ca2021-12-01 14:52:50 +080072
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -050073# Array containing "<repo url>;"<repo name>;<refspec>" elements
74repos=(
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 Zhangc7ad0822022-11-23 17:54:26 +080081 "${QCBOR_PROJECT};${QCBOR_NAME};${QCBOR_REFSPEC}"
Bence Balogh79fda442022-10-14 18:01:37 +020082 "${TFM_EXTRAS_PROJECT};${TFM_EXTRAS_NAME};${TFM_EXTRAS_REFSPEC}"
Xinyu Zhang1f21cb22023-06-26 17:56:49 +080083 "${QA_TOOLS_PROJECT};${QA_TOOLS_NAME};${QA_TOOLS_REFSPEC}"
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -050084)
85
86# Take into consideration non-CI runs where SHARE_FOLDER variable
87# may not be present
88if [ -z "${SHARE_FOLDER}" ]; then
89 # Default Jenkins values
90 SHARE_VOLUME="${SHARE_VOLUME:-$PWD}"
91 JOB_NAME="${JOB_NAME:-local}"
92 BUILD_NUMBER="${BUILD_NUMBER:-0}"
93 SHARE_FOLDER=${SHARE_VOLUME}/${JOB_NAME}/${BUILD_NUMBER}
94fi
95
Paul Sokolovsky62a23e32022-12-23 18:34:50 +030096echo "Share Folder path: ${SHARE_FOLDER}"
97echo
98
99# Don't print mouthfull "You are in 'detached HEAD' state." messages.
100git config --global advice.detachedHead false
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500101
102# clone git repos
103for repo in ${repos[@]}; do
104
105 # parse the repo elements
106 REPO_URL="$(echo "${repo}" | awk -F ';' '{print $1}')"
107 REPO_NAME="$(echo "${repo}" | awk -F ';' '{print $2}')"
108 REPO_REFSPEC="$(echo "${repo}" | awk -F ';' '{print $3}')"
109
110 # in case repository is not define, just skip it
111 if [ -z "${REPO_URL}" ]; then
112 continue
113 fi
114
115 # clone and checkout in case it does not exit
116 if [ ! -d ${SHARE_FOLDER}/${REPO_NAME} ]; then
117 git clone --quiet ${GIT_CLONE_PARAMS} ${REPO_URL} ${SHARE_FOLDER}/${REPO_NAME}
118
119 # fetch and checkout the corresponding refspec
120 cd ${SHARE_FOLDER}/${REPO_NAME}
121
Paul Sokolovsky2ea00ca2022-11-09 17:58:22 +0300122 git fetch ${REPO_URL} ${REPO_REFSPEC}
123 git checkout FETCH_HEAD
Paul Sokolovsky62a23e32022-12-23 18:34:50 +0300124 echo -e "Share Folder ${SHARE_FOLDER}/${REPO_NAME} $(git rev-parse --short HEAD)\n"
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500125 cd $OLDPWD
126
127 else
128 # otherwise just show the head's log
129 cd ${SHARE_FOLDER}/${REPO_NAME}
Paul Sokolovsky62a23e32022-12-23 18:34:50 +0300130 echo -e "Share Folder ${SHARE_FOLDER}/${REPO_NAME} $(git rev-parse --short HEAD)\n"
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500131 cd $OLDPWD
132 fi
133
134 # copy repository into pwd dir (workspace in CI), so each job would work
135 # on its own workspace
136 cp -a -f ${SHARE_FOLDER}/${REPO_NAME} ${WORKSPACE}/${REPO_NAME}
137
138done