-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·71 lines (59 loc) · 2.1 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
#!/bin/bash
set -eux
# Apply hotfix for 'fatal: unsafe repository' error (see #10)
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
cd "${GITHUB_WORKSPACE}" || exit
if [ -z "${INPUT_TAG}" ]; then
echo "[action-create-tag] No-tag was supplied! Please supply a tag."
exit 1
fi
# Set up variables.
TAG="${INPUT_TAG}"
MESSAGE="${INPUT_MESSAGE:-Release ${TAG}}"
FORCE_TAG="${INPUT_FORCE_PUSH_TAG:-false}"
SHA=${INPUT_COMMIT_SHA:-${GITHUB_SHA}}
INCLUDE_SUBMODULES="${INPUT_INCLUDE_SUBMODULES:-false}"
ONLY_SUBMODULE="${INPUT_ONLY_SUBMODULE:-}"
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
echo "GITHUB_SHA=${GITHUB_SHA}"
echo "INPUT_COMMIT_SHA=${INPUT_COMMIT_SHA}"
echo "SHA=${SHA}"
FORCE_SWITCH=""
if [ "${FORCE_TAG}" = 'true' ]; then
FORCE_SWITCH="--force"
fi
echo "FORCE_SWITCH=${FORCE_SWITCH}"
# Create tag
echo "[action-create-tag] Create tag '${TAG}'."
if [ -n "${ONLY_SUBMODULE}" ]; then
git config --global --add safe.directory /github/workspace/${ONLY_SUBMODULE}
pushd ${ONLY_SUBMODULE}
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git tag ${FORCE_SWITCH} -a "${TAG}" -m "${MESSAGE}"
popd
else
git tag ${FORCE_SWITCH} -a "${TAG}" "${SHA}" -m "${MESSAGE}"
if [ "${INCLUDE_SUBMODULES}" = 'true' ]; then
git submodule foreach git config user.name "${GITHUB_ACTOR}"
git submodule foreach git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git submodule foreach git tag ${FORCE_SWITCH} -a "${TAG}" -m "${MESSAGE}"
fi
fi
# Set up remote url for checkout@v1 action.
if [ -n "${INPUT_GITHUB_TOKEN}" ]; then
git remote set-url origin "https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
fi
# Push tag
echo "[action-create-tag] Push tag '${TAG}'."
if [ -n "${ONLY_SUBMODULE}" ]; then
pushd ${ONLY_SUBMODULE}
git push origin "${TAG}" ${FORCE_SWITCH}
popd
else
git push ${FORCE_SWITCH} origin "${TAG}"
if [ "${INCLUDE_SUBMODULES}" = 'true' ]; then
git submodule foreach git push origin "${TAG}" ${FORCE_SWITCH}
fi
fi