-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·45 lines (33 loc) · 1.11 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
#!/bin/sh -l
# Env and options
if [ -z "${GITHUB_WORKSPACE}" ]; then
echo "The GITHUB_WORKSPACE environment variable is not defined."
exit 1
fi
if [ -z "${DATE_FORMAT}" ]; then
echo "The DATE_FORMAT environment variable is not defined."
exit 1
fi
cd "${GITHUB_WORKSPACE}" || exit 1
# Security
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
NEXT_DATE_PART="v$(date "+${DATE_FORMAT}")"
LAST_VERSION=$(git tag --sort=-v:refname | grep -E "^v" | head -n 1)
echo "Last version: ${LAST_VERSION}"
LAST_HASH="$(git show-ref -s "${LAST_VERSION}")"
echo "Last hash : ${LAST_HASH}"
if case $LAST_VERSION in $NEXT_DATE_PART*) ;; *) false;; esac ; then
echo "Incrementing patch version.";
new_version="${LAST_VERSION%.*}.$(( ${LAST_VERSION##*.} + 1 ))";
else
new_version="$NEXT_DATE_PART.0";
fi;
if [ "${PRERELEASE}" = "true" ]; then \
new_version="$new_version-pre-release"; \
fi;
NEXT_VERSION=$new_version;
echo "Next version: ${NEXT_VERSION}";
if [ "$GITHUB_OUTPUT" != "" ]; then
echo "last_version=${LAST_VERSION}" >> "${GITHUB_OUTPUT}";
echo "next_version=${NEXT_VERSION}" >> "${GITHUB_OUTPUT}";
fi