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