-
Notifications
You must be signed in to change notification settings - Fork 6
/
dch_version.sh
executable file
·32 lines (28 loc) · 1.09 KB
/
dch_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
#!/bin/bash
BASH_COMPAT="4.2"
# This is a tool to convert a semver 2.0.0 compatible version to a format which
# is compatible with both debian packaging tools and - after the transformations
# applied in debian pybuild - python PEP 440. It should generate the same python
# package version as is generated by setuptools_scm's "post-release" scheme.
GIT_TAG=$(git describe --tags --abbrev=0 "$@")
GIT_DESCRIBE=$(git describe --tags --long --dirty=.d$(date +%Y%m%d) "$@")
GIT_EXTRA="${GIT_DESCRIBE#${GIT_TAG}}"
GIT_TAG="${GIT_TAG//-/~}"
GIT_TAG="${GIT_TAG//alpha./alpha}"
GIT_TAG="${GIT_TAG//beta./beta}"
GIT_TAG="${GIT_TAG//rc./rc}"
DCH_VERSION="${GIT_TAG}"
GIT_EXTRA="${GIT_EXTRA#-}"
GIT_DISTANCE="${GIT_EXTRA%%-*}"
GIT_BUILD="${GIT_EXTRA#${GIT_DISTANCE}-}"
GIT_BUILD_HASH="${GIT_BUILD%%.*}"
if [[ $GIT_DISTANCE == 0 ]]; then
GIT_BUILD="${GIT_BUILD#${GIT_BUILD_HASH}}"
GIT_BUILD="${GIT_BUILD#.}"
fi
if [[ -n $GIT_BUILD ]]; then
DCH_VERSION+=".post${GIT_DISTANCE}+${GIT_BUILD}"
elif [[ $GIT_DISTANCE != 0 ]]; then
DCH_VERSION+=".post${GIT_DISTANCE}"
fi
echo "DCH_VERSION=$(printf %q "${DCH_VERSION}")"