Leonardo Sandoval | 9dfdd1b | 2020-08-06 17:08:11 -0500 | [diff] [blame^] | 1 | #!/usr/bin/env bash |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 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 | |
| 21 | set -e |
| 22 | |
| 23 | strip_var() { |
| 24 | local var="$1" |
| 25 | local val="$(echo "${!var}" | sed 's#^\s*\|\s*$##g')" |
| 26 | eval "$var=$val" |
| 27 | } |
| 28 | |
| 29 | strip_var CI_REFSPEC |
| 30 | |
| 31 | if [ "$CI_ENVIRONMENT" ]; then |
| 32 | tmpfile="$(mktemp --tmpdir="$WORKSPACE")" |
| 33 | echo "$CI_ENVIRONMENT" | tr ' ' '\n' > "$tmpfile" |
| 34 | set -a |
| 35 | source "$tmpfile" |
| 36 | set +a |
| 37 | fi |
| 38 | |
| 39 | if [ "$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 |
| 51 | fi |
| 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. |
| 56 | if [ -z "$CI_REFSPEC" ] && [ "$REPO_UNDER_TEST" = "tf-a-ci" ] && \ |
| 57 | [ "$GERRIT_REFSPEC" ]; then |
| 58 | export CI_REFSPEC="$GERRIT_REFSPEC" |
| 59 | fi |
| 60 | |
| 61 | ci_root=`pwd`/"tf-a-ci" |
| 62 | # Clone CI repository and move to the refspec |
| 63 | git 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 |
| 68 | echo "CI_ROOT=$ci_root" >> env |
| 69 | export CI_ROOT=$ci_root |
| 70 | echo "CI_ROOT:"$CI_ROOT |
| 71 | |
| 72 | if [ "$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 |
| 94 | fi |
| 95 | |
| 96 | if [ "$ci_only" ]; then |
| 97 | exit 0 |
| 98 | fi |
| 99 | |
| 100 | if ! "$ci_root/script/clone_repos.sh"; then |
| 101 | echo "clone_repos.sh failed!" |
| 102 | cat clone_repos.log |
| 103 | exit 1 |
| 104 | fi |
| 105 | |
| 106 | # vim:set tw=80 sw=8 sts=8 noet: |