Browse Source

simplify version number increasing and always just append "+0"

The increase-version-number script nowadays (it exists just as
convenience and backwards-compatibility wrapper) now just appends
"+0" to the specified <version_number> on the command line.

This turned out to be the most reliable way to get:

  $existing_old_version < $snapshot_version < $new_version

where $existing_old_version is the provided <version_number>,
$snapshot_version is a version number based on the output of the
script (as used inside scripts like generate-{git,svn}-snapshot)
and $new_version is a version number that might show up in the
future.

I am aware of only one exception where this isn't true with +0
appended for $snapshot. This would be the case when e.g. version
1.2.3 would be changed to 1.2.3-1. But this would mean a change
in Debian packaging as well (from Debian package source being
identical to the pristine source (AKA native package) vs.
upstream software packaged within Debian (AKA non-native
package)). In such a situation the $existing_old_version should
be raised from e.g. 1.2.3 to at least 1.2.3.1-1, otherwise the
generated $snapshot_version will be older than
$existing_old_version until it's 1.2.4, 1.3, etc.
merge-requests/109/head
Michael Prokop 11 years ago
parent
commit
fc3d0f11ab
  1. 67
      increase-version-number
  2. 26
      tests/increase-version-number

67
increase-version-number

@ -1,47 +1,34 @@
#!/bin/sh
set -u
if [ "$#" -lt 1 ] ; then
echo "Usage: $0 <version_number>" >&2
exit 1
fi
PREVIOUS_VERSION="$1"
# remove Debian parts of version number (-1*, ~1*, +1*)
BASE_VERSION=$(echo ${PREVIOUS_VERSION} | sed 's/\(-.*\)\|\(~.*\)\|\(+.*\)$//')
# if a Debian version is present, then use '-1' inside snapshot version
DEBIAN_VERSION=''
if echo $PREVIOUS_VERSION | grep -q -- '-' ; then
DEBIAN_VERSION='-1'
fi
if ! echo "$PREVIOUS_VERSION" | grep -q -- '\.' ; then
FIRST_PART="$PREVIOUS_VERSION"
LAST_PART=""
else
# first part of version number (0.9.2 -> 0.9)
FIRST_PART=$(echo $BASE_VERSION | sed 's/\(\.[0-9]*\)$//')
# last digit(s) of version number (0.9.2 -> 2)
LAST_PART=$(echo $BASE_VERSION | sed 's/.*\.\([0-9]*\)$/\1/')
fi
## raise version number (2 -> 3)
# 0.9.0 -> 0.9.1
if echo "$LAST_PART" | grep -q -- '^0$' ; then
RAISE_VERSION=$((LAST_PART + 1))
# 0.9.00 -> 0.9.01
elif echo "$LAST_PART" | grep -q -- '^0' ; then
RAISE_VERSION="0$((LAST_PART + 1))"
# 0.8 -> 0.9
else
RAISE_VERSION=$((LAST_PART + 1))
fi
# concat first part and raised version number (0.9.3)
INCR_VERSION="${FIRST_PART}.${RAISE_VERSION}"
echo "${INCR_VERSION}${DEBIAN_VERSION}"
# This script nowadays (that's why it exists as such simple and
# short script at all) just appends "+0" to the specified
# <version_number> on the command line.
#
# This turned out to be the most reliable way to get:
#
# $existing_old_version < $snapshot_version < $new_version
#
# where $existing_old_version is the provided <version_number>,
# $snapshot_version is a version number based on the output of
# the script (as used inside scripts like
# generate-{git,svn}-snapshot) and $new_version is a version
# number that might show up in the future.
#
# NOTE: The author of jenkins-debian-glue is aware of only one
# exception where this isn't true with +0 appended for $snapshot.
# This would be the case when e.g. version 1.2.3 would be changed
# to 1.2.3-1. But this would mean a change in Debian packaging as
# well (from Debian package source being identical to the
# pristine source (AKA native package) vs. upstream software
# packaged within Debian (AKA non-native package)). In such a
# situation the $existing_old_version should be raised from e.g.
# 1.2.3 to at least 1.2.3.1-1, otherwise the generated
# $snapshot_version will be older than $existing_old_version
# until it's 1.2.4, 1.3, etc.
echo "${1}+0"

26
tests/increase-version-number

@ -4,19 +4,19 @@ SCRIPT=./increase-version-number
testEquality()
{
assertEquals "$($SCRIPT 0.23)" 0.24
assertEquals "$($SCRIPT 23)" 23.1
assertEquals "$($SCRIPT 0.23-1)" 0.24-1
assertEquals "$($SCRIPT 0.1.23-1)" 0.1.24-1
assertEquals "$($SCRIPT 0.1.23-3)" 0.1.24-1
assertEquals "$($SCRIPT 1:0.42-2)" 1:0.43-1
assertEquals "$($SCRIPT 2008.01.02)" 2008.01.03
assertEquals "$($SCRIPT 0.42~2)" 0.43
assertEquals "$($SCRIPT 0.9.0)" 0.9.1
assertEquals "$($SCRIPT 0.9.00)" 0.9.01
assertEquals "$($SCRIPT 0.8)" 0.9
assertEquals "$($SCRIPT 0.9)" 0.10
assertEquals "$($SCRIPT 3.1.4+1)" 3.1.5
assertEquals "$($SCRIPT 0.23)" 0.23+0
assertEquals "$($SCRIPT 23)" 23+0
assertEquals "$($SCRIPT 0.23-1)" 0.23-1+0
assertEquals "$($SCRIPT 0.1.23-1)" 0.1.23-1+0
assertEquals "$($SCRIPT 0.1.23-3)" 0.1.23-3+0
assertEquals "$($SCRIPT 1:0.42-2)" 1:0.42-2+0
assertEquals "$($SCRIPT 2008.01.02)" 2008.01.02+0
assertEquals "$($SCRIPT 0.42~2)" 0.42~2+0
assertEquals "$($SCRIPT 0.9.0)" 0.9.0+0
assertEquals "$($SCRIPT 0.9.00)" 0.9.00+0
assertEquals "$($SCRIPT 0.8)" 0.8+0
assertEquals "$($SCRIPT 0.9)" 0.9+0
assertEquals "$($SCRIPT 3.1.4+1)" 3.1.4+1+0
}
. /usr/share/shunit2/shunit2

Loading…
Cancel
Save