-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgit-release
More file actions
executable file
·79 lines (63 loc) · 1.76 KB
/
Copy pathgit-release
File metadata and controls
executable file
·79 lines (63 loc) · 1.76 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
#!/bin/sh
set -e
if [[ $# != 1 && $# != 2 ]] ; then
>&2 echo "Usage: git release <version-to-increment> [<remote>]"
exit 1
fi
if [[ $# == 2 ]] ; then
REMOTE=$2
else
REMOTE=origin
fi
echo "Pulling changes"
git pull "$REMOTE"
echo "Updating tags from remote $REMOTE"
git fetch "$REMOTE" --tags --force
UNCOMMITTED_CHANGES=`git status -s | wc -l`
if [[ $UNCOMMITTED_CHANGES != 0 ]] ; then
read -p "There are uncommitted changes. Do you wish to continue anyway? (y/n) " ANSWER
if [[ $ANSWER != "y" ]] ; then
exit 1
fi
fi
set +e
CURRENT_VERSION=`git describe --abbrev=0 --match 'v[0-9]*.[0-9]*.[0-9]*' 2> /dev/null`
if [[ $? != 0 ]] ; then
CURRENT_VERSION="v0.1.0"
fi
set -e
SEMVER_REGEX='^v([1-9][0-9]*|0)\.([1-9][0-9]*|0)\.([1-9][0-9]*|0)$'
if [[ ! "$CURRENT_VERSION" =~ $SEMVER_REGEX ]] ; then
>&2 echo "The current version ($CURRENT_VERSION) is not semver compatible"
exit 1
fi
MAJOR=${BASH_REMATCH[1]}
MINOR=${BASH_REMATCH[2]}
PATCH=${BASH_REMATCH[3]}
MAJOR_NAME="major"
MINOR_NAME="minor"
PATCH_NAME="patch"
if [[ $1 == "$MAJOR_NAME" ]] ; then
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
elif [[ $1 == "$MINOR_NAME" ]] ; then
MINOR=$((MINOR + 1))
PATCH=0
elif [[ $1 == "$PATCH_NAME" ]] ; then
PATCH=$((PATCH + 1))
else
>&2 echo "Invalid version value: supported values are '$MAJOR_NAME' '$MINOR_NAME' '$PATCH_NAME'"
exit
fi
NEW_VERSION="v$MAJOR.$MINOR.$PATCH"
read -p "New version will be '$NEW_VERSION'. Are you sure? (y/n) " ANSWER
if [[ $ANSWER != "y" ]] ; then
exit 1
fi
echo "Pushing any local commits"
git push "$REMOTE"
echo "Tagging current commit with version $NEW_VERSION"
git tag -a "$NEW_VERSION" -m "$NEW_VERSION"
echo "Pushing tag $NEW_VERSION to $REMOTE"
git push "$REMOTE" "$NEW_VERSION"