blob: e9602aa1fdf70688692f83dad3e001949273c062 [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
Pau Espin Pedrolc4228d12019-08-07 14:41:44 +020063
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +020064 control_matches="$(grep -e "Package" "${GIT_TOPDIR}/debian/control" | grep "lib" | grep "$major$" | wc -l)"
65 if [ "z$control_matches" = "z0" ]; then
66 echo "ERROR: Found no matching Package lib*$major in debian/control for LIBVERSION=$libversion"
67 exit 1
68 elif [ "z$control_matches" = "z1" ]; then
69 echo "OK: Found 'Package: lib*$major' in debian/control for LIBVERSION=$libversion"
70 else
71 echo "WARN: Found $file_matches files matching 'Package: lib*$major' in debian/control for LIBVERSION=$libversion, manual check required!"
72 fi
Pau Espin Pedrolc4228d12019-08-07 14:41:44 +020073
74 dhstrip_lib_total="$(grep -e "dh_strip" "${GIT_TOPDIR}/debian/rules" | grep "\-plib" | wc -l)"
75 dhstrip_lib_matches="$(grep -e "dh_strip" "${GIT_TOPDIR}/debian/rules" | grep "\-plib" | grep "$major" | wc -l)"
76 if [ "z$dhstrip_lib_total" != "z0" ]; then
77 if [ "z$dhstrip_lib_matches" = "z0" ] ; then
78 echo "ERROR: Found no matching 'dh_strip -plib*$major' line in debian/rules for LIBVERSION=$libversion"
79 exit 1
80 elif [ "z$dhstrip_lib_total" = "z1" ]; then
81 echo "OK: Found 'dh_strip -plib*$major' in debian/rules for LIBVERSION=$libversion"
82 else
83 echo "WARN: Found $dhstrip_lib_matches/$dhstrip_lib_total dh_strip matches 'dh_strip -plib*$major' in debian/rules for LIBVERSION=$libversion, manual check required!"
84 fi
85 fi
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +020086 done
87 # catch and forward exit from pipe subshell "while read":
88 if [ $? -ne 0 ]; then
89 exit 1
90 fi
91 fi
Pau Espin Pedrolc5527f02019-08-07 14:40:08 +020092 if [ "z$DRY_RUN" != "z0" ]; then
93 exit 0
94 fi
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +020095 if [ -f "TODO-RELEASE" ]; then
96 grep '#' TODO-RELEASE > TODO-RELEASE.clean
97 mv TODO-RELEASE.clean TODO-RELEASE
98 git add TODO-RELEASE
99 fi
Harald Welteee497f22017-10-03 16:54:41 +0800100fi
Pau Espin Pedrolc5527f02019-08-07 14:40:08 +0200101
102if [ "z$DRY_RUN" != "z0" ]; then
103 exit 0
104fi
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +0200105gbp dch --debian-tag='%(version)s' --auto --meta --git-author --multimaint-merge --ignore-branch --new-version="$NEW_VER"
Harald Welteee497f22017-10-03 16:54:41 +0800106dch -r -m --distribution "unstable" ""
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +0200107git add debian/changelog
Harald Welteee497f22017-10-03 16:54:41 +0800108bumpversion --current-version $VERSION $REL --tag --commit --tag-name $NEW_VER --allow-dirty
Pau Espin Pedrolbf819322018-05-03 15:25:11 +0200109git commit --amend # let the user add extra information to the release commit.
Harald Welteee497f22017-10-03 16:54:41 +0800110git tag -s $NEW_VER -f -m "Release v$NEW_VER on $ISODATE."
111echo "Release $NEW_VER prepared, tagged and signed."