Harald Welte | ee497f2 | 2017-10-03 16:54:41 +0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | VERSION=$1 |
| 3 | REL=$2 |
| 4 | |
| 5 | if [ "z$REL" = "z" ]; then |
| 6 | echo "No REL value specified, defaulting to 'patch' release" |
Pau Espin Pedrol | 941fd9b | 2018-08-30 12:42:37 +0200 | [diff] [blame] | 7 | REL="patch" |
Harald Welte | ee497f2 | 2017-10-03 16:54:41 +0800 | [diff] [blame] | 8 | fi |
| 9 | |
Pau Espin Pedrol | cf8497c | 2018-08-30 12:56:53 +0200 | [diff] [blame] | 10 | ALLOW_NO_LIBVERSION_CHANGE="${ALLOW_NO_LIBVERSION_CHANGE:-0}" |
Pau Espin Pedrol | 1a72baf | 2018-08-30 13:50:33 +0200 | [diff] [blame] | 11 | ALLOW_NO_LIBVERSION_DEB_MATCH="${ALLOW_NO_LIBVERSION_DEB_MATCH:-0}" |
Pau Espin Pedrol | e6230ef | 2021-02-24 13:22:44 +0100 | [diff] [blame] | 12 | ALLOW_NO_LIBVERSION_RPM_MATCH="${ALLOW_NO_LIBVERSION_RPM_MATCH:-0}" |
Pau Espin Pedrol | c5527f0 | 2019-08-07 14:40:08 +0200 | [diff] [blame] | 13 | # Test stuff but don't modify stuff: |
| 14 | DRY_RUN="${DRY_RUN:-0}" |
Pau Espin Pedrol | 1a72baf | 2018-08-30 13:50:33 +0200 | [diff] [blame] | 15 | |
Pau Espin Pedrol | e6230ef | 2021-02-24 13:22:44 +0100 | [diff] [blame] | 16 | libversion_to_lib_major() { |
Pau Espin Pedrol | 1a72baf | 2018-08-30 13:50:33 +0200 | [diff] [blame] | 17 | 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 Pedrol | cf8497c | 2018-08-30 12:56:53 +0200 | [diff] [blame] | 24 | |
Pau Espin Pedrol | 4450719 | 2021-02-24 12:50:03 +0100 | [diff] [blame] | 25 | get_configureac_pkg_check_modules_list() { |
Pau Espin Pedrol | c996d65 | 2019-08-08 17:37:16 +0200 | [diff] [blame] | 26 | 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 Pedrol | 4450719 | 2021-02-24 12:50:03 +0100 | [diff] [blame] | 31 | 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)," |
| 36 | check_configureac_debctrl_deps_match() { |
| 37 | get_configureac_pkg_check_modules_list | \ |
Pau Espin Pedrol | 6d57556 | 2019-08-07 23:39:32 +0200 | [diff] [blame] | 38 | { 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 Pedrol | e3870b3 | 2021-02-23 13:20:15 +0100 | [diff] [blame] | 48 | parsed_match=$(echo "$debctrl_match" | tr -d "(" | tr -d ")" | tr -d "," | tr -d " " | tr -d "\t" | sed "s/>=/ /g") |
Pau Espin Pedrol | 6d57556 | 2019-08-07 23:39:32 +0200 | [diff] [blame] | 49 | 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 Pedrol | 4450719 | 2021-02-24 12:50:03 +0100 | [diff] [blame] | 73 | # 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," |
| 75 | check_configureac_rpmspecin_deps_match() { |
Pau Espin Pedrol | 1c4195f | 2021-03-26 13:50:08 +0100 | [diff] [blame] | 76 | # 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 Pedrol | 4450719 | 2021-02-24 12:50:03 +0100 | [diff] [blame] | 82 | 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 Pedrol | 3a8d5d3 | 2019-08-08 12:59:40 +0200 | [diff] [blame] | 118 | # Make sure that patches under debian/patches/ apply: |
| 119 | check_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 Pedrol | e6230ef | 2021-02-24 13:22:44 +0100 | [diff] [blame] | 134 | libversion_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 | |
| 177 | libversion_rpmspecin_match() { |
Pau Espin Pedrol | 1c4195f | 2021-03-26 13:50:08 +0100 | [diff] [blame] | 178 | # 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 Pedrol | e6230ef | 2021-02-24 13:22:44 +0100 | [diff] [blame] | 184 | 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 Welte | ee497f2 | 2017-10-03 16:54:41 +0800 | [diff] [blame] | 215 | BUMPVER=`command -v bumpversion` |
Harald Welte | ee497f2 | 2017-10-03 16:54:41 +0800 | [diff] [blame] | 216 | if [ "z$BUMPVER" = "z" ]; then |
| 217 | echo Unable to find 'bumpversion' command. |
| 218 | exit 1 |
| 219 | fi |
Pau Espin Pedrol | 43abde1 | 2021-02-24 16:44:48 +0100 | [diff] [blame] | 220 | NEW_VER=`$BUMPVER --list --current-version $VERSION $REL --allow-dirty | awk -F '=' '{ print $2 }'` |
Harald Welte | ee497f2 | 2017-10-03 16:54:41 +0800 | [diff] [blame] | 221 | if [ "z$NEW_VER" = "z" ]; then |
| 222 | echo "Please fix versioning to match http://semver.org/ spec (current is $VERSION) before proceeding." |
| 223 | exit 1 |
| 224 | fi |
Pau Espin Pedrol | 43abde1 | 2021-02-24 16:44:48 +0100 | [diff] [blame] | 225 | GIT_TOPDIR="$(git rev-parse --show-toplevel)" |
| 226 | LIBVERS=`git grep -n LIBVERSION | grep '=' | grep am | grep -v LDFLAGS` |
| 227 | MAKEMOD=`git diff --cached -GLIBVERSION --stat | grep Makefile.am` |
| 228 | ISODATE=`date -I` |
Harald Welte | ee497f2 | 2017-10-03 16:54:41 +0800 | [diff] [blame] | 229 | |
| 230 | echo "Releasing $VERSION -> $NEW_VER..." |
| 231 | |
Pau Espin Pedrol | 6d57556 | 2019-08-07 23:39:32 +0200 | [diff] [blame] | 232 | check_configureac_debctrl_deps_match |
Pau Espin Pedrol | 4450719 | 2021-02-24 12:50:03 +0100 | [diff] [blame] | 233 | check_configureac_rpmspecin_deps_match |
Pau Espin Pedrol | 3a8d5d3 | 2019-08-08 12:59:40 +0200 | [diff] [blame] | 234 | check_debian_patch_apply |
Pau Espin Pedrol | 6d57556 | 2019-08-07 23:39:32 +0200 | [diff] [blame] | 235 | |
Pau Espin Pedrol | 01dd570 | 2018-05-03 15:01:47 +0200 | [diff] [blame] | 236 | if [ "z$LIBVERS" != "z" ]; then |
Pau Espin Pedrol | cf8497c | 2018-08-30 12:56:53 +0200 | [diff] [blame] | 237 | 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 Pedrol | 01dd570 | 2018-05-03 15:01:47 +0200 | [diff] [blame] | 239 | 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 Pedrol | 0b0f908 | 2018-05-02 15:58:37 +0200 | [diff] [blame] | 241 | exit 1 |
Harald Welte | ee497f2 | 2017-10-03 16:54:41 +0800 | [diff] [blame] | 242 | fi |
Pau Espin Pedrol | 1a72baf | 2018-08-30 13:50:33 +0200 | [diff] [blame] | 243 | if [ "z$ALLOW_NO_LIBVERSION_DEB_MATCH" = "z0" ]; then |
Pau Espin Pedrol | e6230ef | 2021-02-24 13:22:44 +0100 | [diff] [blame] | 244 | libversion_deb_match |
| 245 | fi |
| 246 | if [ "z$ALLOW_NO_LIBVERSION_RPM_MATCH" = "z0" ]; then |
| 247 | libversion_rpmspecin_match |
Pau Espin Pedrol | 1a72baf | 2018-08-30 13:50:33 +0200 | [diff] [blame] | 248 | fi |
Harald Welte | ee497f2 | 2017-10-03 16:54:41 +0800 | [diff] [blame] | 249 | fi |
Pau Espin Pedrol | c5527f0 | 2019-08-07 14:40:08 +0200 | [diff] [blame] | 250 | |
| 251 | if [ "z$DRY_RUN" != "z0" ]; then |
| 252 | exit 0 |
| 253 | fi |
Pau Espin Pedrol | a609713 | 2019-09-19 16:03:42 +0200 | [diff] [blame] | 254 | |
Pau Espin Pedrol | 24277b4 | 2019-12-03 17:35:02 +0100 | [diff] [blame] | 255 | set -e |
Pau Espin Pedrol | a609713 | 2019-09-19 16:03:42 +0200 | [diff] [blame] | 256 | if [ -f "TODO-RELEASE" ]; then |
Pau Espin Pedrol | 1815783 | 2021-02-23 14:31:11 +0100 | [diff] [blame] | 257 | grep '#' TODO-RELEASE > TODO-RELEASE.clean || true |
Pau Espin Pedrol | a609713 | 2019-09-19 16:03:42 +0200 | [diff] [blame] | 258 | mv TODO-RELEASE.clean TODO-RELEASE |
| 259 | git add TODO-RELEASE |
| 260 | fi |
| 261 | |
Oliver Smith | b76811b | 2021-02-26 08:38:20 +0100 | [diff] [blame] | 262 | # Add missing epoch (OS#5046) |
| 263 | DEB_VER=$(head -1 debian/changelog | cut -d ' ' -f 2 | sed 's,(,,' | sed 's,),,') |
| 264 | NEW_VER_WITH_EPOCH="$NEW_VER" |
| 265 | case "$DEB_VER" in |
| 266 | *:*) |
| 267 | epoch="$(echo "$DEB_VER" | cut -d: -f1)" |
| 268 | NEW_VER_WITH_EPOCH="$epoch:$NEW_VER" |
| 269 | ;; |
| 270 | esac |
| 271 | |
| 272 | gbp 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 Welte | ee497f2 | 2017-10-03 16:54:41 +0800 | [diff] [blame] | 280 | dch -r -m --distribution "unstable" "" |
Pau Espin Pedrol | c996d65 | 2019-08-08 17:37:16 +0200 | [diff] [blame] | 281 | git add ${GIT_TOPDIR}/debian/changelog |
Harald Welte | ee497f2 | 2017-10-03 16:54:41 +0800 | [diff] [blame] | 282 | bumpversion --current-version $VERSION $REL --tag --commit --tag-name $NEW_VER --allow-dirty |
Pau Espin Pedrol | bf81932 | 2018-05-03 15:25:11 +0200 | [diff] [blame] | 283 | git commit --amend # let the user add extra information to the release commit. |
Harald Welte | ee497f2 | 2017-10-03 16:54:41 +0800 | [diff] [blame] | 284 | git tag -s $NEW_VER -f -m "Release v$NEW_VER on $ISODATE." |
| 285 | echo "Release $NEW_VER prepared, tagged and signed." |