blob: 3e345778b4b496070f05ccdf7810962b3deb7c5d [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Leonardo Sandoval579c7372020-10-23 15:23:32 -05003# Copyright (c) 2019-2020 Arm Limited. All rights reserved.
Fathi Boudra422bf772019-12-02 11:10:16 +02004#
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
29strip_var CI_REFSPEC
30
31if [ "$CI_ENVIRONMENT" ]; then
32 tmpfile="$(mktemp --tmpdir="$WORKSPACE")"
33 echo "$CI_ENVIRONMENT" | tr ' ' '\n' > "$tmpfile"
34 set -a
35 source "$tmpfile"
36 set +a
37fi
38
39if [ "$CI_SCRATCH" ]; then
40 if [ ! -d "$CI_SCRATCH" ]; then
41 echo "\$CI_SCRATCH is stale; ignored."
42 else
43 # Copy environment and parameter file from scratch to this job's
44 # workspace
45 cp "$CI_SCRATCH/env" .
46 cp "$CI_SCRATCH/env.param" .
47 find "$CI_SCRATCH" -name "*.data" -exec cp -t . '{}' +
48
49 exit 0
50 fi
51fi
52
53# If no CI ref specs were explicitly specified, but was triggered from a CI
54# Gerrit trigger, move to the Gerrit refspec instead so that we use the expected
55# version of clone_repos.sh.
56if [ -z "$CI_REFSPEC" ] && [ "$REPO_UNDER_TEST" = "tf-a-ci" ] && \
57 [ "$GERRIT_REFSPEC" ]; then
58 export CI_REFSPEC="$GERRIT_REFSPEC"
59fi
60
61ci_root=`pwd`/"tf-a-ci"
62# Clone CI repository and move to the refspec
63git clone -q --depth 1 \
64 --reference /arm/projectscratch/ssg/trusted-fw/ref-repos/tf-a-ci \
65 https://gerrit.oss.arm.com/trusted-firmware/tf-a-ci $ci_root
66
67# Set CI_ROOT as a fallback
68echo "CI_ROOT=$ci_root" >> env
69export CI_ROOT=$ci_root
70echo "CI_ROOT:"$CI_ROOT
71
72if [ "$CI_REFSPEC" ]; then
73 # Only recent Git versions support fetching refs via. commit IDs.
74 # However, platform slaves have been updated to a version that can do
75 # this (https://jira.arm.com/browse/SSGSWINF-1426). The module load
76 # commands have been commented out since.
77 #
78 # source /arm/tools/setup/init/bash
79 # module load swdev
80 # module load git/git/2.14.3
81
82 # Translate refpsec if supported
83 if [ -x "$ci_root/script/translate_refspec.py" ]; then
84 CI_REFSPEC="$("$ci_root/script/translate_refspec.py" \
85 -p tf-a-ci "$CI_REFSPEC")"
86 fi
87
88 pushd $ci_root &>/dev/null
89 git fetch -q --depth 1 origin "$CI_REFSPEC"
90 git checkout -q FETCH_HEAD
91 echo
92 echo "Initial CI repo checked out to '$CI_REFSPEC'."
93 popd &>/dev/null
94fi
95
96if [ "$ci_only" ]; then
97 exit 0
98fi
99
100if ! "$ci_root/script/clone_repos.sh"; then
101 echo "clone_repos.sh failed!"
102 cat clone_repos.log
103 exit 1
104fi
105
106# vim:set tw=80 sw=8 sts=8 noet: