1
|
#!/bin/bash
|
2
|
|
3
|
set -e -u
|
4
|
|
5
|
. $HOME/.campo
|
6
|
|
7
|
red="\e[91m"
|
8
|
default="\e[39m"
|
9
|
yellow="\e[93m"
|
10
|
green="\e[92m"
|
11
|
|
12
|
log()
|
13
|
{
|
14
|
echo -e "${yellow}$1${default}"
|
15
|
}
|
16
|
|
17
|
good()
|
18
|
{
|
19
|
echo -e "${green}$1${default}"
|
20
|
}
|
21
|
|
22
|
warning()
|
23
|
{
|
24
|
echo -e "${red}$1${default}"
|
25
|
}
|
26
|
|
27
|
|
28
|
updateFiles()
|
29
|
{
|
30
|
sed -i "s| v[0-9]*\.[0-9]*\.[0-9]* | v$major.$minor.$patch_ |g" README.md
|
31
|
sed -i "s| http.*://.*/file-.*\..*t | http://$CAMPO_DOMAIN/mase/test/file-v$major.$minor.$patch_.txt |g" README.md
|
32
|
|
33
|
commitDate=$(git log -1 --pretty="format:%ci")
|
34
|
sed -i "s|<!--- CommitDate -->.*<!--- /CommitDate -->|<!--- CommitDate -->$commitDate<!--- /CommitDate -->|g" README.md
|
35
|
|
36
|
}
|
37
|
|
38
|
prepareVersion()
|
39
|
{
|
40
|
log "Preparing new tag: v$major.$minor.$patch_"
|
41
|
|
42
|
if [ ! -z "$(git status -s)" ]; then
|
43
|
git commit -m "prepared for new release tag v$major.$minor.$patch_" README.md
|
44
|
else
|
45
|
warning "Replaced version information but nothing changed. Check if versions are ok."
|
46
|
fi
|
47
|
|
48
|
git tag "v$major.$minor.$patch_"
|
49
|
}
|
50
|
|
51
|
inspectVersion()
|
52
|
{
|
53
|
cut=$1
|
54
|
patch_=${cut##*.}
|
55
|
cut=${cut%.*}
|
56
|
minor=${cut##*.}
|
57
|
cut=${cut%.*}
|
58
|
major=${cut##*.}
|
59
|
cut=${cut%.*}
|
60
|
}
|
61
|
|
62
|
git describe --tags --dirty --long
|
63
|
# Must be empty or something was changed or untracked
|
64
|
|
65
|
if [ ! -z "$(git status -s)" ]; then
|
66
|
echo -e "${red}Something is dirty here;${default}"
|
67
|
git status
|
68
|
exit 22
|
69
|
fi
|
70
|
|
71
|
release=$(git describe --tags --dirty --long)
|
72
|
|
73
|
cut=${release#v*}
|
74
|
cut=${cut%%-*}
|
75
|
last=${release##*-}
|
76
|
|
77
|
if [ "$last" == "dirty" ]; then
|
78
|
echo " Its dirty"
|
79
|
release=${release%-*}
|
80
|
fi
|
81
|
|
82
|
sha=${release##*-}
|
83
|
release=${release%-*}
|
84
|
distance=${release##*-}
|
85
|
release=${release%-*}
|
86
|
|
87
|
inspectVersion $cut
|
88
|
|
89
|
echo "Cut: $cut"
|
90
|
echo "Sha: $sha"
|
91
|
echo "Distance: $distance"
|
92
|
echo "Current/Old Release: $major . $minor . $patch_"
|
93
|
doPrepareVersion=no
|
94
|
|
95
|
if [ "$#" -gt "0" ]; then
|
96
|
echo "Version manually"
|
97
|
inspectVersion ${1#v*}
|
98
|
doPrepareVersion=yes
|
99
|
elif [ "$distance" != "0" ]; then
|
100
|
echo "I have to create a new tag"
|
101
|
let patch_+=1
|
102
|
doPrepareVersion=yes
|
103
|
fi
|
104
|
|
105
|
updateFiles
|
106
|
|
107
|
if [ ! -z "$(git status -s)" ] && [ ! "${doPrepareVersion}" == "yes" ]; then
|
108
|
warning "Files changed but i was not going to update. Maybe URL changed. Increasing version"
|
109
|
git diff
|
110
|
let patch_+=1
|
111
|
updateFiles
|
112
|
doPrepareVersion=yes
|
113
|
fi
|
114
|
|
115
|
if [ "${doPrepareVersion}" == "yes" ]; then
|
116
|
echo "New Release: $major . $minor . $patch_"
|
117
|
prepareVersion
|
118
|
else
|
119
|
log "No re-versioning necessary"
|
120
|
fi
|
121
|
|
122
|
good finished
|
123
|
|
124
|
|
125
|
#---fin------------------------------------------------------------------------
|