blob: 52ccfeb846e4fb6de493134ed8b0756213a51d07 [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 Pedrol44507192021-02-24 12:50:03 +010024get_configureac_pkg_check_modules_list() {
Pau Espin Pedrolc996d652019-08-08 17:37:16 +020025 if [ -f "${GIT_TOPDIR}/openbsc/configure.ac" ]; then
26 configureac_file="openbsc/configure.ac"
27 else
28 configureac_file="configure.ac"
29 fi
Pau Espin Pedrol44507192021-02-24 12:50:03 +010030 grep -e "PKG_CHECK_MODULES(" "${GIT_TOPDIR}/${configureac_file}" | cut -d "," -f 2 | tr -d ")" | tr -d "[" | tr -d "]" | tr -d " " | sed "s/>=/ /g"
31}
32
33# Make sure that depedency requirement versions match in configure.ac vs debian/control.
34#eg: "PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 1.1.0)" vs "libosmocore-dev (>= 1.0.0),"
35check_configureac_debctrl_deps_match() {
36 get_configureac_pkg_check_modules_list | \
Pau Espin Pedrol6d575562019-08-07 23:39:32 +020037 { return_error=0
38 while read -r dep ver; do
39
40 debctrl_match="$(grep -e "${dep}-dev" ${GIT_TOPDIR}/debian/control | grep ">=")"
41 debctrl_match_count="$(echo "$debctrl_match" | grep -c ">=")"
42 if [ "z$debctrl_match_count" != "z0" ]; then
43 #echo "Dependency <$dep, $ver> from configure.ac matched in debian/control! ($debctrl_match_count)"
44 if [ "z$debctrl_match_count" != "z1" ]; then
45 echo "WARN: configure.ac <$dep, $ver> matches debian/control $debctrl_match_count times, manual check required!"
46 else # 1 match:
Pau Espin Pedrole3870b32021-02-23 13:20:15 +010047 parsed_match=$(echo "$debctrl_match" | tr -d "(" | tr -d ")" | tr -d "," | tr -d " " | tr -d "\t" | sed "s/>=/ /g")
Pau Espin Pedrol6d575562019-08-07 23:39:32 +020048 debctrl_dep=$(echo "$parsed_match" | cut -d " " -f 1 | sed "s/-dev//g")
49 debctrl_ver=$(echo "$parsed_match" | cut -d " " -f 2)
50 if [ "z$dep" != "z$debctrl_dep" ] || [ "z$ver" != "z$debctrl_ver" ]; then
51 echo "ERROR: configure.ac <$dep, $ver> does NOT match debian/control <$debctrl_dep, $debctrl_ver>!"
52 return_error=1
53 #else
54 # echo "OK: configure.ac <$dep, $ver> matches debian/control <$debctrl_dep, $debctrl_ver>"
55 fi
56 fi
57 fi
58 done
59 if [ $return_error -ne 0 ]; then
60 exit 1
61 fi
62 }
63
64 # catch and forward exit from pipe subshell "while read":
65 if [ $? -ne 0 ]; then
66 echo "ERROR: exiting due to previous errors"
67 exit 1
68 fi
69 echo "OK: dependency specific versions in configure.ac and debian/control match"
70}
71
Pau Espin Pedrol44507192021-02-24 12:50:03 +010072# Make sure that depedency requirement versions match in configure.ac vs contrib/*.spec.in.
73#eg: "PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 1.1.0)" vs "pkgconfig(libosmocore-dev) >= 1.0.0,"
74check_configureac_rpmspecin_deps_match() {
75 get_configureac_pkg_check_modules_list | \
76 { return_error=0
77 while read -r dep ver; do
78
79 rpmspecin_match="$(grep -e "pkgconfig(${dep})" ${GIT_TOPDIR}/contrib/*.spec.in | grep BuildRequires | grep pkgconfig | grep ">=")"
80 rpmspecin_match_count="$(echo "$rpmspecin_match" | grep -c ">=")"
81 if [ "z$rpmspecin_match_count" != "z0" ]; then
82 #echo "Dependency <$dep, $ver> from configure.ac matched in contrib/*.spec.in! ($rpmspecin_match_count)"
83 if [ "z$rpmspecin_match_count" != "z1" ]; then
84 echo "WARN: configure.ac <$dep, $ver> matches contrib/*.spec.in $rpmspecin_match_count times, manual check required!"
85 else # 1 match:
86 parsed_match=$(echo "$rpmspecin_match" | tr -d "(" | tr -d ")" | tr -d ":" | tr -d " " | tr -d "\t" | sed "s/BuildRequires//g" | sed "s/pkgconfig//g" |sed "s/>=/ /g")
87 rpmspecin_dep=$(echo "$parsed_match" | cut -d " " -f 1)
88 rpmspecin_ver=$(echo "$parsed_match" | cut -d " " -f 2)
89 if [ "z$dep" != "z$rpmspecin_dep" ] || [ "z$ver" != "z$rpmspecin_ver" ]; then
90 echo "ERROR: configure.ac <$dep, $ver> does NOT match contrib/*.spec.in <$rpmspecin_dep, $rpmspecin_ver>!"
91 return_error=1
92 #else
93 # echo "OK: configure.ac <$dep, $ver> matches contrib/*.spec.in <$debctrl_dep, $debctrl_ver>"
94 fi
95 fi
96 fi
97 done
98 if [ $return_error -ne 0 ]; then
99 exit 1
100 fi
101 }
102
103 # catch and forward exit from pipe subshell "while read":
104 if [ $? -ne 0 ]; then
105 echo "ERROR: exiting due to previous errors"
106 exit 1
107 fi
108 echo "OK: dependency specific versions in configure.ac and contrib/*.spec.in match"
109}
110
Pau Espin Pedrol3a8d5d32019-08-08 12:59:40 +0200111# Make sure that patches under debian/patches/ apply:
112check_debian_patch_apply() {
113 if [ ! -d "${GIT_TOPDIR}/debian/patches" ]; then
114 return
115 fi
116 for patch in ${GIT_TOPDIR}/debian/patches/*.patch; do
117 git apply --check $patch
118 if [ $? -ne 0 ]; then
119 echo "ERROR: patch no longer applies! $patch"
120 exit 1
121 else
122 echo "OK: patch applies: $patch"
123 fi
124 done
125}
126
Harald Welteee497f22017-10-03 16:54:41 +0800127BUMPVER=`command -v bumpversion`
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +0200128GIT_TOPDIR="$(git rev-parse --show-toplevel)"
Harald Welteee497f22017-10-03 16:54:41 +0800129NEW_VER=`bumpversion --list --current-version $VERSION $REL --allow-dirty | awk -F '=' '{ print $2 }'`
130LIBVERS=`git grep -n LIBVERSION | grep '=' | grep am | grep -v LDFLAGS`
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +0200131MAKEMOD=`git diff --cached -GLIBVERSION --stat | grep Makefile.am`
Harald Welteee497f22017-10-03 16:54:41 +0800132ISODATE=`date -I`
133
134if [ "z$BUMPVER" = "z" ]; then
135 echo Unable to find 'bumpversion' command.
136 exit 1
137fi
138
139if [ "z$NEW_VER" = "z" ]; then
140 echo "Please fix versioning to match http://semver.org/ spec (current is $VERSION) before proceeding."
141 exit 1
142fi
143
144echo "Releasing $VERSION -> $NEW_VER..."
145
Pau Espin Pedrol6d575562019-08-07 23:39:32 +0200146check_configureac_debctrl_deps_match
Pau Espin Pedrol44507192021-02-24 12:50:03 +0100147check_configureac_rpmspecin_deps_match
Pau Espin Pedrol3a8d5d32019-08-08 12:59:40 +0200148check_debian_patch_apply
Pau Espin Pedrol6d575562019-08-07 23:39:32 +0200149
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +0200150if [ "z$LIBVERS" != "z" ]; then
Pau Espin Pedrolcf8497c2018-08-30 12:56:53 +0200151 if [ "z$MAKEMOD" = "z" ] && [ "z$ALLOW_NO_LIBVERSION_CHANGE" = "z0" ]; then
152 echo "ERROR: Before releasing, please modify some of the libversions: $LIBVERS"
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +0200153 echo "You should NOT be doing this unless you've read and understood following article:"
154 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 +0200155 exit 1
Harald Welteee497f22017-10-03 16:54:41 +0800156 fi
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +0200157 if [ "z$ALLOW_NO_LIBVERSION_DEB_MATCH" = "z0" ]; then
158 echo "$LIBVERS" | while read -r line; do
Pau Espin Pedrol2c281292019-08-06 17:58:22 +0200159 libversion=$(echo "$line" | cut -d "=" -f 2 | tr -d "[:space:]")
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +0200160 major="$(libversion_to_deb_major "$libversion")"
161 file_matches="$(find "${GIT_TOPDIR}/debian" -name "lib*${major}.install" | wc -l)"
162 if [ "z$file_matches" = "z0" ]; then
163 echo "ERROR: Found no matching debian/lib*$major.install file for LIBVERSION=$libversion"
164 exit 1
165 elif [ "z$file_matches" = "z1" ]; then
166 echo "OK: Found matching debian/lib*$major.install for LIBVERSION=$libversion"
167 else
168 echo "WARN: Found $file_matches files matching debian/lib*$major.install for LIBVERSION=$libversion, manual check required!"
169 fi
Pau Espin Pedrolc4228d12019-08-07 14:41:44 +0200170
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +0200171 control_matches="$(grep -e "Package" "${GIT_TOPDIR}/debian/control" | grep "lib" | grep "$major$" | wc -l)"
172 if [ "z$control_matches" = "z0" ]; then
173 echo "ERROR: Found no matching Package lib*$major in debian/control for LIBVERSION=$libversion"
174 exit 1
175 elif [ "z$control_matches" = "z1" ]; then
176 echo "OK: Found 'Package: lib*$major' in debian/control for LIBVERSION=$libversion"
177 else
178 echo "WARN: Found $file_matches files matching 'Package: lib*$major' in debian/control for LIBVERSION=$libversion, manual check required!"
179 fi
Pau Espin Pedrolc4228d12019-08-07 14:41:44 +0200180
181 dhstrip_lib_total="$(grep -e "dh_strip" "${GIT_TOPDIR}/debian/rules" | grep "\-plib" | wc -l)"
182 dhstrip_lib_matches="$(grep -e "dh_strip" "${GIT_TOPDIR}/debian/rules" | grep "\-plib" | grep "$major" | wc -l)"
183 if [ "z$dhstrip_lib_total" != "z0" ]; then
184 if [ "z$dhstrip_lib_matches" = "z0" ] ; then
185 echo "ERROR: Found no matching 'dh_strip -plib*$major' line in debian/rules for LIBVERSION=$libversion"
186 exit 1
187 elif [ "z$dhstrip_lib_total" = "z1" ]; then
188 echo "OK: Found 'dh_strip -plib*$major' in debian/rules for LIBVERSION=$libversion"
189 else
190 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!"
191 fi
192 fi
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +0200193 done
194 # catch and forward exit from pipe subshell "while read":
195 if [ $? -ne 0 ]; then
196 exit 1
197 fi
198 fi
Pau Espin Pedrolc5527f02019-08-07 14:40:08 +0200199 if [ "z$DRY_RUN" != "z0" ]; then
200 exit 0
201 fi
Harald Welteee497f22017-10-03 16:54:41 +0800202fi
Pau Espin Pedrolc5527f02019-08-07 14:40:08 +0200203
204if [ "z$DRY_RUN" != "z0" ]; then
205 exit 0
206fi
Pau Espin Pedrola6097132019-09-19 16:03:42 +0200207
Pau Espin Pedrol24277b42019-12-03 17:35:02 +0100208set -e
Pau Espin Pedrola6097132019-09-19 16:03:42 +0200209if [ -f "TODO-RELEASE" ]; then
Pau Espin Pedrol18157832021-02-23 14:31:11 +0100210 grep '#' TODO-RELEASE > TODO-RELEASE.clean || true
Pau Espin Pedrola6097132019-09-19 16:03:42 +0200211 mv TODO-RELEASE.clean TODO-RELEASE
212 git add TODO-RELEASE
213fi
214
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +0200215gbp dch --debian-tag='%(version)s' --auto --meta --git-author --multimaint-merge --ignore-branch --new-version="$NEW_VER"
Harald Welteee497f22017-10-03 16:54:41 +0800216dch -r -m --distribution "unstable" ""
Pau Espin Pedrolc996d652019-08-08 17:37:16 +0200217git add ${GIT_TOPDIR}/debian/changelog
Harald Welteee497f22017-10-03 16:54:41 +0800218bumpversion --current-version $VERSION $REL --tag --commit --tag-name $NEW_VER --allow-dirty
Pau Espin Pedrolbf819322018-05-03 15:25:11 +0200219git commit --amend # let the user add extra information to the release commit.
Harald Welteee497f22017-10-03 16:54:41 +0800220git tag -s $NEW_VER -f -m "Release v$NEW_VER on $ISODATE."
221echo "Release $NEW_VER prepared, tagged and signed."