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 | set_ci_root() { |
| 30 | ci_root=`pwd`/"platform-ci" |
| 31 | CI_ROOT=$ci_root |
| 32 | } |
| 33 | |
| 34 | strip_var CI_REFSPEC |
| 35 | |
| 36 | if [ ! -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 |
| 41 | fi |
| 42 | |
| 43 | if [ "$CI_ENVIRONMENT" ]; then |
| 44 | tmpfile="$(mktemp --tmpdir="$WORKSPACE")" |
| 45 | echo "$CI_ENVIRONMENT" | tr ' ' '\n' > "$tmpfile" |
| 46 | set -a |
| 47 | source "$tmpfile" |
| 48 | set +a |
| 49 | fi |
| 50 | |
| 51 | if [ "$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 |
| 63 | fi |
| 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. |
| 68 | if [ -z "$CI_REFSPEC" ] && [ "$REPO_UNDER_TEST" = "trusted-firmware-ci" ] && \ |
| 69 | [ "$GERRIT_REFSPEC" ]; then |
| 70 | export CI_REFSPEC="$GERRIT_REFSPEC" |
| 71 | fi |
| 72 | |
| 73 | # Clone CI repository and move to the refspec |
| 74 | if [ ! -d "platform-ci" ] |
| 75 | then |
| 76 | git clone -q --depth 1 \ |
| 77 | --reference /arm/projectscratch/ssg/trusted-fw/ref-repos/trusted-firmware-ci \ |
Zelalem | d36c2d9 | 2020-08-04 16:59:47 -0500 | [diff] [blame] | 78 | https://gerrit.oss.arm.com/pdswinf/ci/pdcs-platforms/platform-ci |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 79 | else |
| 80 | pushd platform-ci |
| 81 | git fetch |
| 82 | git checkout origin/master |
| 83 | popd |
| 84 | fi |
| 85 | |
| 86 | set_ci_root |
| 87 | # Set CI_ROOT as a fallback |
| 88 | echo "CI_ROOT=$ci_root" >> env |
| 89 | |
| 90 | if [ "$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 |
| 112 | fi |
| 113 | |
| 114 | if [ "$ci_only" ]; then |
| 115 | exit 0 |
| 116 | fi |
| 117 | |
| 118 | if echo "$-" | grep -q "x"; then |
| 119 | minus_x="-x" |
| 120 | fi |
| 121 | |
| 122 | if ! bash $minus_x "$ci_root/script/clone_repos.sh"; then |
| 123 | echo "clone_repos.sh failed!" |
| 124 | cat clone_repos.log |
| 125 | exit 1 |
| 126 | fi |
| 127 | |
| 128 | # vim:set tw=80 sw=8 sts=8 noet: |