-
Notifications
You must be signed in to change notification settings - Fork 239
Expand file tree
/
Copy pathstart.sh
More file actions
119 lines (100 loc) · 3.54 KB
/
start.sh
File metadata and controls
119 lines (100 loc) · 3.54 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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/sh
set -e
INPUT_ATOMIC=${INPUT_ATOMIC:-true}
INPUT_FORCE=${INPUT_FORCE:-false}
INPUT_FORCE_WITH_LEASE=${INPUT_FORCE_WITH_LEASE:-false}
INPUT_SSH=${INPUT_SSH:-false}
INPUT_TAGS=${INPUT_TAGS:-false}
INPUT_PUSH_ONLY_TAGS=${INPUT_PUSH_ONLY_TAGS:-false}
INPUT_DIRECTORY=${INPUT_DIRECTORY:-"."}
INPUT_PUSH_TO_SUBMODULES=${INPUT_PUSH_TO_SUBMODULES:-""}
INPUT_PULL=${INPUT_PULL:-false}
_ATOMIC_OPTION=""
_FORCE_OPTION=""
REPOSITORY=${INPUT_REPOSITORY:-$GITHUB_REPOSITORY}
echo "Push to branch $INPUT_BRANCH";
[ -z "${INPUT_GITHUB_TOKEN}" ] && {
echo "Missing input 'token' (or legacy 'github_token'). Please set one of:";
echo " token: \${{ secrets.GITHUB_TOKEN }}";
echo " github_token: \${{ secrets.GITHUB_TOKEN }}";
exit 1;
};
if ${INPUT_FORCE} && ${INPUT_FORCE_WITH_LEASE}; then
echo "Please, specify only force or force_with_lease and not both.";
exit 1;
fi
if ${INPUT_ATOMIC}; then
_ATOMIC_OPTION="--atomic"
fi
if ${INPUT_FORCE}; then
_FORCE_OPTION="--force"
fi
if ${INPUT_FORCE_WITH_LEASE}; then
_FORCE_OPTION="--force-with-lease"
fi
if ${INPUT_TAGS}; then
_TAGS="--tags"
fi
if [ -n "${INPUT_PUSH_TO_SUBMODULES}" ]; then
_INPUT_PUSH_TO_SUBMODULES="--recurse-submodules=${INPUT_PUSH_TO_SUBMODULES}"
fi
cd ${INPUT_DIRECTORY}
if git symbolic-ref --quiet HEAD > /dev/null 2>&1; then
_DETACHED_HEAD=false
else
_DETACHED_HEAD=true
fi
if ${_DETACHED_HEAD}; then
echo "Warning: The repository is in a detached HEAD state.";
echo "This happens when actions/checkout checks out a tag, a commit SHA, or a";
echo "pull-request merge commit rather than a real branch.";
echo "To resolve this, check out a branch explicitly in your actions/checkout step,";
echo "for example: 'ref: \${{ github.head_ref }}' or 'ref: main'.";
echo "Note: setting this action's 'branch' input (e.g. branch: main) only controls";
echo "the push destination — it does not check out a branch in your workspace.";
fi
if [ "${INPUT_PULL}" != "false" ]; then
if ${_DETACHED_HEAD}; then
echo "Error: 'pull' is enabled but the repository is in detached HEAD state."
echo "git pull only works when a branch is currently checked out."
echo "Either disable the 'pull' input or check out a branch explicitly"
echo "(e.g. add 'ref: \${{ github.head_ref }}' to the actions/checkout step)."
exit 1
fi
if ${INPUT_SSH}; then
_pull_remote="git@${INPUT_GITHUB_URL}:${REPOSITORY}.git"
else
_pull_remote="${INPUT_GITHUB_URL_PROTOCOL}//oauth2:${INPUT_GITHUB_TOKEN}@${INPUT_GITHUB_URL}/${REPOSITORY}.git"
fi
case "${INPUT_PULL}" in
rebase|true)
_pull_strategy="--rebase"
;;
merge)
_pull_strategy="--no-rebase"
;;
ff-only)
_pull_strategy="--ff-only"
;;
*)
echo "Unknown pull strategy: '${INPUT_PULL}'. Use rebase, merge, ff-only, or true."
exit 1
;;
esac
echo "Pulling from ${INPUT_BRANCH} (strategy: ${INPUT_PULL}) before push..."
git pull ${_pull_strategy} "${_pull_remote}" "${INPUT_BRANCH}"
fi
if ${INPUT_SSH}; then
remote_repo="git@${INPUT_GITHUB_URL}:${REPOSITORY}.git"
else
remote_repo="${INPUT_GITHUB_URL_PROTOCOL}//oauth2:${INPUT_GITHUB_TOKEN}@${INPUT_GITHUB_URL}/${REPOSITORY}.git"
fi
if ! ${INPUT_FORCE_WITH_LEASE}; then
ADDITIONAL_PARAMETERS="${remote_repo} HEAD:${INPUT_BRANCH}"
elif ${INPUT_PUSH_ONLY_TAGS}; then
ADDITIONAL_PARAMETERS="${remote_repo}"
fi
if ${INPUT_FORCE_WITH_LEASE} && ${INPUT_TAGS}; then
_ATOMIC_OPTION=""
fi
git push $ADDITIONAL_PARAMETERS $_INPUT_PUSH_TO_SUBMODULES $_ATOMIC_OPTION --follow-tags $_FORCE_OPTION $_TAGS;