-
Notifications
You must be signed in to change notification settings - Fork 42
/
entrypoint.sh
executable file
·81 lines (67 loc) · 2.63 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
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
set -e
echo
echo " 'Nightly Merge Action' is using the following input:"
echo " - stable_branch = '$INPUT_STABLE_BRANCH'"
echo " - development_branch = '$INPUT_DEVELOPMENT_BRANCH'"
echo " - allow_ff = $INPUT_ALLOW_FF"
echo " - allow_git_lfs = $INPUT_GIT_LFS"
echo " - ff_only = $INPUT_FF_ONLY"
echo " - allow_forks = $INPUT_ALLOW_FORKS"
echo " - user_name = $INPUT_USER_NAME"
echo " - user_email = $INPUT_USER_EMAIL"
echo " - push_token = $INPUT_PUSH_TOKEN = ${!INPUT_PUSH_TOKEN}"
echo
if [[ $INPUT_ALLOW_FORKS != "true" ]]; then
URI=https://api.github.com
API_HEADER="Accept: application/vnd.github.v3+json"
AUTH_HEADER=$([ -z "${GITHUB_TOKEN}" ] && echo 'foo: bar' || echo "Authorization: bearer ${GITHUB_TOKEN}")
pr_resp=$(curl -X GET -s -H "${AUTH_HEADER}" -H "${API_HEADER}" "${URI}/repos/$GITHUB_REPOSITORY")
if [[ "$(echo "$pr_resp" | jq -r .fork)" != "false" ]]; then
echo "Nightly merge action is disabled for forks (use the 'allow_forks' option to enable it)."
exit 0
fi
fi
if [[ -z "${!INPUT_PUSH_TOKEN}" ]]; then
echo "Set the ${INPUT_PUSH_TOKEN} env variable."
exit 1
fi
FF_MODE="--no-ff"
if [[ "$INPUT_ALLOW_FF" == "true" ]]; then
FF_MODE="--ff"
if [[ "$INPUT_FF_ONLY" == "true" ]]; then
FF_MODE="--ff-only"
fi
else
if [[ "$INPUT_FF_ONLY" == "true" ]]; then
echo "ff_only specified, but allow_ff isn't please update the options to make them consistent"
exit 1
fi
fi
git config --global --add safe.directory "$GITHUB_WORKSPACE"
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_STABLE_BRANCH
(git checkout $INPUT_STABLE_BRANCH && git pull)||git checkout -b $INPUT_STABLE_BRANCH origin/$INPUT_STABLE_BRANCH
git fetch origin $INPUT_DEVELOPMENT_BRANCH
(git checkout $INPUT_DEVELOPMENT_BRANCH && git pull)||git checkout -b $INPUT_DEVELOPMENT_BRANCH origin/$INPUT_DEVELOPMENT_BRANCH
if git merge-base --is-ancestor $INPUT_STABLE_BRANCH $INPUT_DEVELOPMENT_BRANCH; then
echo "No merge is necessary"
exit 0
fi;
set +o xtrace
echo
echo " 'Nightly Merge Action' is trying to merge the '$INPUT_STABLE_BRANCH' branch ($(git log -1 --pretty=%H $INPUT_STABLE_BRANCH))"
echo " into the '$INPUT_DEVELOPMENT_BRANCH' branch ($(git log -1 --pretty=%H $INPUT_DEVELOPMENT_BRANCH))"
echo
set -o xtrace
# Do the merge
git merge $FF_MODE --no-edit $INPUT_STABLE_BRANCH
# Pull lfs if enabled
if [[ $INPUT_GIT_LFS == "true" ]]; then
git lfs pull
fi
# Push the branch
git push origin $INPUT_DEVELOPMENT_BRANCH