-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversioning.sh
executable file
·59 lines (54 loc) · 1.2 KB
/
versioning.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
#!/bin/bash
function print_help {
echo "Commands available, each will tag current version, which locks it :"
echo " publish"
echo " inc patch"
echo " inc minor"
echo " inc major"
}
function publish {
git tag -l | grep -q `cat VERSION`
if [ $? -ne 0 ]
then
if [ -z "$(git status --untracked-files=no --porcelain)" ]
then
git tag `semver tag`
else
git commit -am `semver tag`
git tag `semver tag`
fi
git push
git push --tags
else
echo "This version has already been published."
fi
}
function increment {
git tag -l | grep -q `cat VERSION`
if [ $? -ne 0 ]
then
echo "This version hasn't been published yet. Publishing ..."
publish
fi
semver $1 $2
Vversion=`semver tag`
version=${Vversion:1}
echo $version > VERSION
sed -E "s/ \"version\": \"([0-9\.]+)\",/ \"version\": \"$version\",/" package.json > package.json.tmp
mv package.json.tmp package.json
git commit -am "bumped to $(semver tag)"
}
if [ $# -eq 1 ] && [ $1 == "publish" ]
then
publish
exit $?
elif [ $# -eq 2 ] && [ $1 == "inc" ]
then
if [ $2 == "patch" ] || [ $2 == "minor" ] || [ $2 == "major" ]
then
increment $1 $2
exit $?
fi
fi
print_help
exit 0