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}" |
| 12 | |
| 13 | libversion_to_deb_major() { |
| 14 | libversion="$1" |
| 15 | current="$(echo "$libversion" | cut -d ":" -f 1)" |
| 16 | #revision="$(echo "$libversion" | cut -d ":" -f 2)" |
| 17 | age="$(echo "$libversion" | cut -d ":" -f 3)" |
| 18 | major="$(expr "$current" - "$age")" |
| 19 | echo "$major" |
| 20 | } |
Pau Espin Pedrol | cf8497c | 2018-08-30 12:56:53 +0200 | [diff] [blame] | 21 | |
Harald Welte | ee497f2 | 2017-10-03 16:54:41 +0800 | [diff] [blame] | 22 | BUMPVER=`command -v bumpversion` |
Pau Espin Pedrol | 1a72baf | 2018-08-30 13:50:33 +0200 | [diff] [blame] | 23 | GIT_TOPDIR="$(git rev-parse --show-toplevel)" |
Harald Welte | ee497f2 | 2017-10-03 16:54:41 +0800 | [diff] [blame] | 24 | NEW_VER=`bumpversion --list --current-version $VERSION $REL --allow-dirty | awk -F '=' '{ print $2 }'` |
| 25 | LIBVERS=`git grep -n LIBVERSION | grep '=' | grep am | grep -v LDFLAGS` |
Pau Espin Pedrol | 01dd570 | 2018-05-03 15:01:47 +0200 | [diff] [blame] | 26 | MAKEMOD=`git diff --cached -GLIBVERSION --stat | grep Makefile.am` |
Harald Welte | ee497f2 | 2017-10-03 16:54:41 +0800 | [diff] [blame] | 27 | ISODATE=`date -I` |
| 28 | |
| 29 | if [ "z$BUMPVER" = "z" ]; then |
| 30 | echo Unable to find 'bumpversion' command. |
| 31 | exit 1 |
| 32 | fi |
| 33 | |
| 34 | if [ "z$NEW_VER" = "z" ]; then |
| 35 | echo "Please fix versioning to match http://semver.org/ spec (current is $VERSION) before proceeding." |
| 36 | exit 1 |
| 37 | fi |
| 38 | |
| 39 | echo "Releasing $VERSION -> $NEW_VER..." |
| 40 | |
Pau Espin Pedrol | 01dd570 | 2018-05-03 15:01:47 +0200 | [diff] [blame] | 41 | if [ "z$LIBVERS" != "z" ]; then |
Pau Espin Pedrol | cf8497c | 2018-08-30 12:56:53 +0200 | [diff] [blame] | 42 | if [ "z$MAKEMOD" = "z" ] && [ "z$ALLOW_NO_LIBVERSION_CHANGE" = "z0" ]; then |
| 43 | echo "ERROR: Before releasing, please modify some of the libversions: $LIBVERS" |
Pau Espin Pedrol | 01dd570 | 2018-05-03 15:01:47 +0200 | [diff] [blame] | 44 | echo "You should NOT be doing this unless you've read and understood following article:" |
| 45 | 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] | 46 | exit 1 |
Harald Welte | ee497f2 | 2017-10-03 16:54:41 +0800 | [diff] [blame] | 47 | fi |
Pau Espin Pedrol | 1a72baf | 2018-08-30 13:50:33 +0200 | [diff] [blame] | 48 | if [ "z$ALLOW_NO_LIBVERSION_DEB_MATCH" = "z0" ]; then |
| 49 | echo "$LIBVERS" | while read -r line; do |
| 50 | libversion=$(echo "$line" | cut -d "=" -f 2) |
| 51 | major="$(libversion_to_deb_major "$libversion")" |
| 52 | file_matches="$(find "${GIT_TOPDIR}/debian" -name "lib*${major}.install" | wc -l)" |
| 53 | if [ "z$file_matches" = "z0" ]; then |
| 54 | echo "ERROR: Found no matching debian/lib*$major.install file for LIBVERSION=$libversion" |
| 55 | exit 1 |
| 56 | elif [ "z$file_matches" = "z1" ]; then |
| 57 | echo "OK: Found matching debian/lib*$major.install for LIBVERSION=$libversion" |
| 58 | else |
| 59 | echo "WARN: Found $file_matches files matching debian/lib*$major.install for LIBVERSION=$libversion, manual check required!" |
| 60 | fi |
| 61 | control_matches="$(grep -e "Package" "${GIT_TOPDIR}/debian/control" | grep "lib" | grep "$major$" | wc -l)" |
| 62 | if [ "z$control_matches" = "z0" ]; then |
| 63 | echo "ERROR: Found no matching Package lib*$major in debian/control for LIBVERSION=$libversion" |
| 64 | exit 1 |
| 65 | elif [ "z$control_matches" = "z1" ]; then |
| 66 | echo "OK: Found 'Package: lib*$major' in debian/control for LIBVERSION=$libversion" |
| 67 | else |
| 68 | echo "WARN: Found $file_matches files matching 'Package: lib*$major' in debian/control for LIBVERSION=$libversion, manual check required!" |
| 69 | fi |
| 70 | done |
| 71 | # catch and forward exit from pipe subshell "while read": |
| 72 | if [ $? -ne 0 ]; then |
| 73 | exit 1 |
| 74 | fi |
| 75 | fi |
Pau Espin Pedrol | 01dd570 | 2018-05-03 15:01:47 +0200 | [diff] [blame] | 76 | if [ -f "TODO-RELEASE" ]; then |
| 77 | grep '#' TODO-RELEASE > TODO-RELEASE.clean |
| 78 | mv TODO-RELEASE.clean TODO-RELEASE |
| 79 | git add TODO-RELEASE |
| 80 | fi |
Harald Welte | ee497f2 | 2017-10-03 16:54:41 +0800 | [diff] [blame] | 81 | fi |
Pau Espin Pedrol | 01dd570 | 2018-05-03 15:01:47 +0200 | [diff] [blame] | 82 | gbp dch --debian-tag='%(version)s' --auto --meta --git-author --multimaint-merge --ignore-branch --new-version="$NEW_VER" |
Harald Welte | ee497f2 | 2017-10-03 16:54:41 +0800 | [diff] [blame] | 83 | dch -r -m --distribution "unstable" "" |
Pau Espin Pedrol | 01dd570 | 2018-05-03 15:01:47 +0200 | [diff] [blame] | 84 | git add debian/changelog |
Harald Welte | ee497f2 | 2017-10-03 16:54:41 +0800 | [diff] [blame] | 85 | 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] | 86 | 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] | 87 | git tag -s $NEW_VER -f -m "Release v$NEW_VER on $ISODATE." |
| 88 | echo "Release $NEW_VER prepared, tagged and signed." |