blob: ebcfbd2c8515c10524372a16b81b95f1f4ea5401 [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
23strip_var() {
24 local var="$1"
25 local val="$(echo "${!var}" | sed 's#^\s*\|\s*$##g')"
26 eval "$var=$val"
27}
28
29set_ci_root() {
30 ci_root=`pwd`/"platform-ci"
31 CI_ROOT=$ci_root
32}
33
34strip_var CI_REFSPEC
35
36if [ ! -z $PROJECT ]; then
37 export REPO_UNDER_TEST=`basename $PROJECT`
38 echo "REPO_UNDER_TEST is blank, but PROJECT is set, setting REPO_UNDER_TEST based on PROJECT"
39 echo "REPO_UNDER_TEST=$REPO_UNDER_TEST"
40 echo "REPO_UNDER_TEST=$REPO_UNDER_TEST" >> env
41fi
42
43# For jobs triggered by Gerrit, obtain REPO_UNDER_TEST, TF_SRC_REPO_URL
44# and TFTF_SRC_REPO_URL (if not set explicitly) from Gerrit Environment
45# variables.
46
47if [ "$GERRIT_REFSPEC" ]; then
48
49 if [ -z $REPO_UNDER_TEST ]; then
50 if [ $GERRIT_PROJECT == "pdcs-platforms/ap/tf-topics" ] || [ $GERRIT_PROJECT == "TF-A/trusted-firmware-a" ]; then
51 export REPO_UNDER_TEST="trusted-firmware"
52 echo "REPO_UNDER_TEST is blank, setting REPO_UNDER_TEST based on GERRIT_PROJECT"
53
54 elif [ $GERRIT_PROJECT == "trusted-firmware/tf-a-tests" ] || [ $GERRIT_PROJECT == "TF-A/tf-a-tests" ]; then
55 export REPO_UNDER_TEST="trusted-firmware-tf"
56 echo "REPO_UNDER_TEST is blank, setting REPO_UNDER_TEST based on GERRIT_PROJECT"
57
58 elif [ $GERRIT_PROJECT == "pdswinf/ci/pdcs-platforms/platform-ci" ]; then
59 export REPO_UNDER_TEST="trusted-firmware-ci"
60 echo "REPO_UNDER_TEST is blank, setting REPO_UNDER_TEST based on GERRIT_PROJECT"
61 fi
62 fi
63
64 if [ -z $TF_SRC_REPO_URL ] && [ $REPO_UNDER_TEST == "trusted-firmware" ]; then
65 export TF_SRC_REPO_URL="https://$GERRIT_HOST/$GERRIT_PROJECT"
66 fi
67
68 if [ -z $TFTF_SRC_REPO_URL ] && [ $REPO_UNDER_TEST == "trusted-firmware-tf" ]; then
69 export TFTF_SRC_REPO_URL="https://$GERRIT_HOST/$GERRIT_PROJECT"
70 fi
71fi
72
73if [ "$CI_ENVIRONMENT" ]; then
74 tmpfile="$(mktemp --tmpdir="$WORKSPACE")"
75 echo "$CI_ENVIRONMENT" | tr ' ' '\n' > "$tmpfile"
76 set -a
77 source "$tmpfile"
78 set +a
79fi
80
81if [ "$CI_SCRATCH" ]; then
82 if [ ! -d "$CI_SCRATCH" ]; then
83 echo "\$CI_SCRATCH is stale; ignored."
84 else
85 # Copy environment and parameter file from scratch to this job's
86 # workspace
87 cp "$CI_SCRATCH/env" .
88 cp "$CI_SCRATCH/env.param" .
89 find "$CI_SCRATCH" -name "*.data" -exec cp -t . '{}' +
90
91 exit 0
92 fi
93fi
94
95# If no CI ref specs were explicitly specified, but was triggered from a CI
96# Gerrit trigger, move to the Gerrit refspec instead so that we use the expected
97# version of clone_repos.sh.
98if [ -z "$CI_REFSPEC" ] && [ "$REPO_UNDER_TEST" = "trusted-firmware-ci" ] && \
99 [ "$GERRIT_REFSPEC" ]; then
100 export CI_REFSPEC="$GERRIT_REFSPEC"
101fi
102
103# Clone CI repository and move to the refspec
104if [ ! -d "platform-ci" ]
105then
106git clone -q --depth 1 \
107 --reference /arm/projectscratch/ssg/trusted-fw/ref-repos/trusted-firmware-ci \
108 https://gerrit.oss.arm.com/pdswinf/ci/pdcs-platforms/platform-ci
109else
110 pushd platform-ci
111 git fetch
112 git checkout origin/master
113 popd
114fi
115
116set_ci_root
117# Set CI_ROOT as a fallback
118echo "CI_ROOT=$ci_root" >> env
119
120if [ "$CI_REFSPEC" ]; then
121 # Only recent Git versions support fetching refs via. commit IDs.
122 # However, platform slaves have been updated to a version that can do
123 # this (https://jira.arm.com/browse/SSGSWINF-1426). The module load
124 # commands have been commented out since.
125 #
126 # source /arm/tools/setup/init/bash
127 # module load swdev
128 # module load git/git/2.14.3
129
130 # Translate refspec if supported
131 if [ -x "$ci_root/script/translate_refspec.py" ]; then
132 CI_REFSPEC="$("$ci_root/script/translate_refspec.py" \
133 -p trusted-firmware-ci -s arm "$CI_REFSPEC")"
134 fi
135
136 pushd platform-ci &>/dev/null
137 git fetch -q --depth 1 origin "$CI_REFSPEC"
138 git checkout -q FETCH_HEAD
139 echo
140 echo "Initial CI repo checked out to '$CI_REFSPEC'."
141 popd &>/dev/null
142fi
143
144if [ "$ci_only" ]; then
145 exit 0
146fi
147
148if echo "$-" | grep -q "x"; then
149 minus_x="-x"
150fi
151
152if ! bash $minus_x "$ci_root/script/clone_repos.sh"; then
153 echo "clone_repos.sh failed!"
154 cat clone_repos.log
155 exit 1
156fi
157
158# vim:set tw=80 sw=8 sts=8 noet: