Zelalem | 917b43e | 2020-08-04 11:39:55 -0500 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (c) 2019, Arm Limited. All rights reserved. |
| 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | |
| 8 | # Push the updated master from local to the selected remote |
| 9 | # |
| 10 | # $1 = git remote human readable name |
| 11 | # $2 = git remote URL |
| 12 | sync_repo() |
| 13 | { |
| 14 | local result |
| 15 | |
| 16 | echo Pushing to "$1"... |
| 17 | git push --tags $2 master |
| 18 | result=$? |
| 19 | if [ $result != 0 ] |
| 20 | then |
| 21 | echo Pushing to $1 FAILED! |
| 22 | else |
| 23 | echo Pushing to $1 SUCCEEDED! |
| 24 | fi |
| 25 | return $result |
| 26 | } |
| 27 | |
| 28 | # Clone the selected repo from tf.org |
| 29 | # |
| 30 | # Some variables utilised inside this function come from utils.sh |
| 31 | # |
| 32 | # $1 = repo to clone |
| 33 | clone_repo() |
| 34 | { |
| 35 | local repo_url |
| 36 | local repo_name |
| 37 | |
| 38 | case $1 in |
| 39 | trusted-firmware-a) |
| 40 | repo_url=$tf_src_repo_url |
| 41 | repo_name="TF-A" |
| 42 | ;; |
| 43 | tf-a-tests) |
| 44 | repo_url=$tftf_src_repo_url |
| 45 | repo_name="TF-A-Tests" |
| 46 | ;; |
| 47 | *) |
| 48 | echo "ERROR: Unknown repo to be cloned. sync.sh failed!" |
| 49 | exit 1 |
| 50 | ;; |
| 51 | esac |
| 52 | |
| 53 | # Check if the repo clone exists in the job's workspace |
| 54 | if [ ! -d $1 ] |
| 55 | then |
| 56 | # Fresh clone |
| 57 | echo Cloning $repo_name from trustedfirmware.org... |
| 58 | git clone $repo_url |
| 59 | else |
| 60 | echo Will use existing repo for "$repo_name"... |
| 61 | fi |
| 62 | } |
| 63 | |
| 64 | # Pull changes from tf.org to the local repo |
| 65 | # |
| 66 | # $1 = repo to update. It must be the same with the directory name |
| 67 | pull_changes() |
| 68 | { |
| 69 | cd $1 |
| 70 | echo Pulling $1 from trustedfirmware.org... |
| 71 | git remote update --prune |
| 72 | git checkout master |
| 73 | git merge --ff-only origin/master |
| 74 | cd - > /dev/null |
| 75 | } |
| 76 | |
| 77 | # exit if anything fails |
| 78 | set -e |
| 79 | |
| 80 | # Source this file to get TF-A and TF-A-Tests repo URLs |
| 81 | source "$CI_ROOT/utils.sh" |
| 82 | |
| 83 | clone_repo trusted-firmware-a |
| 84 | clone_repo tf-a-tests |
| 85 | |
| 86 | pull_changes trusted-firmware-a |
| 87 | pull_changes tf-a-tests |
| 88 | |
| 89 | # stop exiting automatically |
| 90 | set +e |
| 91 | |
| 92 | # Update TF-A remotes |
| 93 | cd trusted-firmware-a |
| 94 | sync_repo GitHub https://$GH_USER:$GH_PASSWORD@github.com/ARM-software/arm-trusted-firmware.git |
| 95 | github=$? |
| 96 | sync_repo "internal TF-A Gerrit" $tf_arm_gerrit_repo |
| 97 | tfa_gerrit=$? |
| 98 | |
| 99 | # Update TF-A-Tests |
| 100 | cd ../tf-a-tests |
| 101 | sync_repo "internal TF-A-Tests Gerrit" $tftf_arm_gerrit_repo |
| 102 | tftf_gerrit=$? |
| 103 | |
| 104 | if [ $github != 0 -o $tfa_gerrit != 0 -o $tftf_gerrit != 0 ] |
| 105 | then |
| 106 | exit 1 |
| 107 | fi |