This repository has been archived by the owner on Jan 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtag2rel.sh
executable file
·212 lines (191 loc) · 7.37 KB
/
tag2rel.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/bash
## Script to extract versioning information from a git tag
usage(){
usage="Usage: $0 <tag>
Options:
<tag> is (optionally) the tag being used to create a release in the form vX.Y.Z(-(alpha|beta|pre|rc)[0-9]+)?(-git[a-fA-F0-9]{6,8})?
Returns:
* Major is the current major version number
* Minor is the current minor version number
* Patch is the current patch version number
* Version(version) is the base X.Y.Z version of the tag which is the parent of the commit being built
* Release(relver) is the release version added to an RPM i.e., X.Y.Z-relver (see https://fedoraproject.org/wiki/Package_Versioning_Examples for examples)
* FullVersion
* TagVersion is the full name of the tag which is a parent of this commit
* Revision(gitrev) is the git revision hash of the commit
* GitVersion(gitver) e.g., v0.99.0-pre10-2-g47878f-dirty
Major:0 Minor:99 Patch:0 Release:0.3.pre10 Version:0.99.0 FullVersion:v0.99.0-pre10 TagVersion:v0.99.0 Revision:47878ff GitVersion:v0.99.0-pre10-2-g47878f-dirty
Description:
This script aims to provide a unique identifier for every built version of a package.
Whether for a build done by the CI system, or a local build made by a developer, certain information will be encoded
For an untagged release, gitver will be used to determine the base tag, and will compute the distance from this most recent, adding this as a devX release for python and -0.0.X.dev for the RPM 'Release' tag (alpha|beta|pre|rc)X releases (from the tag) will be built as adding this as a pre-release build (alpha|beta|pre|rc)X release for python and -0.Y.X.(alpha|beta|pre|rc) for the RPM 'Release' tag, where Y indicates 1,2,3,4 for alpha,beta,pre,rc (resp.)
If the parent tag is a complete tag, the returned tag will be bumped and the Release indicates the number of commits since that tag and the .devX designation
"
return 0
}
# list of tags and associated rpm/python release versions:
## ** Examples:
# tag name RPM Release pre-release
# v0.2.2 0.2.2 1 "-git<hash>"
# * commit 1 0.2.2 1.0.1.dev "-final.dev1-git<hash>"
# OR
# * commit 1 0.2.3 0.0.1.dev "-dev1-git<hash>"
# * commit 2 0.2.3 0.0.2.dev "-dev2-git<hash>"
# * commit 3 0.2.3 0.0.3.dev "-dev3-git<hash>"
# * commit 4 0.2.3 0.0.4.dev "-dev4-git<hash>"
# v0.2.3-alpha1 0.2.3 0.1.1.alpha1 "-alpha1-git<hash>"
# * commit 1 0.2.3 0.1.1.1.alpha1.dev "-alpha1.dev1-git<hash>"
# * commit 2 0.2.3 0.1.1.2.alpha1.dev "-alpha1.dev2-git<hash>"
# * commit 3 0.2.3 0.1.1.3.alpha1.dev "-alpha1.dev3-git<hash>"
# v0.2.3-alpha2 0.2.3 0.1.2.alpha2 "-alpha2-git<hash>"
# v0.2.3-alpha3 0.2.3 0.1.3.alpha3 "-alpha3-git<hash>"
# v0.2.3-beta1 0.2.3 0.2.1.beta1 "-beta1-git<hash>"
# v0.2.3-beta2 0.2.3 0.2.2.beta2 "-beta2-git<hash>"
# v0.2.3-pre1 0.2.3 0.3.1.pre1 "-pre1-git<hash>"
# v0.2.3-pre2 0.2.3 0.3.2.pre2 "-pre2-git<hash>"
# v0.2.3-pre3 0.2.3 0.3.3.pre3 "-pre3-git<hash>"
# v0.2.3-rc1 0.2.3 0.4.1.rc1 "-rc1-git<hash>"
# v0.2.3-rc2 0.2.3 0.4.2.rc2 "-rc2-git<hash>"
# v0.2.3 0.2.3 1 "-git<hash>"
# if previuos tag is complete, e.g., v0.2.2, bump next version values:
# Major: 1.0.0
# Minor: 0.3.0
# Patch: 0.2.3
# probably better to try to use setuptools_scm, which does this natively, but want something generically applicable
if [ -z ${1+x} ]
then
version=$(git describe --abbrev=0 --tags --always 2>/dev/null)
else
version=$1
fi
relver=1
gitrev=$(git rev-parse --short HEAD 2>/dev/null)
gitver=$(git describe --abbrev=6 --dirty --always --tags 2>/dev/null)
## can fail if no tags are present, robustify
tagcommit=$(git rev-list --tags --max-count=1 2>/dev/null)
lasttag=$(git describe --tags ${tagcommit} 2>/dev/null)
revision=0
if [ ! -z ${lasttag+x} ]
then
revision=$(git rev-list ${lasttag}.. --count 2>/dev/null)
fi
if [ -z ${revision+x} ]
then
revision=0
fi
# basic version unit is vX.Y.Z
vre='^v?(\.)?([0-9]+)\.([0-9]+)\.([0-9]+)'
gre='(git[0-9a-fA-F]{6,8})'
fullver=${version}
if [[ $version =~ $vre$ ]]
then
basever=$version
if [ ${revision} = "0" ]
then
buildtag="-final"
else
## needs a version bump somehow
# relver=0.0.$revision.dev
## doesn't need a version bump
relver=1.0.${revision}.dev
buildtag="-final.dev${revision}"
fi
elif [[ $version =~ $vre* ]]
then
pretag=""
if [[ ${version##*-} =~ ^git ]]
then
## only kept for legacy reason, don't put this in your tag
basever=${version%-*}
prerel=${version##*-}
version=${version%-*}
pretag="-git"
relnum=0
fi
if [[ ${version##*-} =~ ^dev ]]
then
## only kept for legacy reason, don't put this in your tag
basever=${version%-*}
prerel=${version##*-}
version=${version%-*}
pretag="-dev"
relnum=0
fi
if [[ ${version##*-} =~ ^(alpha|beta|pre|rc) ]]
then
basever=${version%-*}
prerel=${version##*-}
if [[ ${prerel} =~ ^alpha ]]
then
pretag="-alpha"
relnum=1
elif [[ ${prerel} =~ ^beta ]]
then
pretag="-beta"
relnum=2
elif [[ ${prerel} =~ ^pre ]]
then
pretag="-pre"
relnum=3
elif [[ ${prerel} =~ ^rc ]]
then
pretag="-rc"
relnum=3
fi
fi
tags=( $(git tag -l "*${basever}${pretag}*") )
ntags=$((${#tags[@]}))
if [[ ${prerel} =~ ^rc ]]
then
# because setuptools rewrites 'pre' as 'rc', need to count the number of 'pre' tags prior to addign the number of 'rc' tags
# or we enforce that 'pre' and 'rc' are the "same" class, 'rc'>'pre',
# and must numerically increase e.g., pre1->pre2->pre3->rc4->rc5
pretags=( $(git tag -l "*${basever}-pre*") )
npretags=$((${#pretags[@]}))
ntags=$((ntags+npretags))
fi
if [ ${revision} = "0" ]
then
relver=0.${relnum}.${ntags}.${prerel}
buildtag="${pretag}${ntags}"
else
relver=0.${relnum}.${ntags}.${revision}.${prerel}
buildtag="${pretag}${ntags}.dev${revision}"
fi
else
basever=untagged
buildtag="-dev${revision}"
fi
if ! [[ ${basever} =~ "untagged" ]]
then
version=${basever##v}
patch=${version##*.}
version=${version%.*}
minor=${version##*.}
major=${version%.*}
version=${basever##v}
else
## maybe try to extract tag info from Makefile (whole point was to remove this from the makefile...)?
version=${basever##v}
fullver=${version}-git${gitrev}
major=0
minor=0
patch=0
fi
NextMajorVer=$((major+1)).0.0
NextMinorVer=${major}.$((minor+1)).0
NextPatchVer=${major}.${minor}.$((patch+1))
## Output a single parseable line? or output multiple lines?
echo Major:${major} \
Minor:${minor} \
Patch:${patch} \
Release:${relver} \
Version:${version} \
FullVersion:${fullver} \
TagVersion:${basever} \
BuildTag:${buildtag} \
Revision:${gitrev} \
GitVersion:${gitver} \
NextMajorVer:${NextMajorVer} \
NextMinorVer:${NextMinorVer} \
NextPatchVer:${NextPatchVer}