blob: f778a8082d91afd9c05cd18dc866e984c6b79d04 [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" = "trusted-firmware-ci" ] && \
57 [ "$GERRIT_REFSPEC" ]; then
58 export CI_REFSPEC="$GERRIT_REFSPEC"
59fi
60
61# Clone CI repository and move to the refspec
62git clone -q --depth 1 \
63 --reference /arm/projectscratch/ssg/trusted-fw/ref-repos/trusted-firmware-ci \
Zelalemd36c2d92020-08-04 16:59:47 -050064 https://gerrit.oss.arm.com/pdswinf/ci/pdcs-platforms/platform-ci
Fathi Boudra422bf772019-12-02 11:10:16 +020065
66# Set CI_ROOT as a fallback
67ci_root="platform-ci/trusted-fw/new-ci"
68echo "CI_ROOT=$ci_root" >> env
69
70if [ "$CI_REFSPEC" ]; then
71 # Only recent Git versions support fetching refs via. commit IDs.
72 # However, platform slaves have been updated to a version that can do
73 # this (https://jira.arm.com/browse/SSGSWINF-1426). The module load
74 # commands have been commented out since.
75 #
76 # source /arm/tools/setup/init/bash
77 # module load swdev
78 # module load git/git/2.14.3
79
80 # Translate refpsec if supported
81 if [ -x "$ci_root/script/translate_refspec.py" ]; then
82 CI_REFSPEC="$("$ci_root/script/translate_refspec.py" \
83 -p trusted-firmware-ci "$CI_REFSPEC")"
84 fi
85
86 pushd platform-ci &>/dev/null
87 git fetch -q --depth 1 origin "$CI_REFSPEC"
88 git checkout -q FETCH_HEAD
89 echo
90 echo "Initial CI repo checked out to '$CI_REFSPEC'."
91 popd &>/dev/null
92fi
93
94if [ "$ci_only" ]; then
95 exit 0
96fi
97
98if echo "$-" | grep -q "x"; then
99 minus_x="-x"
100fi
101
102if ! bash $minus_x "$ci_root/script/clone_repos.sh"; then
103 echo "clone_repos.sh failed!"
104 cat clone_repos.log
105 exit 1
106fi
107
108# vim:set tw=80 sw=8 sts=8 noet: