-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync_repo.sh
executable file
·60 lines (51 loc) · 1.86 KB
/
sync_repo.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
#!/bin/sh
set -e
# Synchronize the current repo with upstream repo
#
# The source should be in $GITHUB_WORKSPACE
# Input Parameters:
UPSTREAM_REPO=$1
UPSTREAM_BRANCH=$2
ORIGIN_BRANCH=$3
WORKFLOW_BRANCH=$4
echo ">>> Setup repo"
echo "$ git checkout $ORIGIN_BRANCH"
git checkout $ORIGIN_BRANCH
echo "$ git remote set-url origin $GITHUB_REPOSITORY"
git remote set-url origin "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY"
echo "$ git remote add upstream $UPSTREAM_REPO"
git remote add upstream "$UPSTREAM_REPO"
echo "$ git fetch upstream $UPSTREAM_BRANCH"
git fetch upstream $UPSTREAM_BRANCH
echo ">>> Check Origin and Upstream"
ORIGIN_HEAD=$(git log -1 --format=%H origin/$ORIGIN_BRANCH)
echo "ORIGIN_HEAD: $ORIGIN_HEAD"
UPSTREAM_HEAD=$(git log -1 --format=%H upstream/$UPSTREAM_BRANCH)
echo "UPSTREAM_HEAD: $UPSTREAM_HEAD"
if [ "$ORIGIN_HEAD" = "$UPSTREAM_HEAD" ]; then
echo "Repos are already synched. Eixt..."
exit 0
fi
echo "Repos are NOT synced. Need to merge..."
echo ">>> Sync origin with upstream"
echo "$ git remote set-branches origin *"
git remote set-branches origin '*'
echo "$ git fetch origin --unshallow"
git fetch origin --unshallow
echo "$ git push -f origin refs/remotes/upstream/$UPSTREAM_BRANCH:refs/heads/$ORIGIN_BRANCH"
git push -f origin "refs/remotes/upstream/$UPSTREAM_BRANCH:refs/heads/$ORIGIN_BRANCH"
echo "$ git push -f origin refs/tags/*"
git push -f origin "refs/tags/*"
echo ">>> Cherry-pick workflow commit"
WORKFLOW_SHA=$(git log -1 --format=%H origin/$WORKFLOW_BRANCH)
echo "workflow commit: $WORKFLOW_SHA"
echo "$ git checkout -b $WORKFLOW_BRANCH origin/$ORIGIN_BRANCH"
git checkout -b $WORKFLOW_BRANCH origin/$ORIGIN_BRANCH
echo "$ git branch"
git branch
echo "$ git cherry-pick $WORKFLOW_SHA"
git cherry-pick $WORKFLOW_SHA
echo "$ git push -f origin $WORKFLOW_BRANCH"
git push -f origin $WORKFLOW_BRANCH
echo ">>> Done Exit"
exit 0