-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgithub_sync.sh
More file actions
executable file
·56 lines (37 loc) · 1.25 KB
/
github_sync.sh
File metadata and controls
executable file
·56 lines (37 loc) · 1.25 KB
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
#!/bin/bash
set -eu
# User inputs.
ORGANIZATION=$1
REPOSITORY=$2
BRANCH=$3
# Set in upstream environment.
# WORKFLOW_USER - 'mygithubusername'
# WORKFLOW_EMAIL - 'mygithubuseremail'
# WORKFLOW_TOKEN - secret 'SECRET'
# FORK - Fork to sync
cd ${REPOSITORY}-${BRANCH}
echo -e "\nBranch:"
git branch
git config --global user.name "${WORKFLOW_USER}"
git config --global user.email "${WORKFLOW_EMAIL}"
echo -e "\nAdding remotes ..."
git remote add upstream https://github.com/${ORGANIZATION}/${REPOSITORY}.git
echo -e "\nRemotes added:"
git remote -v
git fetch upstream ${BRANCH}
LOCAL_COMMIT_HASH=$(git rev-parse ${BRANCH})
UPSTREAM_COMMIT_HASH=$(git rev-parse upstream/${BRANCH})
if [[ "${LOCAL_COMMIT_HASH}" == "${UPSTREAM_COMMIT_HASH}" ]]; then
echo -e "\nNo new commits to sync"
else
echo -e"\nNew commits being synced:"
git log upstream/${BRANCH} "${LOCAL_COMMIT_HASH}"..HEAD --pretty=oneline
echo -e "\nSyncing ..."
git pull --no-edit upstream ${BRANCH}
echo -e "\nSync successful"
git config --local --unset-all "http.https://github.com/.extraheader"
echo -e "\nPushing branch to origin ..."
git push https://${WORKFLOW_USER}:${WORKFLOW_TOKEN}@github.com/${FORK}/${REPOSITORY}.git $GITHUB_REF
echo -e "\nPush successful"
fi
exit 0