-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathversion.sh
executable file
·79 lines (74 loc) · 2.18 KB
/
version.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
#!/bin/bash
version="$(cat $(dirname "$0")/VERSION)"
version_full="$(echo ${version} | cut -d '-' -f1 -s)"
if [ -z "${version_full}" ]; then
version_full="${version}"
version_pre=""
else
version_pre="$(echo ${version} | cut -d '-' -f2 -s)"
fi
git_tag_exact_match=$(git describe --exact-match 2> /dev/null)
if [ $? -eq 0 ]; then
if git diff --quiet 2> /dev/null; then
if [ -n "${version_pre}" ]; then
echo "Release version includes a pre-release" 1>&2
exit 1
fi
if [ "${version_full}" != "${git_tag_exact_match}" ]; then
echo "Release version doesn't match git tag: ${git_tag_exact_match}" 1>&2
exit 1
fi
echo "${version_full}"
exit 0
else
if [ -z "${version_pre}" ]; then
echo "Pre-release version needs a pre-release in VERSION file" 1>&2
exit 1
fi
if [ ${version_full} == ${git_tag_exact_match} ]; then
echo "Pre-release version matches a previous release" 1>&2
exit 1
fi
git_commit_id=$(git rev-parse --short=6 HEAD 2> /dev/null)
if [ $? -ne 0 ]; then
exit 1
fi
echo "${version_full}-0.0+git.${git_commit_id}"
exit 1
fi
fi
git_tag_closest=$(git describe --abbrev=0 2> /dev/null)
if [ $? -eq 0 ]; then
if [ ${version_full} == ${git_tag_closest} ]; then
echo "Pre-release version matches a previous release" 1>&2
exit 1
fi
git_commit_count=$(git rev-list --count "${git_tag_closest}..HEAD" 2> /dev/null)
if [ $? -ne 0 ]; then
exit 1
fi
else
git_commit_count=$(git rev-list --count HEAD 2> /dev/null)
fi
if [ -n "${git_commit_count}" ]; then
if [ -z "${version_pre}" ]; then
echo "Pre-release version needs a pre-release" 1>&2
exit 1
fi
git_commit_id=$(git rev-parse --short=6 HEAD 2> /dev/null)
if [ $? -ne 0 ]; then
exit 1
fi
if git diff --quiet 2> /dev/null; then
echo "${version_full}-${git_commit_count}+git.${git_commit_id}"
else
let "git_commit_count+=1"
echo "${version_full}-${git_commit_count}+git.${git_commit_id}.dirty"
fi
exit 0
fi
if [ -z "${version_pre}" ]; then
echo "${version_full}"
else
echo "${version_full}-${version_pre}"
fi