blob: 8c6aace548490d535245c9baeb999d8898f7e95b [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Zelalemd36c2d92020-08-04 16:59:47 -05002#
3# Copyright (c) 2019, Arm Limited. All rights reserved.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8# This script is meant to be run from Jenkins to make an initial clone of the
9# CI repository.
10#
11# - If CI_SCRATCH is set, we assume that a parent job has already cloned
12# required repositories; so we skip further cloning.
13#
14# - Otherwise, we call clone_repos.sh to have all required repositories to be
15# cloned.
16#
17# Note that, since this file resides in the repository itself, a copy of this
18# file must be 'wget'. I.e., any changes to to this file must be committed first
19# to the CI repository master for it to take effect!
20
21set -e
22
Zelalem11ea6e02020-08-18 14:49:51 -050023arm_gerrit_url="gerrit.oss.arm.com"
24tforg_gerrit_url="review.trustedfirmware.org"
Zelalem90a439a2020-08-20 19:28:39 -050025ci_url="${CI_SRC_REPO_URL:-https://$arm_gerrit_url/pdswinf/ci/pdcs-platforms/platform-ci}"
Zelalem11ea6e02020-08-18 14:49:51 -050026gerrit_server="arm"
27
28if [ "$ci_url" == *${tforg_gerrit_url}* ];then
29 gerrit_server="tforg"
30fi
31
Zelalemd36c2d92020-08-04 16:59:47 -050032strip_var() {
33 local var="$1"
34 local val="$(echo "${!var}" | sed 's#^\s*\|\s*$##g')"
35 eval "$var=$val"
36}
37
38set_ci_root() {
39 ci_root=`pwd`/"platform-ci"
40 CI_ROOT=$ci_root
41}
42
43strip_var CI_REFSPEC
44
45if [ ! -z $PROJECT ]; then
46 export REPO_UNDER_TEST=`basename $PROJECT`
47 echo "REPO_UNDER_TEST is blank, but PROJECT is set, setting REPO_UNDER_TEST based on PROJECT"
48 echo "REPO_UNDER_TEST=$REPO_UNDER_TEST"
49 echo "REPO_UNDER_TEST=$REPO_UNDER_TEST" >> env
50fi
51
52# For jobs triggered by Gerrit, obtain REPO_UNDER_TEST, TF_SRC_REPO_URL
53# and TFTF_SRC_REPO_URL (if not set explicitly) from Gerrit Environment
54# variables.
55
56if [ "$GERRIT_REFSPEC" ]; then
57
58 if [ -z $REPO_UNDER_TEST ]; then
59 if [ $GERRIT_PROJECT == "pdcs-platforms/ap/tf-topics" ] || [ $GERRIT_PROJECT == "TF-A/trusted-firmware-a" ]; then
60 export REPO_UNDER_TEST="trusted-firmware"
61 echo "REPO_UNDER_TEST is blank, setting REPO_UNDER_TEST based on GERRIT_PROJECT"
62
63 elif [ $GERRIT_PROJECT == "trusted-firmware/tf-a-tests" ] || [ $GERRIT_PROJECT == "TF-A/tf-a-tests" ]; then
64 export REPO_UNDER_TEST="trusted-firmware-tf"
65 echo "REPO_UNDER_TEST is blank, setting REPO_UNDER_TEST based on GERRIT_PROJECT"
66
67 elif [ $GERRIT_PROJECT == "pdswinf/ci/pdcs-platforms/platform-ci" ]; then
68 export REPO_UNDER_TEST="trusted-firmware-ci"
69 echo "REPO_UNDER_TEST is blank, setting REPO_UNDER_TEST based on GERRIT_PROJECT"
70 fi
71 fi
72
73 if [ -z $TF_SRC_REPO_URL ] && [ $REPO_UNDER_TEST == "trusted-firmware" ]; then
74 export TF_SRC_REPO_URL="https://$GERRIT_HOST/$GERRIT_PROJECT"
75 fi
76
77 if [ -z $TFTF_SRC_REPO_URL ] && [ $REPO_UNDER_TEST == "trusted-firmware-tf" ]; then
78 export TFTF_SRC_REPO_URL="https://$GERRIT_HOST/$GERRIT_PROJECT"
79 fi
80fi
81
82if [ "$CI_ENVIRONMENT" ]; then
83 tmpfile="$(mktemp --tmpdir="$WORKSPACE")"
84 echo "$CI_ENVIRONMENT" | tr ' ' '\n' > "$tmpfile"
85 set -a
86 source "$tmpfile"
87 set +a
88fi
89
90if [ "$CI_SCRATCH" ]; then
91 if [ ! -d "$CI_SCRATCH" ]; then
92 echo "\$CI_SCRATCH is stale; ignored."
93 else
94 # Copy environment and parameter file from scratch to this job's
95 # workspace
96 cp "$CI_SCRATCH/env" .
97 cp "$CI_SCRATCH/env.param" .
98 find "$CI_SCRATCH" -name "*.data" -exec cp -t . '{}' +
99
100 exit 0
101 fi
102fi
103
104# If no CI ref specs were explicitly specified, but was triggered from a CI
105# Gerrit trigger, move to the Gerrit refspec instead so that we use the expected
106# version of clone_repos.sh.
107if [ -z "$CI_REFSPEC" ] && [ "$REPO_UNDER_TEST" = "trusted-firmware-ci" ] && \
108 [ "$GERRIT_REFSPEC" ]; then
109 export CI_REFSPEC="$GERRIT_REFSPEC"
110fi
111
112# Clone CI repository and move to the refspec
113if [ ! -d "platform-ci" ]
114then
115git clone -q --depth 1 \
116 --reference /arm/projectscratch/ssg/trusted-fw/ref-repos/trusted-firmware-ci \
Zelalem11ea6e02020-08-18 14:49:51 -0500117 $ci_url platform-ci
Zelalemd36c2d92020-08-04 16:59:47 -0500118else
119 pushd platform-ci
120 git fetch
121 git checkout origin/master
122 popd
123fi
124
125set_ci_root
126# Set CI_ROOT as a fallback
127echo "CI_ROOT=$ci_root" >> env
128
129if [ "$CI_REFSPEC" ]; then
130 # Only recent Git versions support fetching refs via. commit IDs.
131 # However, platform slaves have been updated to a version that can do
132 # this (https://jira.arm.com/browse/SSGSWINF-1426). The module load
133 # commands have been commented out since.
134 #
135 # source /arm/tools/setup/init/bash
136 # module load swdev
137 # module load git/git/2.14.3
138
139 # Translate refspec if supported
140 if [ -x "$ci_root/script/translate_refspec.py" ]; then
141 CI_REFSPEC="$("$ci_root/script/translate_refspec.py" \
Zelalem11ea6e02020-08-18 14:49:51 -0500142 -p trusted-firmware-ci -s $gerrit_server "$CI_REFSPEC")"
Zelalemd36c2d92020-08-04 16:59:47 -0500143 fi
144
145 pushd platform-ci &>/dev/null
146 git fetch -q --depth 1 origin "$CI_REFSPEC"
147 git checkout -q FETCH_HEAD
148 echo
149 echo "Initial CI repo checked out to '$CI_REFSPEC'."
150 popd &>/dev/null
151fi
152
153if [ "$ci_only" ]; then
154 exit 0
155fi
156
157if echo "$-" | grep -q "x"; then
158 minus_x="-x"
159fi
160
161if ! bash $minus_x "$ci_root/script/clone_repos.sh"; then
162 echo "clone_repos.sh failed!"
163 cat clone_repos.log
164 exit 1
165fi
166
167# vim:set tw=80 sw=8 sts=8 noet: