blob: 38f238dfdeb3d3f99eb261d98457f6dd7798b576 [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
Pau Espin Pedrol6d575562019-08-07 23:39:32 +020024# Make sure that depedency requirement versions match in configure.ac vs debian/control.
25#eg: "PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 1.1.0)" vs "libosmocore-dev (>= 1.0.0),"
26check_configureac_debctrl_deps_match() {
27 configureac_list=$(grep -e "PKG_CHECK_MODULES" "${GIT_TOPDIR}/configure.ac" | cut -d "," -f 2 | tr -d ")" | tr -d " " | sed "s/>=/ /g")
28 echo "$configureac_list" | \
29 { return_error=0
30 while read -r dep ver; do
31
32 debctrl_match="$(grep -e "${dep}-dev" ${GIT_TOPDIR}/debian/control | grep ">=")"
33 debctrl_match_count="$(echo "$debctrl_match" | grep -c ">=")"
34 if [ "z$debctrl_match_count" != "z0" ]; then
35 #echo "Dependency <$dep, $ver> from configure.ac matched in debian/control! ($debctrl_match_count)"
36 if [ "z$debctrl_match_count" != "z1" ]; then
37 echo "WARN: configure.ac <$dep, $ver> matches debian/control $debctrl_match_count times, manual check required!"
38 else # 1 match:
39 parsed_match=$(echo "$debctrl_match" | tr -d "(" | tr -d ")" | tr -d "," | tr -d " " | sed "s/>=/ /g")
40 debctrl_dep=$(echo "$parsed_match" | cut -d " " -f 1 | sed "s/-dev//g")
41 debctrl_ver=$(echo "$parsed_match" | cut -d " " -f 2)
42 if [ "z$dep" != "z$debctrl_dep" ] || [ "z$ver" != "z$debctrl_ver" ]; then
43 echo "ERROR: configure.ac <$dep, $ver> does NOT match debian/control <$debctrl_dep, $debctrl_ver>!"
44 return_error=1
45 #else
46 # echo "OK: configure.ac <$dep, $ver> matches debian/control <$debctrl_dep, $debctrl_ver>"
47 fi
48 fi
49 fi
50 done
51 if [ $return_error -ne 0 ]; then
52 exit 1
53 fi
54 }
55
56 # catch and forward exit from pipe subshell "while read":
57 if [ $? -ne 0 ]; then
58 echo "ERROR: exiting due to previous errors"
59 exit 1
60 fi
61 echo "OK: dependency specific versions in configure.ac and debian/control match"
62}
63
Harald Welteee497f22017-10-03 16:54:41 +080064BUMPVER=`command -v bumpversion`
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +020065GIT_TOPDIR="$(git rev-parse --show-toplevel)"
Harald Welteee497f22017-10-03 16:54:41 +080066NEW_VER=`bumpversion --list --current-version $VERSION $REL --allow-dirty | awk -F '=' '{ print $2 }'`
67LIBVERS=`git grep -n LIBVERSION | grep '=' | grep am | grep -v LDFLAGS`
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +020068MAKEMOD=`git diff --cached -GLIBVERSION --stat | grep Makefile.am`
Harald Welteee497f22017-10-03 16:54:41 +080069ISODATE=`date -I`
70
71if [ "z$BUMPVER" = "z" ]; then
72 echo Unable to find 'bumpversion' command.
73 exit 1
74fi
75
76if [ "z$NEW_VER" = "z" ]; then
77 echo "Please fix versioning to match http://semver.org/ spec (current is $VERSION) before proceeding."
78 exit 1
79fi
80
81echo "Releasing $VERSION -> $NEW_VER..."
82
Pau Espin Pedrol6d575562019-08-07 23:39:32 +020083check_configureac_debctrl_deps_match
84
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +020085if [ "z$LIBVERS" != "z" ]; then
Pau Espin Pedrolcf8497c2018-08-30 12:56:53 +020086 if [ "z$MAKEMOD" = "z" ] && [ "z$ALLOW_NO_LIBVERSION_CHANGE" = "z0" ]; then
87 echo "ERROR: Before releasing, please modify some of the libversions: $LIBVERS"
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +020088 echo "You should NOT be doing this unless you've read and understood following article:"
89 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 +020090 exit 1
Harald Welteee497f22017-10-03 16:54:41 +080091 fi
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +020092 if [ "z$ALLOW_NO_LIBVERSION_DEB_MATCH" = "z0" ]; then
93 echo "$LIBVERS" | while read -r line; do
Pau Espin Pedrol2c281292019-08-06 17:58:22 +020094 libversion=$(echo "$line" | cut -d "=" -f 2 | tr -d "[:space:]")
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +020095 major="$(libversion_to_deb_major "$libversion")"
96 file_matches="$(find "${GIT_TOPDIR}/debian" -name "lib*${major}.install" | wc -l)"
97 if [ "z$file_matches" = "z0" ]; then
98 echo "ERROR: Found no matching debian/lib*$major.install file for LIBVERSION=$libversion"
99 exit 1
100 elif [ "z$file_matches" = "z1" ]; then
101 echo "OK: Found matching debian/lib*$major.install for LIBVERSION=$libversion"
102 else
103 echo "WARN: Found $file_matches files matching debian/lib*$major.install for LIBVERSION=$libversion, manual check required!"
104 fi
Pau Espin Pedrolc4228d12019-08-07 14:41:44 +0200105
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +0200106 control_matches="$(grep -e "Package" "${GIT_TOPDIR}/debian/control" | grep "lib" | grep "$major$" | wc -l)"
107 if [ "z$control_matches" = "z0" ]; then
108 echo "ERROR: Found no matching Package lib*$major in debian/control for LIBVERSION=$libversion"
109 exit 1
110 elif [ "z$control_matches" = "z1" ]; then
111 echo "OK: Found 'Package: lib*$major' in debian/control for LIBVERSION=$libversion"
112 else
113 echo "WARN: Found $file_matches files matching 'Package: lib*$major' in debian/control for LIBVERSION=$libversion, manual check required!"
114 fi
Pau Espin Pedrolc4228d12019-08-07 14:41:44 +0200115
116 dhstrip_lib_total="$(grep -e "dh_strip" "${GIT_TOPDIR}/debian/rules" | grep "\-plib" | wc -l)"
117 dhstrip_lib_matches="$(grep -e "dh_strip" "${GIT_TOPDIR}/debian/rules" | grep "\-plib" | grep "$major" | wc -l)"
118 if [ "z$dhstrip_lib_total" != "z0" ]; then
119 if [ "z$dhstrip_lib_matches" = "z0" ] ; then
120 echo "ERROR: Found no matching 'dh_strip -plib*$major' line in debian/rules for LIBVERSION=$libversion"
121 exit 1
122 elif [ "z$dhstrip_lib_total" = "z1" ]; then
123 echo "OK: Found 'dh_strip -plib*$major' in debian/rules for LIBVERSION=$libversion"
124 else
125 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!"
126 fi
127 fi
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +0200128 done
129 # catch and forward exit from pipe subshell "while read":
130 if [ $? -ne 0 ]; then
131 exit 1
132 fi
133 fi
Pau Espin Pedrolc5527f02019-08-07 14:40:08 +0200134 if [ "z$DRY_RUN" != "z0" ]; then
135 exit 0
136 fi
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +0200137 if [ -f "TODO-RELEASE" ]; then
138 grep '#' TODO-RELEASE > TODO-RELEASE.clean
139 mv TODO-RELEASE.clean TODO-RELEASE
140 git add TODO-RELEASE
141 fi
Harald Welteee497f22017-10-03 16:54:41 +0800142fi
Pau Espin Pedrolc5527f02019-08-07 14:40:08 +0200143
144if [ "z$DRY_RUN" != "z0" ]; then
145 exit 0
146fi
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +0200147gbp dch --debian-tag='%(version)s' --auto --meta --git-author --multimaint-merge --ignore-branch --new-version="$NEW_VER"
Harald Welteee497f22017-10-03 16:54:41 +0800148dch -r -m --distribution "unstable" ""
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +0200149git add debian/changelog
Harald Welteee497f22017-10-03 16:54:41 +0800150bumpversion --current-version $VERSION $REL --tag --commit --tag-name $NEW_VER --allow-dirty
Pau Espin Pedrolbf819322018-05-03 15:25:11 +0200151git commit --amend # let the user add extra information to the release commit.
Harald Welteee497f22017-10-03 16:54:41 +0800152git tag -s $NEW_VER -f -m "Release v$NEW_VER on $ISODATE."
153echo "Release $NEW_VER prepared, tagged and signed."