forked from bambamboole/gha-upmerge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·48 lines (36 loc) · 1.44 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
#!/bin/bash
set -e
echo
echo " 'Upmerge Action' is using the following input:"
echo " - from_branch = '$INPUT_FROM_BRANCH'"
echo " - to_branch = '$INPUT_TO_BRANCH'"
echo " - user_name = $INPUT_USER_NAME"
echo " - user_email = $INPUT_USER_EMAIL"
echo " - push_token = $INPUT_PUSH_TOKEN = ${!INPUT_PUSH_TOKEN}"
echo
if [[ -z "${!INPUT_PUSH_TOKEN}" ]]; then
echo "Set the ${INPUT_PUSH_TOKEN} env variable."
exit 1
fi
git remote set-url origin https://x-access-token:${!INPUT_PUSH_TOKEN}@github.com/$GITHUB_REPOSITORY.git
git config --global user.name "$INPUT_USER_NAME"
git config --global user.email "$INPUT_USER_EMAIL"
set -o xtrace
git fetch origin $INPUT_FROM_BRANCH
(git checkout $INPUT_FROM_BRANCH && git pull)||git checkout -b $INPUT_FROM_BRANCH origin/$INPUT_FROM_BRANCH
git fetch origin $INPUT_TO_BRANCH
(git checkout $INPUT_TO_BRANCH && git pull)||git checkout -b $INPUT_TO_BRANCH origin/$INPUT_TO_BRANCH
if git merge-base --is-ancestor $INPUT_FROM_BRANCH $INPUT_TO_BRANCH; then
echo "No merge is necessary"
exit 0
fi;
set +o xtrace
echo
echo " 'Upmerge Action' is trying to merge the '$INPUT_FROM_BRANCH' branch ($(git log -1 --pretty=%H $INPUT_FROM_BRANCH))"
echo " into the '$INPUT_TO_BRANCH' branch ($(git log -1 --pretty=%H $INPUT_TO_BRANCH))"
echo
set -o xtrace
# Do the merge
git merge --no-edit $INPUT_FROM_BRANCH --allow-unrelated-histories -X theirs --squash
# Push the branch
git push --force origin $INPUT_TO_BRANCH