-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
70 lines (53 loc) · 1.71 KB
/
entrypoint.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
#!/usr/bin/env bash
set -x
UPSTREAM_REPO=$1
UPSTREAM_BRANCH=$2
DOWNSTREAM_BRANCH=$3
GITHUB_TOKEN=$4
FETCH_ARGS=$5
MERGE_ARGS=$6
PUSH_ARGS=$7
SPAWN_LOGS=$8
if [[ -z "$UPSTREAM_REPO" ]]; then
echo "Missing \$UPSTREAM_REPO"
exit 1
fi
if [[ -z "$DOWNSTREAM_BRANCH" ]]; then
echo "Missing \$DOWNSTREAM_BRANCH"
echo "Default to ${UPSTREAM_BRANCH}"
DOWNSTREAM_BREANCH=UPSTREAM_BRANCH
fi
if ! echo "$UPSTREAM_REPO" | grep '\.git'; then
UPSTREAM_REPO="https://github.com/${UPSTREAM_REPO_PATH}.git"
fi
echo "UPSTREAM_REPO=$UPSTREAM_REPO"
git clone "https://github.com/${GITHUB_REPOSITORY}.git" work
cd work || { echo "Missing work dir" && exit 2 ; }
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git config --local user.password ${GITHUB_TOKEN}
git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git remote add upstream "$UPSTREAM_REPO"
git fetch ${FETCH_ARGS} upstream
git remote -v
git checkout ${DOWNSTREAM_BRANCH}
case ${SPAWN_LOGS} in
(true) echo -n "sync-merge-upstream-repo https://github.com/maximohub/sync-merge-upstream-repo keeping CI alive."\
"UNIX Time: " >> sync-merge-upstream-repo
date +"%s" >> sync-merge-upstream-repo
git add sync-merge-upstream-repo
git commit sync-merge-upstream-repo -m "Syncing...";;
(false) echo "Not spawning time logs"
esac
git push origin
MERGE_RESULT=$(git merge ${MERGE_ARGS} upstream/${UPSTREAM_BRANCH})
if [[ $MERGE_RESULT == "" ]]
then
exit 1
elif [[ $MERGE_RESULT != *"Already up to date."* ]]
then
git commit -m "Merged upstream"
git push ${PUSH_ARGS} origin ${DOWNSTREAM_BRANCH} || exit $?
fi
cd ..
rm -rf work