forked from Benbentwo/increment-semver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·89 lines (74 loc) · 1.86 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
82
83
84
85
86
87
88
89
#!/bin/bash
# Increment a version string using Semantic Versioning (SemVer) terminology.
# Parse command line options.
while getopts ":Mmp" Option
do
case $Option in
M ) major=true;;
m ) minor=true;;
p ) patch=true;;
esac
done
shift $(($OPTIND - 1))
#version=$1
echo "cd to github workspace"
cd ${GITHUB_WORKSPACE}
git version
git for-each-ref refs/tags/ --count=1 --sort=-version:refname --format='%(refname:short)'
version=$(git for-each-ref refs/tags/ --count=1 --sort=-version:refname --format='%(refname:short)')
echo "Version: ${version}"
if [ -z ${version} ]
then
echo "Couldn't determine version"
exit 1
fi
# Build array from version string.
ba=( ${version//-/ } ) #base version+postfix
a=( ${ba//./ } )
major_version=0
# If version string is missing or has the wrong number of members, show usage message.
if [ ${#a[@]} -ne 3 ]
then
echo "usage: $(basename $0) [-Mmp] major.minor.patch"
exit 1
fi
# Increment version numbers as requested.
if [ ! -z $major ]
then
# Check for v in version (e.g. v1.0 not just 1.0)
if [[ ${a[0]} =~ ([vV]?)([0-9]+) ]]
then
v="${BASH_REMATCH[1]}"
major_version=${BASH_REMATCH[2]}
((major_version++))
a[0]=${v}${major_version}
else
((a[0]++))
major_version=a[0]
fi
a[1]=0
a[2]=0
fi
if [ ! -z $minor ]
then
((a[1]++))
a[2]=0
fi
if [ ! -z $patch ]
then
((a[2]++))
fi
echo "${a[0]}.${a[1]}.${a[2]}"
if [[ ! -z "$INPUT_POSTFIX" ]]; then
echo "POSTFIX is $INPUT_POSTFIX"
version=$(echo "${a[0]}.${a[1]}.${a[2]}-$INPUT_POSTFIX")
preversion=true
else
version=$(echo "${a[0]}.${a[1]}.${a[2]}")
preversion=false
fi
just_numbers=$(echo "${major_version}.${a[1]}.${a[2]}")
echo "Result version $version (preversion: $preversion)"
echo "::set-output name=version::${version}"
echo "::set-output name=stripped-version::${just_numbers}"
echo "::set-output name=preversion::${version}"