blob: 0d3617ba3b0eb55d60cdda7f9af8acaa23d6014c [file] [log] [blame]
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -05001#!/usr/bin/env bash
2#
3# Copyright (c) 2021 Arm Limited. All rights reserved.
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
30# Global defaults
31GIT_CLONE_PARAMS="--no-checkout"
32
33# Must projects
34TFM_PROJECT="${CODE_REPO:?}"
35TFM_REFSPEC="${GERRIT_REFSPEC:?}"
36TFM_NAME="trusted-firmware-m"
37
38SCRIPTS_PROJECT="${CI_SCRIPTS_REPO:?}"
39SCRIPTS_REFSPEC="${CI_SCRIPTS_BRANCH:?}"
40SCRIPTS_NAME="tf-m-ci-scripts"
41
42# Optional projects
43TFM_TESTS_PROJECT="${TFM_TESTS_URL:-}"
44TFM_TESTS_REFSPEC="${TFM_TESTS_REFSPEC:-}"
45TFM_TESTS_NAME="tf-m-tests"
46
47MBEDTLS_PROJECT="${MBEDTLS_URL:-}"
48MBEDTLS_REFSPEC="${MBEDTLS_VERSION:-}"
49MBEDTLS_NAME="mbedtls"
50
51MCUBOOT_PROJECT="${MCUBOOT_URL:-}"
52MCUBOOT_REFSPEC="${MCUBOOT_REFSPEC:-}"
53MCUBOOT_NAME="mcuboot"
54
55PSA_ARCH_TESTS_PROJECT="${PSA_ARCH_TESTS_URL:-}"
56PSA_ARCH_TESTS_REFSPEC="${PSA_ARCH_TESTS_VERSION:-}"
57PSA_ARCH_TESTS_NAME="psa-arch-tests"
58
Xinyu Zhangc9e44ca2021-12-01 14:52:50 +080059PSA_QCBOR_PROJECT="https://github.com/laurencelundblade/QCBOR.git"
60PSA_QCBOR_REFSPEC="refs/heads/master"
61PSA_QCBOR_NAME="psa_qcbor"
62
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -050063# Array containing "<repo url>;"<repo name>;<refspec>" elements
64repos=(
65 "${TFM_PROJECT};${TFM_NAME};${TFM_REFSPEC}"
66 "${TFM_TESTS_PROJECT};${TFM_TESTS_NAME};${TFM_TESTS_REFSPEC}"
67 "${SCRIPTS_PROJECT};${SCRIPTS_NAME};${SCRIPTS_REFSPEC}"
68 "${MBEDTLS_PROJECT};${MBEDTLS_NAME};${MBEDTLS_REFSPEC}"
69 "${MCUBOOT_PROJECT};${MCUBOOT_NAME};${MCUBOOT_REFSPEC}"
70 "${PSA_ARCH_TESTS_PROJECT};${PSA_ARCH_TESTS_NAME};${PSA_ARCH_TESTS_REFSPEC}"
Xinyu Zhangc9e44ca2021-12-01 14:52:50 +080071 "${PSA_QCBOR_PROJECT};${PSA_QCBOR_NAME};${PSA_QCBOR_REFSPEC}"
Paul Sokolovsky67e72a22022-03-03 23:32:57 +030072 "https://review.trustedfirmware.org/ci/qa-tools;qa-tools;openci"
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -050073)
74
75# Take into consideration non-CI runs where SHARE_FOLDER variable
76# may not be present
77if [ -z "${SHARE_FOLDER}" ]; then
78 # Default Jenkins values
79 SHARE_VOLUME="${SHARE_VOLUME:-$PWD}"
80 JOB_NAME="${JOB_NAME:-local}"
81 BUILD_NUMBER="${BUILD_NUMBER:-0}"
82 SHARE_FOLDER=${SHARE_VOLUME}/${JOB_NAME}/${BUILD_NUMBER}
83fi
84
85echo "Share Folder ${SHARE_FOLDER}"
86
87# clone git repos
88for repo in ${repos[@]}; do
89
90 # parse the repo elements
91 REPO_URL="$(echo "${repo}" | awk -F ';' '{print $1}')"
92 REPO_NAME="$(echo "${repo}" | awk -F ';' '{print $2}')"
93 REPO_REFSPEC="$(echo "${repo}" | awk -F ';' '{print $3}')"
94
95 # in case repository is not define, just skip it
96 if [ -z "${REPO_URL}" ]; then
97 continue
98 fi
99
100 # clone and checkout in case it does not exit
101 if [ ! -d ${SHARE_FOLDER}/${REPO_NAME} ]; then
102 git clone --quiet ${GIT_CLONE_PARAMS} ${REPO_URL} ${SHARE_FOLDER}/${REPO_NAME}
103
104 # fetch and checkout the corresponding refspec
105 cd ${SHARE_FOLDER}/${REPO_NAME}
106
107 git fetch ${REPO_URL} ${REPO_REFSPEC} && git checkout FETCH_HEAD
108 echo -e "\n\nShare Folder ${SHARE_FOLDER}/${REPO_NAME} $(git rev-parse --short HEAD)\n\n"
109 cd $OLDPWD
110
111 else
112 # otherwise just show the head's log
113 cd ${SHARE_FOLDER}/${REPO_NAME}
114 echo -e "\n\nShare Folder ${SHARE_FOLDER}/${REPO_NAME} $(git rev-parse --short HEAD)\n\n"
115 cd $OLDPWD
116 fi
117
118 # copy repository into pwd dir (workspace in CI), so each job would work
119 # on its own workspace
120 cp -a -f ${SHARE_FOLDER}/${REPO_NAME} ${WORKSPACE}/${REPO_NAME}
121
122done