blob: 4d4d080b6bf589acad85164b340e67057658827d [file] [log] [blame]
Harald Welteee497f22017-10-03 16:54:41 +08001#!/bin/sh
2VERSION=$1
3REL=$2
4
5if [ "z$REL" = "z" ]; then
6 echo "No REL value specified, defaulting to 'patch' release"
Pau Espin Pedrol941fd9b2018-08-30 12:42:37 +02007 REL="patch"
Harald Welteee497f22017-10-03 16:54:41 +08008fi
9
Pau Espin Pedrolcf8497c2018-08-30 12:56:53 +020010ALLOW_NO_LIBVERSION_CHANGE="${ALLOW_NO_LIBVERSION_CHANGE:-0}"
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +020011ALLOW_NO_LIBVERSION_DEB_MATCH="${ALLOW_NO_LIBVERSION_DEB_MATCH:-0}"
12
13libversion_to_deb_major() {
14 libversion="$1"
15 current="$(echo "$libversion" | cut -d ":" -f 1)"
16 #revision="$(echo "$libversion" | cut -d ":" -f 2)"
17 age="$(echo "$libversion" | cut -d ":" -f 3)"
18 major="$(expr "$current" - "$age")"
19 echo "$major"
20}
Pau Espin Pedrolcf8497c2018-08-30 12:56:53 +020021
Harald Welteee497f22017-10-03 16:54:41 +080022BUMPVER=`command -v bumpversion`
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +020023GIT_TOPDIR="$(git rev-parse --show-toplevel)"
Harald Welteee497f22017-10-03 16:54:41 +080024NEW_VER=`bumpversion --list --current-version $VERSION $REL --allow-dirty | awk -F '=' '{ print $2 }'`
25LIBVERS=`git grep -n LIBVERSION | grep '=' | grep am | grep -v LDFLAGS`
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +020026MAKEMOD=`git diff --cached -GLIBVERSION --stat | grep Makefile.am`
Harald Welteee497f22017-10-03 16:54:41 +080027ISODATE=`date -I`
28
29if [ "z$BUMPVER" = "z" ]; then
30 echo Unable to find 'bumpversion' command.
31 exit 1
32fi
33
34if [ "z$NEW_VER" = "z" ]; then
35 echo "Please fix versioning to match http://semver.org/ spec (current is $VERSION) before proceeding."
36 exit 1
37fi
38
39echo "Releasing $VERSION -> $NEW_VER..."
40
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +020041if [ "z$LIBVERS" != "z" ]; then
Pau Espin Pedrolcf8497c2018-08-30 12:56:53 +020042 if [ "z$MAKEMOD" = "z" ] && [ "z$ALLOW_NO_LIBVERSION_CHANGE" = "z0" ]; then
43 echo "ERROR: Before releasing, please modify some of the libversions: $LIBVERS"
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +020044 echo "You should NOT be doing this unless you've read and understood following article:"
45 echo "https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html#Updating-version-info"
Pau Espin Pedrol0b0f9082018-05-02 15:58:37 +020046 exit 1
Harald Welteee497f22017-10-03 16:54:41 +080047 fi
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +020048 if [ "z$ALLOW_NO_LIBVERSION_DEB_MATCH" = "z0" ]; then
49 echo "$LIBVERS" | while read -r line; do
50 libversion=$(echo "$line" | cut -d "=" -f 2)
51 major="$(libversion_to_deb_major "$libversion")"
52 file_matches="$(find "${GIT_TOPDIR}/debian" -name "lib*${major}.install" | wc -l)"
53 if [ "z$file_matches" = "z0" ]; then
54 echo "ERROR: Found no matching debian/lib*$major.install file for LIBVERSION=$libversion"
55 exit 1
56 elif [ "z$file_matches" = "z1" ]; then
57 echo "OK: Found matching debian/lib*$major.install for LIBVERSION=$libversion"
58 else
59 echo "WARN: Found $file_matches files matching debian/lib*$major.install for LIBVERSION=$libversion, manual check required!"
60 fi
61 control_matches="$(grep -e "Package" "${GIT_TOPDIR}/debian/control" | grep "lib" | grep "$major$" | wc -l)"
62 if [ "z$control_matches" = "z0" ]; then
63 echo "ERROR: Found no matching Package lib*$major in debian/control for LIBVERSION=$libversion"
64 exit 1
65 elif [ "z$control_matches" = "z1" ]; then
66 echo "OK: Found 'Package: lib*$major' in debian/control for LIBVERSION=$libversion"
67 else
68 echo "WARN: Found $file_matches files matching 'Package: lib*$major' in debian/control for LIBVERSION=$libversion, manual check required!"
69 fi
70 done
71 # catch and forward exit from pipe subshell "while read":
72 if [ $? -ne 0 ]; then
73 exit 1
74 fi
75 fi
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +020076 if [ -f "TODO-RELEASE" ]; then
77 grep '#' TODO-RELEASE > TODO-RELEASE.clean
78 mv TODO-RELEASE.clean TODO-RELEASE
79 git add TODO-RELEASE
80 fi
Harald Welteee497f22017-10-03 16:54:41 +080081fi
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +020082gbp dch --debian-tag='%(version)s' --auto --meta --git-author --multimaint-merge --ignore-branch --new-version="$NEW_VER"
Harald Welteee497f22017-10-03 16:54:41 +080083dch -r -m --distribution "unstable" ""
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +020084git add debian/changelog
Harald Welteee497f22017-10-03 16:54:41 +080085bumpversion --current-version $VERSION $REL --tag --commit --tag-name $NEW_VER --allow-dirty
Pau Espin Pedrolbf819322018-05-03 15:25:11 +020086git commit --amend # let the user add extra information to the release commit.
Harald Welteee497f22017-10-03 16:54:41 +080087git tag -s $NEW_VER -f -m "Release v$NEW_VER on $ISODATE."
88echo "Release $NEW_VER prepared, tagged and signed."