-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathupdate_local_branch.sh
executable file
·74 lines (65 loc) · 2.34 KB
/
update_local_branch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
set -o pipefail
set -x
function retry() {
local n=1
local -r -i max="$1"; shift
local delay=5
while true; do
"$@" && break || {
if [[ $n -lt $max ]]; then
((n++))
>&2 echo "Command failed. Attempt $n/$max:"
sleep $delay;
else
fail "The command has failed after $n attempts."
fi
}
done
}
REPO="$1"
PR_BRANCH="${2:-image-tag-update}"
SCRIPT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
OTHER_CLONE_ROOT=${OTHER_CLONE_ROOT:-${SCRIPT_ROOT}/../../..}
if [ "$REPO_OWNER" = "aws" ]; then
ORIGIN_ORG="eks-distro-pr-bot"
UPSTREAM_ORG="aws"
else
ORIGIN_ORG=$REPO_OWNER
UPSTREAM_ORG=$REPO_OWNER
fi
if [ "$JOB_TYPE" = "presubmit" ]; then
PR_BRANCH="image-update-branch"
fi
if [ ! -d ${OTHER_CLONE_ROOT}/${ORIGIN_ORG}/${REPO} ]; then
git clone https://github.com/${ORIGIN_ORG}/${REPO}.git ${OTHER_CLONE_ROOT}/${ORIGIN_ORG}/${REPO}
fi
cd ${OTHER_CLONE_ROOT}/${ORIGIN_ORG}/${REPO}
if [ $(git branch --show-current) != $PR_BRANCH ]; then
git config --global push.default current
git config user.name "EKS Distro PR Bot"
git config user.email "aws-model-rocket-bots+eksdistroprbot@amazon.com"
git config remote.origin.url >&- || git remote add origin git@github.com:${ORIGIN_ORG}/${REPO}.git
git config remote.upstream.url >&- || git remote add upstream https://github.com/${UPSTREAM_ORG}/${REPO}.git
if [ "$REPO" = "eks-distro-build-tooling" ] && [ "$JOB_TYPE" = "presubmit" ]; then
git fetch upstream pull/$PULL_NUMBER/head:image-update-branch
git checkout $PR_BRANCH
else
retry 2 git fetch upstream
git checkout upstream/main -b $PR_BRANCH
fi
fi