blob: c69eb02f8fd2c9b4dfec8b62a289553473ab4475 [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
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
43if [ "$CI_ENVIRONMENT" ]; then
44 tmpfile="$(mktemp --tmpdir="$WORKSPACE")"
45 echo "$CI_ENVIRONMENT" | tr ' ' '\n' > "$tmpfile"
46 set -a
47 source "$tmpfile"
48 set +a
49fi
50
51if [ "$CI_SCRATCH" ]; then
52 if [ ! -d "$CI_SCRATCH" ]; then
53 echo "\$CI_SCRATCH is stale; ignored."
54 else
55 # Copy environment and parameter file from scratch to this job's
56 # workspace
57 cp "$CI_SCRATCH/env" .
58 cp "$CI_SCRATCH/env.param" .
59 find "$CI_SCRATCH" -name "*.data" -exec cp -t . '{}' +
60
61 exit 0
62 fi
63fi
64
65# If no CI ref specs were explicitly specified, but was triggered from a CI
66# Gerrit trigger, move to the Gerrit refspec instead so that we use the expected
67# version of clone_repos.sh.
68if [ -z "$CI_REFSPEC" ] && [ "$REPO_UNDER_TEST" = "trusted-firmware-ci" ] && \
69 [ "$GERRIT_REFSPEC" ]; then
70 export CI_REFSPEC="$GERRIT_REFSPEC"
71fi
72
73# Clone CI repository and move to the refspec
74if [ ! -d "platform-ci" ]
75then
76git clone -q --depth 1 \
77 --reference /arm/projectscratch/ssg/trusted-fw/ref-repos/trusted-firmware-ci \
Zelalemd36c2d92020-08-04 16:59:47 -050078 https://gerrit.oss.arm.com/pdswinf/ci/pdcs-platforms/platform-ci
Fathi Boudra422bf772019-12-02 11:10:16 +020079else
80 pushd platform-ci
81 git fetch
82 git checkout origin/master
83 popd
84fi
85
86set_ci_root
87# Set CI_ROOT as a fallback
88echo "CI_ROOT=$ci_root" >> env
89
90if [ "$CI_REFSPEC" ]; then
91 # Only recent Git versions support fetching refs via. commit IDs.
92 # However, platform slaves have been updated to a version that can do
93 # this (https://jira.arm.com/browse/SSGSWINF-1426). The module load
94 # commands have been commented out since.
95 #
96 # source /arm/tools/setup/init/bash
97 # module load swdev
98 # module load git/git/2.14.3
99
100 # Translate refspec if supported
101 if [ -x "$ci_root/script/translate_refspec.py" ]; then
102 CI_REFSPEC="$("$ci_root/script/translate_refspec.py" \
103 -p trusted-firmware-ci -s arm "$CI_REFSPEC")"
104 fi
105
106 pushd platform-ci &>/dev/null
107 git fetch -q --depth 1 origin "$CI_REFSPEC"
108 git checkout -q FETCH_HEAD
109 echo
110 echo "Initial CI repo checked out to '$CI_REFSPEC'."
111 popd &>/dev/null
112fi
113
114if [ "$ci_only" ]; then
115 exit 0
116fi
117
118if echo "$-" | grep -q "x"; then
119 minus_x="-x"
120fi
121
122if ! bash $minus_x "$ci_root/script/clone_repos.sh"; then
123 echo "clone_repos.sh failed!"
124 cat clone_repos.log
125 exit 1
126fi
127
128# vim:set tw=80 sw=8 sts=8 noet: