blob: d59083c08a82a5a1d2cf692cd6dd142e666042f9 [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}"
Pau Espin Pedrolc5527f02019-08-07 14:40:08 +020012# Test stuff but don't modify stuff:
13DRY_RUN="${DRY_RUN:-0}"
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +020014
15libversion_to_deb_major() {
16 libversion="$1"
17 current="$(echo "$libversion" | cut -d ":" -f 1)"
18 #revision="$(echo "$libversion" | cut -d ":" -f 2)"
19 age="$(echo "$libversion" | cut -d ":" -f 3)"
20 major="$(expr "$current" - "$age")"
21 echo "$major"
22}
Pau Espin Pedrolcf8497c2018-08-30 12:56:53 +020023
Harald Welteee497f22017-10-03 16:54:41 +080024BUMPVER=`command -v bumpversion`
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +020025GIT_TOPDIR="$(git rev-parse --show-toplevel)"
Harald Welteee497f22017-10-03 16:54:41 +080026NEW_VER=`bumpversion --list --current-version $VERSION $REL --allow-dirty | awk -F '=' '{ print $2 }'`
27LIBVERS=`git grep -n LIBVERSION | grep '=' | grep am | grep -v LDFLAGS`
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +020028MAKEMOD=`git diff --cached -GLIBVERSION --stat | grep Makefile.am`
Harald Welteee497f22017-10-03 16:54:41 +080029ISODATE=`date -I`
30
31if [ "z$BUMPVER" = "z" ]; then
32 echo Unable to find 'bumpversion' command.
33 exit 1
34fi
35
36if [ "z$NEW_VER" = "z" ]; then
37 echo "Please fix versioning to match http://semver.org/ spec (current is $VERSION) before proceeding."
38 exit 1
39fi
40
41echo "Releasing $VERSION -> $NEW_VER..."
42
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +020043if [ "z$LIBVERS" != "z" ]; then
Pau Espin Pedrolcf8497c2018-08-30 12:56:53 +020044 if [ "z$MAKEMOD" = "z" ] && [ "z$ALLOW_NO_LIBVERSION_CHANGE" = "z0" ]; then
45 echo "ERROR: Before releasing, please modify some of the libversions: $LIBVERS"
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +020046 echo "You should NOT be doing this unless you've read and understood following article:"
47 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 +020048 exit 1
Harald Welteee497f22017-10-03 16:54:41 +080049 fi
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +020050 if [ "z$ALLOW_NO_LIBVERSION_DEB_MATCH" = "z0" ]; then
51 echo "$LIBVERS" | while read -r line; do
Pau Espin Pedrol2c281292019-08-06 17:58:22 +020052 libversion=$(echo "$line" | cut -d "=" -f 2 | tr -d "[:space:]")
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +020053 major="$(libversion_to_deb_major "$libversion")"
54 file_matches="$(find "${GIT_TOPDIR}/debian" -name "lib*${major}.install" | wc -l)"
55 if [ "z$file_matches" = "z0" ]; then
56 echo "ERROR: Found no matching debian/lib*$major.install file for LIBVERSION=$libversion"
57 exit 1
58 elif [ "z$file_matches" = "z1" ]; then
59 echo "OK: Found matching debian/lib*$major.install for LIBVERSION=$libversion"
60 else
61 echo "WARN: Found $file_matches files matching debian/lib*$major.install for LIBVERSION=$libversion, manual check required!"
62 fi
63 control_matches="$(grep -e "Package" "${GIT_TOPDIR}/debian/control" | grep "lib" | grep "$major$" | wc -l)"
64 if [ "z$control_matches" = "z0" ]; then
65 echo "ERROR: Found no matching Package lib*$major in debian/control for LIBVERSION=$libversion"
66 exit 1
67 elif [ "z$control_matches" = "z1" ]; then
68 echo "OK: Found 'Package: lib*$major' in debian/control for LIBVERSION=$libversion"
69 else
70 echo "WARN: Found $file_matches files matching 'Package: lib*$major' in debian/control for LIBVERSION=$libversion, manual check required!"
71 fi
72 done
73 # catch and forward exit from pipe subshell "while read":
74 if [ $? -ne 0 ]; then
75 exit 1
76 fi
77 fi
Pau Espin Pedrolc5527f02019-08-07 14:40:08 +020078 if [ "z$DRY_RUN" != "z0" ]; then
79 exit 0
80 fi
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +020081 if [ -f "TODO-RELEASE" ]; then
82 grep '#' TODO-RELEASE > TODO-RELEASE.clean
83 mv TODO-RELEASE.clean TODO-RELEASE
84 git add TODO-RELEASE
85 fi
Harald Welteee497f22017-10-03 16:54:41 +080086fi
Pau Espin Pedrolc5527f02019-08-07 14:40:08 +020087
88if [ "z$DRY_RUN" != "z0" ]; then
89 exit 0
90fi
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +020091gbp dch --debian-tag='%(version)s' --auto --meta --git-author --multimaint-merge --ignore-branch --new-version="$NEW_VER"
Harald Welteee497f22017-10-03 16:54:41 +080092dch -r -m --distribution "unstable" ""
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +020093git add debian/changelog
Harald Welteee497f22017-10-03 16:54:41 +080094bumpversion --current-version $VERSION $REL --tag --commit --tag-name $NEW_VER --allow-dirty
Pau Espin Pedrolbf819322018-05-03 15:25:11 +020095git commit --amend # let the user add extra information to the release commit.
Harald Welteee497f22017-10-03 16:54:41 +080096git tag -s $NEW_VER -f -m "Release v$NEW_VER on $ISODATE."
97echo "Release $NEW_VER prepared, tagged and signed."