blob: 3566ef92d78a4fb361279d7f818b460be7f814b7 [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() {
Pau Espin Pedrol1c4195f2021-03-26 13:50:08 +010076 # Some projects don't have rpm spec files:
77 if [ "z$(find "${GIT_TOPDIR}/contrib" -name "*.spec.in" | wc -l)" = "z0" ]; then
78 echo "INFO: Project has no 'contrib/*.spec.in' files, skipping RPM specific configure.ac dependency version checks"
79 return
80 fi
81
Pau Espin Pedrol44507192021-02-24 12:50:03 +010082 get_configureac_pkg_check_modules_list | \
83 { return_error=0
84 while read -r dep ver; do
85
86 rpmspecin_match="$(grep -e "pkgconfig(${dep})" ${GIT_TOPDIR}/contrib/*.spec.in | grep BuildRequires | grep pkgconfig | grep ">=")"
87 rpmspecin_match_count="$(echo "$rpmspecin_match" | grep -c ">=")"
88 if [ "z$rpmspecin_match_count" != "z0" ]; then
89 #echo "Dependency <$dep, $ver> from configure.ac matched in contrib/*.spec.in! ($rpmspecin_match_count)"
90 if [ "z$rpmspecin_match_count" != "z1" ]; then
91 echo "WARN: configure.ac <$dep, $ver> matches contrib/*.spec.in $rpmspecin_match_count times, manual check required!"
92 else # 1 match:
93 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")
94 rpmspecin_dep=$(echo "$parsed_match" | cut -d " " -f 1)
95 rpmspecin_ver=$(echo "$parsed_match" | cut -d " " -f 2)
96 if [ "z$dep" != "z$rpmspecin_dep" ] || [ "z$ver" != "z$rpmspecin_ver" ]; then
97 echo "ERROR: configure.ac <$dep, $ver> does NOT match contrib/*.spec.in <$rpmspecin_dep, $rpmspecin_ver>!"
98 return_error=1
99 #else
100 # echo "OK: configure.ac <$dep, $ver> matches contrib/*.spec.in <$debctrl_dep, $debctrl_ver>"
101 fi
102 fi
103 fi
104 done
105 if [ $return_error -ne 0 ]; then
106 exit 1
107 fi
108 }
109
110 # catch and forward exit from pipe subshell "while read":
111 if [ $? -ne 0 ]; then
112 echo "ERROR: exiting due to previous errors"
113 exit 1
114 fi
115 echo "OK: dependency specific versions in configure.ac and contrib/*.spec.in match"
116}
117
Pau Espin Pedrol3a8d5d32019-08-08 12:59:40 +0200118# Make sure that patches under debian/patches/ apply:
119check_debian_patch_apply() {
120 if [ ! -d "${GIT_TOPDIR}/debian/patches" ]; then
121 return
122 fi
123 for patch in ${GIT_TOPDIR}/debian/patches/*.patch; do
124 git apply --check $patch
125 if [ $? -ne 0 ]; then
126 echo "ERROR: patch no longer applies! $patch"
127 exit 1
128 else
129 echo "OK: patch applies: $patch"
130 fi
131 done
132}
133
Pau Espin Pedrole6230ef2021-02-24 13:22:44 +0100134libversion_deb_match() {
135 echo "$LIBVERS" | while read -r line; do
136 libversion=$(echo "$line" | cut -d "=" -f 2 | tr -d "[:space:]")
137 major="$(libversion_to_lib_major "$libversion")"
138 file_matches="$(find "${GIT_TOPDIR}/debian" -name "lib*${major}.install" | wc -l)"
139 if [ "z$file_matches" = "z0" ]; then
140 echo "ERROR: Found no matching debian/lib*$major.install file for LIBVERSION=$libversion"
141 exit 1
142 elif [ "z$file_matches" = "z1" ]; then
143 echo "OK: Found matching debian/lib*$major.install for LIBVERSION=$libversion"
144 else
145 echo "WARN: Found $file_matches files matching debian/lib*$major.install for LIBVERSION=$libversion, manual check required!"
146 fi
147
148 control_matches="$(grep -e "Package" "${GIT_TOPDIR}/debian/control" | grep "lib" | grep "$major$" | wc -l)"
149 if [ "z$control_matches" = "z0" ]; then
150 echo "ERROR: Found no matching Package lib*$major in debian/control for LIBVERSION=$libversion"
151 exit 1
152 elif [ "z$control_matches" = "z1" ]; then
153 echo "OK: Found 'Package: lib*$major' in debian/control for LIBVERSION=$libversion"
154 else
155 echo "WARN: Found $file_matches files matching 'Package: lib*$major' in debian/control for LIBVERSION=$libversion, manual check required!"
156 fi
157
158 dhstrip_lib_total="$(grep -e "dh_strip" "${GIT_TOPDIR}/debian/rules" | grep "\-plib" | wc -l)"
159 dhstrip_lib_matches="$(grep -e "dh_strip" "${GIT_TOPDIR}/debian/rules" | grep "\-plib" | grep "$major" | wc -l)"
160 if [ "z$dhstrip_lib_total" != "z0" ]; then
161 if [ "z$dhstrip_lib_matches" = "z0" ] ; then
162 echo "ERROR: Found no matching 'dh_strip -plib*$major' line in debian/rules for LIBVERSION=$libversion"
163 exit 1
164 elif [ "z$dhstrip_lib_total" = "z1" ]; then
165 echo "OK: Found 'dh_strip -plib*$major' in debian/rules for LIBVERSION=$libversion"
166 else
167 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!"
168 fi
169 fi
170 done
171 # catch and forward exit from pipe subshell "while read":
172 if [ $? -ne 0 ]; then
173 exit 1
174 fi
175}
176
177libversion_rpmspecin_match() {
Pau Espin Pedrol1c4195f2021-03-26 13:50:08 +0100178 # Some projects don't have rpm spec files:
179 if [ "z$(find "${GIT_TOPDIR}/contrib" -name "*.spec.in" | wc -l)" = "z0" ]; then
180 echo "INFO: Project has no 'contrib/*.spec.in' files, skipping RPM specific LIBVERSION checks"
181 return
182 fi
183
Pau Espin Pedrole6230ef2021-02-24 13:22:44 +0100184 echo "$LIBVERS" | while read -r line; do
185 libversion=$(echo "$line" | cut -d "=" -f 2 | tr -d "[:space:]")
186 major="$(libversion_to_lib_major "$libversion")"
187
188 control_matches="$(grep -e "%files" "${GIT_TOPDIR}/contrib/"*.spec.in | grep "lib" | grep "$major$" | wc -l)"
189 if [ "z$control_matches" = "z0" ]; then
190 echo "ERROR: Found no matching '%files -n lib*$major' in contrib/*.spec.in for LIBVERSION=$libversion"
191 exit 1
192 elif [ "z$control_matches" = "z1" ]; then
193 echo "OK: Found '%files -n lib*$major' in contrib/*.spec.in for LIBVERSION=$libversion"
194 else
195 echo "WARN: Found $file_matches files matching '%files -n lib*$major' in contrib/*.spec.in for LIBVERSION=$libversion, manual check required!"
196 fi
197
198 control_matches="$(grep -e "_libdir" "${GIT_TOPDIR}/contrib/"*.spec.in | grep "/lib" | grep "so.$major" | wc -l)"
199 if [ "z$control_matches" = "z0" ]; then
200 echo "ERROR: Found no matching '%_libdir/lib*.so.$major*' in contrib/*.spec.in for LIBVERSION=$libversion"
201 exit 1
202 elif [ "z$control_matches" = "z1" ]; then
203 echo "OK: Found '%_libdir/lib*.so.$major*' in contrib/*.spec.in for LIBVERSION=$libversion"
204 else
205 echo "WARN: Found $file_matches files matching '%_libdir/lib*.so.$major*' in contrib/*.spec.in for LIBVERSION=$libversion, manual check required!"
206 fi
207 done
208 # catch and forward exit from pipe subshell "while read":
209 if [ $? -ne 0 ]; then
210 exit 1
211 fi
212}
213
214
Harald Welteee497f22017-10-03 16:54:41 +0800215BUMPVER=`command -v bumpversion`
Harald Welteee497f22017-10-03 16:54:41 +0800216if [ "z$BUMPVER" = "z" ]; then
217 echo Unable to find 'bumpversion' command.
218 exit 1
219fi
Pau Espin Pedrol43abde12021-02-24 16:44:48 +0100220NEW_VER=`$BUMPVER --list --current-version $VERSION $REL --allow-dirty | awk -F '=' '{ print $2 }'`
Harald Welteee497f22017-10-03 16:54:41 +0800221if [ "z$NEW_VER" = "z" ]; then
222 echo "Please fix versioning to match http://semver.org/ spec (current is $VERSION) before proceeding."
223 exit 1
224fi
Pau Espin Pedrol43abde12021-02-24 16:44:48 +0100225GIT_TOPDIR="$(git rev-parse --show-toplevel)"
Pau Espin Pedrolab5e9892021-11-16 13:02:28 +0100226LIBVERS=`git grep -n LIBVERSION | grep '=' | grep am | grep -v LDFLAGS | grep -v osmo-release.sh`
Pau Espin Pedrol43abde12021-02-24 16:44:48 +0100227MAKEMOD=`git diff --cached -GLIBVERSION --stat | grep Makefile.am`
228ISODATE=`date -I`
Harald Welteee497f22017-10-03 16:54:41 +0800229
230echo "Releasing $VERSION -> $NEW_VER..."
231
Pau Espin Pedrol6d575562019-08-07 23:39:32 +0200232check_configureac_debctrl_deps_match
Pau Espin Pedrol44507192021-02-24 12:50:03 +0100233check_configureac_rpmspecin_deps_match
Pau Espin Pedrol3a8d5d32019-08-08 12:59:40 +0200234check_debian_patch_apply
Pau Espin Pedrol6d575562019-08-07 23:39:32 +0200235
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +0200236if [ "z$LIBVERS" != "z" ]; then
Pau Espin Pedrolcf8497c2018-08-30 12:56:53 +0200237 if [ "z$MAKEMOD" = "z" ] && [ "z$ALLOW_NO_LIBVERSION_CHANGE" = "z0" ]; then
238 echo "ERROR: Before releasing, please modify some of the libversions: $LIBVERS"
Pau Espin Pedrol01dd5702018-05-03 15:01:47 +0200239 echo "You should NOT be doing this unless you've read and understood following article:"
240 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 +0200241 exit 1
Harald Welteee497f22017-10-03 16:54:41 +0800242 fi
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +0200243 if [ "z$ALLOW_NO_LIBVERSION_DEB_MATCH" = "z0" ]; then
Pau Espin Pedrole6230ef2021-02-24 13:22:44 +0100244 libversion_deb_match
245 fi
246 if [ "z$ALLOW_NO_LIBVERSION_RPM_MATCH" = "z0" ]; then
247 libversion_rpmspecin_match
Pau Espin Pedrol1a72baf2018-08-30 13:50:33 +0200248 fi
Harald Welteee497f22017-10-03 16:54:41 +0800249fi
Pau Espin Pedrolc5527f02019-08-07 14:40:08 +0200250
251if [ "z$DRY_RUN" != "z0" ]; then
252 exit 0
253fi
Pau Espin Pedrola6097132019-09-19 16:03:42 +0200254
Pau Espin Pedrol24277b42019-12-03 17:35:02 +0100255set -e
Pau Espin Pedrola6097132019-09-19 16:03:42 +0200256if [ -f "TODO-RELEASE" ]; then
Pau Espin Pedrol18157832021-02-23 14:31:11 +0100257 grep '#' TODO-RELEASE > TODO-RELEASE.clean || true
Pau Espin Pedrola6097132019-09-19 16:03:42 +0200258 mv TODO-RELEASE.clean TODO-RELEASE
259 git add TODO-RELEASE
260fi
261
Oliver Smithb76811b2021-02-26 08:38:20 +0100262# Add missing epoch (OS#5046)
263DEB_VER=$(head -1 debian/changelog | cut -d ' ' -f 2 | sed 's,(,,' | sed 's,),,')
264NEW_VER_WITH_EPOCH="$NEW_VER"
265case "$DEB_VER" in
266*:*)
267 epoch="$(echo "$DEB_VER" | cut -d: -f1)"
268 NEW_VER_WITH_EPOCH="$epoch:$NEW_VER"
269 ;;
270esac
271
272gbp dch \
273 --debian-tag='%(version)s' \
274 --auto \
275 --meta \
276 --git-author \
277 --multimaint-merge \
278 --ignore-branch \
279 --new-version="$NEW_VER_WITH_EPOCH"
Harald Welteee497f22017-10-03 16:54:41 +0800280dch -r -m --distribution "unstable" ""
Pau Espin Pedrolc996d652019-08-08 17:37:16 +0200281git add ${GIT_TOPDIR}/debian/changelog
Harald Welteee497f22017-10-03 16:54:41 +0800282bumpversion --current-version $VERSION $REL --tag --commit --tag-name $NEW_VER --allow-dirty
Pau Espin Pedrolbf819322018-05-03 15:25:11 +0200283git commit --amend # let the user add extra information to the release commit.
Harald Welteee497f22017-10-03 16:54:41 +0800284git tag -s $NEW_VER -f -m "Release v$NEW_VER on $ISODATE."
285echo "Release $NEW_VER prepared, tagged and signed."