blob: c0b0b4a74d137a61456e2b8196f3275f7c85dab0 [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 Pedrole6230ef2021-02-24 13:22:44 +010012ALLOW_NO_LIBVERSION_RPM_MATCH="${ALLOW_NO_LIBVERSION_RPM_MATCH:-0}"
Pau Espin Pedrolc5527f02019-08-07 14:40:08 +020013# Test stuff but don't modify stuff:
14DRY_RUN="${DRY_RUN:-0}"
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +020015
Pau Espin Pedrole6230ef2021-02-24 13:22:44 +010016libversion_to_lib_major() {
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +020017 libversion="$1"
18 current="$(echo "$libversion" | cut -d ":" -f 1)"
19 #revision="$(echo "$libversion" | cut -d ":" -f 2)"
20 age="$(echo "$libversion" | cut -d ":" -f 3)"
21 major="$(expr "$current" - "$age")"
22 echo "$major"
23}
Pau Espin Pedrolcf8497c2018-08-30 12:56:53 +020024
Pau Espin Pedrol44507192021-02-24 12:50:03 +010025get_configureac_pkg_check_modules_list() {
Pau Espin Pedrolc996d652019-08-08 17:37:16 +020026 if [ -f "${GIT_TOPDIR}/openbsc/configure.ac" ]; then
27 configureac_file="openbsc/configure.ac"
28 else
29 configureac_file="configure.ac"
30 fi
Pau Espin Pedrol44507192021-02-24 12:50:03 +010031 grep -e "PKG_CHECK_MODULES(" "${GIT_TOPDIR}/${configureac_file}" | cut -d "," -f 2 | tr -d ")" | tr -d "[" | tr -d "]" | tr -d " " | sed "s/>=/ /g"
32}
33
34# Make sure that depedency requirement versions match in configure.ac vs debian/control.
35#eg: "PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 1.1.0)" vs "libosmocore-dev (>= 1.0.0),"
36check_configureac_debctrl_deps_match() {
37 get_configureac_pkg_check_modules_list | \
Pau Espin Pedrol6d575562019-08-07 23:39:32 +020038 { return_error=0
39 while read -r dep ver; do
40
41 debctrl_match="$(grep -e "${dep}-dev" ${GIT_TOPDIR}/debian/control | grep ">=")"
42 debctrl_match_count="$(echo "$debctrl_match" | grep -c ">=")"
43 if [ "z$debctrl_match_count" != "z0" ]; then
44 #echo "Dependency <$dep, $ver> from configure.ac matched in debian/control! ($debctrl_match_count)"
45 if [ "z$debctrl_match_count" != "z1" ]; then
46 echo "WARN: configure.ac <$dep, $ver> matches debian/control $debctrl_match_count times, manual check required!"
47 else # 1 match:
Pau Espin Pedrole3870b32021-02-23 13:20:15 +010048 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 +020049 debctrl_dep=$(echo "$parsed_match" | cut -d " " -f 1 | sed "s/-dev//g")
50 debctrl_ver=$(echo "$parsed_match" | cut -d " " -f 2)
51 if [ "z$dep" != "z$debctrl_dep" ] || [ "z$ver" != "z$debctrl_ver" ]; then
52 echo "ERROR: configure.ac <$dep, $ver> does NOT match debian/control <$debctrl_dep, $debctrl_ver>!"
53 return_error=1
54 #else
55 # echo "OK: configure.ac <$dep, $ver> matches debian/control <$debctrl_dep, $debctrl_ver>"
56 fi
57 fi
58 fi
59 done
60 if [ $return_error -ne 0 ]; then
61 exit 1
62 fi
63 }
64
65 # catch and forward exit from pipe subshell "while read":
66 if [ $? -ne 0 ]; then
67 echo "ERROR: exiting due to previous errors"
68 exit 1
69 fi
70 echo "OK: dependency specific versions in configure.ac and debian/control match"
71}
72
Pau Espin Pedrol44507192021-02-24 12:50:03 +010073# Make sure that depedency requirement versions match in configure.ac vs contrib/*.spec.in.
74#eg: "PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 1.1.0)" vs "pkgconfig(libosmocore-dev) >= 1.0.0,"
75check_configureac_rpmspecin_deps_match() {
76 get_configureac_pkg_check_modules_list | \
77 { return_error=0
78 while read -r dep ver; do
79
80 rpmspecin_match="$(grep -e "pkgconfig(${dep})" ${GIT_TOPDIR}/contrib/*.spec.in | grep BuildRequires | grep pkgconfig | grep ">=")"
81 rpmspecin_match_count="$(echo "$rpmspecin_match" | grep -c ">=")"
82 if [ "z$rpmspecin_match_count" != "z0" ]; then
83 #echo "Dependency <$dep, $ver> from configure.ac matched in contrib/*.spec.in! ($rpmspecin_match_count)"
84 if [ "z$rpmspecin_match_count" != "z1" ]; then
85 echo "WARN: configure.ac <$dep, $ver> matches contrib/*.spec.in $rpmspecin_match_count times, manual check required!"
86 else # 1 match:
87 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")
88 rpmspecin_dep=$(echo "$parsed_match" | cut -d " " -f 1)
89 rpmspecin_ver=$(echo "$parsed_match" | cut -d " " -f 2)
90 if [ "z$dep" != "z$rpmspecin_dep" ] || [ "z$ver" != "z$rpmspecin_ver" ]; then
91 echo "ERROR: configure.ac <$dep, $ver> does NOT match contrib/*.spec.in <$rpmspecin_dep, $rpmspecin_ver>!"
92 return_error=1
93 #else
94 # echo "OK: configure.ac <$dep, $ver> matches contrib/*.spec.in <$debctrl_dep, $debctrl_ver>"
95 fi
96 fi
97 fi
98 done
99 if [ $return_error -ne 0 ]; then
100 exit 1
101 fi
102 }
103
104 # catch and forward exit from pipe subshell "while read":
105 if [ $? -ne 0 ]; then
106 echo "ERROR: exiting due to previous errors"
107 exit 1
108 fi
109 echo "OK: dependency specific versions in configure.ac and contrib/*.spec.in match"
110}
111
Pau Espin Pedrol3a8d5d32019-08-08 12:59:40 +0200112# Make sure that patches under debian/patches/ apply:
113check_debian_patch_apply() {
114 if [ ! -d "${GIT_TOPDIR}/debian/patches" ]; then
115 return
116 fi
117 for patch in ${GIT_TOPDIR}/debian/patches/*.patch; do
118 git apply --check $patch
119 if [ $? -ne 0 ]; then
120 echo "ERROR: patch no longer applies! $patch"
121 exit 1
122 else
123 echo "OK: patch applies: $patch"
124 fi
125 done
126}
127
Pau Espin Pedrole6230ef2021-02-24 13:22:44 +0100128libversion_deb_match() {
129 echo "$LIBVERS" | while read -r line; do
130 libversion=$(echo "$line" | cut -d "=" -f 2 | tr -d "[:space:]")
131 major="$(libversion_to_lib_major "$libversion")"
132 file_matches="$(find "${GIT_TOPDIR}/debian" -name "lib*${major}.install" | wc -l)"
133 if [ "z$file_matches" = "z0" ]; then
134 echo "ERROR: Found no matching debian/lib*$major.install file for LIBVERSION=$libversion"
135 exit 1
136 elif [ "z$file_matches" = "z1" ]; then
137 echo "OK: Found matching debian/lib*$major.install for LIBVERSION=$libversion"
138 else
139 echo "WARN: Found $file_matches files matching debian/lib*$major.install for LIBVERSION=$libversion, manual check required!"
140 fi
141
142 control_matches="$(grep -e "Package" "${GIT_TOPDIR}/debian/control" | grep "lib" | grep "$major$" | wc -l)"
143 if [ "z$control_matches" = "z0" ]; then
144 echo "ERROR: Found no matching Package lib*$major in debian/control for LIBVERSION=$libversion"
145 exit 1
146 elif [ "z$control_matches" = "z1" ]; then
147 echo "OK: Found 'Package: lib*$major' in debian/control for LIBVERSION=$libversion"
148 else
149 echo "WARN: Found $file_matches files matching 'Package: lib*$major' in debian/control for LIBVERSION=$libversion, manual check required!"
150 fi
151
152 dhstrip_lib_total="$(grep -e "dh_strip" "${GIT_TOPDIR}/debian/rules" | grep "\-plib" | wc -l)"
153 dhstrip_lib_matches="$(grep -e "dh_strip" "${GIT_TOPDIR}/debian/rules" | grep "\-plib" | grep "$major" | wc -l)"
154 if [ "z$dhstrip_lib_total" != "z0" ]; then
155 if [ "z$dhstrip_lib_matches" = "z0" ] ; then
156 echo "ERROR: Found no matching 'dh_strip -plib*$major' line in debian/rules for LIBVERSION=$libversion"
157 exit 1
158 elif [ "z$dhstrip_lib_total" = "z1" ]; then
159 echo "OK: Found 'dh_strip -plib*$major' in debian/rules for LIBVERSION=$libversion"
160 else
161 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!"
162 fi
163 fi
164 done
165 # catch and forward exit from pipe subshell "while read":
166 if [ $? -ne 0 ]; then
167 exit 1
168 fi
169}
170
171libversion_rpmspecin_match() {
172 echo "$LIBVERS" | while read -r line; do
173 libversion=$(echo "$line" | cut -d "=" -f 2 | tr -d "[:space:]")
174 major="$(libversion_to_lib_major "$libversion")"
175
176 control_matches="$(grep -e "%files" "${GIT_TOPDIR}/contrib/"*.spec.in | grep "lib" | grep "$major$" | wc -l)"
177 if [ "z$control_matches" = "z0" ]; then
178 echo "ERROR: Found no matching '%files -n lib*$major' in contrib/*.spec.in for LIBVERSION=$libversion"
179 exit 1
180 elif [ "z$control_matches" = "z1" ]; then
181 echo "OK: Found '%files -n lib*$major' in contrib/*.spec.in for LIBVERSION=$libversion"
182 else
183 echo "WARN: Found $file_matches files matching '%files -n lib*$major' in contrib/*.spec.in for LIBVERSION=$libversion, manual check required!"
184 fi
185
186 control_matches="$(grep -e "_libdir" "${GIT_TOPDIR}/contrib/"*.spec.in | grep "/lib" | grep "so.$major" | wc -l)"
187 if [ "z$control_matches" = "z0" ]; then
188 echo "ERROR: Found no matching '%_libdir/lib*.so.$major*' in contrib/*.spec.in for LIBVERSION=$libversion"
189 exit 1
190 elif [ "z$control_matches" = "z1" ]; then
191 echo "OK: Found '%_libdir/lib*.so.$major*' in contrib/*.spec.in for LIBVERSION=$libversion"
192 else
193 echo "WARN: Found $file_matches files matching '%_libdir/lib*.so.$major*' in contrib/*.spec.in for LIBVERSION=$libversion, manual check required!"
194 fi
195 done
196 # catch and forward exit from pipe subshell "while read":
197 if [ $? -ne 0 ]; then
198 exit 1
199 fi
200}
201
202
Harald Welteee497f22017-10-03 16:54:41 +0800203BUMPVER=`command -v bumpversion`
Harald Welteee497f22017-10-03 16:54:41 +0800204if [ "z$BUMPVER" = "z" ]; then
205 echo Unable to find 'bumpversion' command.
206 exit 1
207fi
Pau Espin Pedrol43abde12021-02-24 16:44:48 +0100208NEW_VER=`$BUMPVER --list --current-version $VERSION $REL --allow-dirty | awk -F '=' '{ print $2 }'`
Harald Welteee497f22017-10-03 16:54:41 +0800209if [ "z$NEW_VER" = "z" ]; then
210 echo "Please fix versioning to match http://semver.org/ spec (current is $VERSION) before proceeding."
211 exit 1
212fi
Pau Espin Pedrol43abde12021-02-24 16:44:48 +0100213GIT_TOPDIR="$(git rev-parse --show-toplevel)"
214LIBVERS=`git grep -n LIBVERSION | grep '=' | grep am | grep -v LDFLAGS`
215MAKEMOD=`git diff --cached -GLIBVERSION --stat | grep Makefile.am`
216ISODATE=`date -I`
Harald Welteee497f22017-10-03 16:54:41 +0800217
218echo "Releasing $VERSION -> $NEW_VER..."
219
Pau Espin Pedrol6d575562019-08-07 23:39:32 +0200220check_configureac_debctrl_deps_match
Pau Espin Pedrol44507192021-02-24 12:50:03 +0100221check_configureac_rpmspecin_deps_match
Pau Espin Pedrol3a8d5d32019-08-08 12:59:40 +0200222check_debian_patch_apply
Pau Espin Pedrol6d575562019-08-07 23:39:32 +0200223
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +0200224if [ "z$LIBVERS" != "z" ]; then
Pau Espin Pedrolcf8497c2018-08-30 12:56:53 +0200225 if [ "z$MAKEMOD" = "z" ] && [ "z$ALLOW_NO_LIBVERSION_CHANGE" = "z0" ]; then
226 echo "ERROR: Before releasing, please modify some of the libversions: $LIBVERS"
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +0200227 echo "You should NOT be doing this unless you've read and understood following article:"
228 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 +0200229 exit 1
Harald Welteee497f22017-10-03 16:54:41 +0800230 fi
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +0200231 if [ "z$ALLOW_NO_LIBVERSION_DEB_MATCH" = "z0" ]; then
Pau Espin Pedrole6230ef2021-02-24 13:22:44 +0100232 libversion_deb_match
233 fi
234 if [ "z$ALLOW_NO_LIBVERSION_RPM_MATCH" = "z0" ]; then
235 libversion_rpmspecin_match
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +0200236 fi
Harald Welteee497f22017-10-03 16:54:41 +0800237fi
Pau Espin Pedrolc5527f02019-08-07 14:40:08 +0200238
239if [ "z$DRY_RUN" != "z0" ]; then
240 exit 0
241fi
Pau Espin Pedrola6097132019-09-19 16:03:42 +0200242
Pau Espin Pedrol24277b42019-12-03 17:35:02 +0100243set -e
Pau Espin Pedrola6097132019-09-19 16:03:42 +0200244if [ -f "TODO-RELEASE" ]; then
Pau Espin Pedrol18157832021-02-23 14:31:11 +0100245 grep '#' TODO-RELEASE > TODO-RELEASE.clean || true
Pau Espin Pedrola6097132019-09-19 16:03:42 +0200246 mv TODO-RELEASE.clean TODO-RELEASE
247 git add TODO-RELEASE
248fi
249
Oliver Smithb76811b2021-02-26 08:38:20 +0100250# Add missing epoch (OS#5046)
251DEB_VER=$(head -1 debian/changelog | cut -d ' ' -f 2 | sed 's,(,,' | sed 's,),,')
252NEW_VER_WITH_EPOCH="$NEW_VER"
253case "$DEB_VER" in
254*:*)
255 epoch="$(echo "$DEB_VER" | cut -d: -f1)"
256 NEW_VER_WITH_EPOCH="$epoch:$NEW_VER"
257 ;;
258esac
259
260gbp dch \
261 --debian-tag='%(version)s' \
262 --auto \
263 --meta \
264 --git-author \
265 --multimaint-merge \
266 --ignore-branch \
267 --new-version="$NEW_VER_WITH_EPOCH"
Harald Welteee497f22017-10-03 16:54:41 +0800268dch -r -m --distribution "unstable" ""
Pau Espin Pedrolc996d652019-08-08 17:37:16 +0200269git add ${GIT_TOPDIR}/debian/changelog
Harald Welteee497f22017-10-03 16:54:41 +0800270bumpversion --current-version $VERSION $REL --tag --commit --tag-name $NEW_VER --allow-dirty
Pau Espin Pedrolbf819322018-05-03 15:25:11 +0200271git commit --amend # let the user add extra information to the release commit.
Harald Welteee497f22017-10-03 16:54:41 +0800272git tag -s $NEW_VER -f -m "Release v$NEW_VER on $ISODATE."
273echo "Release $NEW_VER prepared, tagged and signed."