| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | # In a git/autoconf/automake-enabled project with a NEWS file and a version- |
| 3 | # controlled .prev-version file, automate the procedure by which we record |
| 4 | # the date, release-type and version string in the NEWS file. That commit |
| 5 | # will serve to identify the release, so apply a signed tag to it as well. |
| 6 | VERSION=2026-02-04.14 # UTC |
| 7 | |
| 8 | # Note: this is a bash script (could be zsh or dash) |
| 9 | |
| 10 | # Copyright (C) 2009-2026 Free Software Foundation, Inc. |
| 11 | |
| 12 | # This program is free software: you can redistribute it and/or modify |
| 13 | # it under the terms of the GNU General Public License as published by |
| 14 | # the Free Software Foundation, either version 3 of the License, or |
| 15 | # (at your option) any later version. |
| 16 | |
| 17 | # This program is distributed in the hope that it will be useful, |
| 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | # GNU General Public License for more details. |
| 21 | |
| 22 | # You should have received a copy of the GNU General Public License |
| 23 | # along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 24 | |
| 25 | # Written by Jim Meyering |
| 26 | |
| 27 | ME=$(basenamescip-shell system . . basename. "$0") |
| 28 | warnscip-shell shell parted 3.7-1 warn().() { printfscip-shell system . . printf. '%s: %s\n' "$ME" "$*" >&2; } |
| 29 | diescip-shell shell parted 3.7-1 die().() { warnscip-shell shell parted 3.7-1 warn(). "$*"; exit 1; } |
| 30 | |
| 31 | helpscip-shell shell parted 3.7-1 help().() |
| 32 | { |
| 33 | catscip-shell system . . cat. <<EOF |
| 34 | Usage: $ME [OPTION...] VERSION RELEASE_TYPE |
| 35 | |
| 36 | Run this script from top_srcdir to perform the final pre-release NEWS |
| 37 | update in which the date, release-type and version string are |
| 38 | recorded. Commit that result with a log entry marking the release, |
| 39 | and apply a signed tag. Run it from your project's top-level |
| 40 | directory. |
| 41 | |
| 42 | Requirements: |
| 43 | - you use git for version-control |
| 44 | - a version-controlled .prev-version file |
| 45 | - a NEWS file, by default with line 3 identical to this: |
| 46 | $noteworthy_stub |
| 47 | |
| 48 | Options: |
| 49 | --branch=BRANCH set release branch (default: $branch) |
| 50 | -C, --builddir=DIR location of (configured) Makefile (default: $builddir) |
| 51 | |
| 52 | --news=FILE NEWS file name (default: $news) |
| 53 | --stub=STR release heading placeholder (default: |
| 54 | $noteworthy_stub) |
| 55 | --stub-version=STR release version placeholder (default: $ver_stub) |
| 56 | --stub-date=STR release date placeholder (default: $date_stub) |
| 57 | --stub-type=STR release type placeholder (default: $type_stub) |
| 58 | --stub-lines=RANGE sed line address range to search for heading |
| 59 | (default: $stub_range) |
| 60 | |
| 61 | --help print this help, then exit |
| 62 | --version print version number, then exit |
| 63 | |
| 64 | EXAMPLE: |
| 65 | To update NEWS and tag the beta 8.1 release of coreutils, I would run this: |
| 66 | |
| 67 | $ME 8.1 beta |
| 68 | |
| 69 | Report bugs and patches to <[email protected]>. |
| 70 | EOF |
| 71 | exit |
| 72 | } |
| 73 | |
| 74 | versionscip-shell shell parted 3.7-1 version().() |
| 75 | { |
| 76 | year=$(echoscip-shell system . . echo. "$VERSION" | sedscip-shell system . . sed. 's/[^0-9].*//') |
| 77 | catscip-shell system . . cat. <<EOF |
| 78 | $ME $VERSION |
| 79 | Copyright (C) $year Free Software Foundation, Inc, |
| 80 | License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html> |
| 81 | This is free software: you are free to change and redistribute it. |
| 82 | There is NO WARRANTY, to the extent permitted by law. |
| 83 | EOF |
| 84 | exit |
| 85 | } |
| 86 | |
| 87 | ## ------ ## |
| 88 | ## Main. ## |
| 89 | ## ------ ## |
| 90 | |
| 91 | # Constants. |
| 92 | noteworthy='* Noteworthy changes in release' |
| 93 | |
| 94 | # Variables. |
| 95 | branch=$(gitscip-shell system . . git. branch | sedscip-shell system . . sed. -ne '/^\* /{s///;p;q;}scip-shell filesystem . . `/^\* /{s///;p;q;}`.') |
| 96 | builddir=. |
| 97 | news=NEWS |
| 98 | ver_stub='?.?' |
| 99 | date_stub='(????-??-??)' |
| 100 | type_stub='[?]' |
| 101 | noteworthy_stub="$noteworthy $ver_stub $date_stub $type_stub" |
| 102 | stub_range=3 |
| 103 | |
| 104 | while testscip-shell system . . test. $# != 0 |
| 105 | do |
| 106 | # Handle --option=value by splitting apart and putting back on argv. |
| 107 | case $1 in |
| 108 | --*=*) |
| 109 | opt=$(echoscip-shell system . . echo. "$1" | sedscip-shell system . . sed. -e 's/=.*//') |
| 110 | val=$(echoscip-shell system . . echo. "$1" | sedscip-shell system . . sed. -e 's/[^=]*=//') |
| 111 | shift |
| 112 | set dummy "$opt" "$val" "$@"; shift |
| 113 | ;; |
| 114 | esac |
| 115 | |
| 116 | case $1 in |
| 117 | --help|--version) ${1#--};; |
| 118 | --branch) shift; branch=$1; shift ;; |
| 119 | -C|--builddir) shift; builddir=$1; shift ;; |
| 120 | --news) shift; news=$1; shift ;; |
| 121 | --stub) shift; noteworthy_stub=$1; shift ;; |
| 122 | --stub-version) shift; ver_stub=$1; shift ;; |
| 123 | --stub-date) shift; date_stub=$1; shift ;; |
| 124 | --stub-type) shift; type_stub=$1; shift ;; |
| 125 | --stub-lines) shift; stub_range=$1; shift ;; |
| 126 | --*) diescip-shell shell parted 3.7-1 die(). "unrecognized option: $1";; |
| 127 | *) break;; |
| 128 | esac |
| 129 | done |
| 130 | |
| 131 | testscip-shell system . . test. $# = 2 \ |
| 132 | || diescip-shell shell parted 3.7-1 die(). "Usage: $ME [OPTION...] VERSION TYPE" |
| 133 | |
| 134 | ver=$1 |
| 135 | type=$2 |
| 136 | |
| 137 | |
| 138 | ## ---------------------- ## |
| 139 | ## First, sanity checks. ## |
| 140 | ## ---------------------- ## |
| 141 | |
| 142 | # Verify that $ver looks like a version number, and... |
| 143 | echoscip-shell system . . echo. "$ver"|grepscip-shell system . . grep. -E '^[0-9][0-9.]*[0-9]$' > /dev/nullscip-shell filesystem . . `/dev/null`. \ |
| 144 | || diescip-shell shell parted 3.7-1 die(). "invalid version: $ver" |
| 145 | prev_ver=$(catscip-shell system . . cat. .prev-version) \ |
| 146 | || diescip-shell shell parted 3.7-1 die(). 'failed to determine previous version number from .prev-version' |
| 147 | |
| 148 | # Verify that $ver is sensible (> .prev-version). |
| 149 | case $(printfscip-shell system . . printf. "%s\n%s\n" "$prev_ver" "$ver"|sortscip-shell system . . sort. -V -u|trscip-shell system . . tr. '\n' ':') in |
| 150 | "$prev_ver:$ver:") ;; |
| 151 | *) diescip-shell shell parted 3.7-1 die(). "invalid version: $ver (<= $prev_ver)";; |
| 152 | esac |
| 153 | |
| 154 | case $type in |
| 155 | alpha|beta|stable) ;; |
| 156 | *) diescip-shell shell parted 3.7-1 die(). "invalid release type: $type";; |
| 157 | esac |
| 158 | |
| 159 | # No local modifications allowed. |
| 160 | case $(gitscip-shell system . . git. diff-index --name-only HEAD) in |
| 161 | '') ;; |
| 162 | *) diescip-shell shell parted 3.7-1 die(). 'this tree is dirty; commit your changes first';; |
| 163 | esac |
| 164 | |
| 165 | # Ensure the current branch name is correct: |
| 166 | curr_br=$(gitscip-shell system . . git. rev-parse --symbolic-full-name HEAD) |
| 167 | testscip-shell system . . test. "$curr_br" = "refs/heads/$branch" || diescip-shell shell parted 3.7-1 die(). not on branch $branch |
| 168 | |
| 169 | # Extract package name from Makefile. |
| 170 | Makefile=$builddir/Makefile |
| 171 | pkg=$(sedscip-shell system . . sed. -n 's/^PACKAGE = \(.*\)/\1/p' "$Makefile") \ |
| 172 | || diescip-shell shell parted 3.7-1 die(). "failed to determine package name from $Makefile" |
| 173 | |
| 174 | # Check that stub about to be replaced is in given NEWS line range. |
| 175 | stub_line=$(sedscip-shell system . . sed. -n "${stub_range}p" $news \ |
| 176 | | env gl_stub="$noteworthy_stub" \ |
| 177 | awk '$0 == ENVIRON["gl_stub"] { print NR }') |
| 178 | testscip-shell system . . test. -n "$stub_line" \ |
| 179 | || diescip-shell shell parted 3.7-1 die(). "one of line(s) $stub_range of $news must be exactly '$noteworthy_stub'" |
| 180 | |
| 181 | # One more than the line number $stub_line is relative to. |
| 182 | stub_offset=$(sedscip-shell system . . sed. -n "${stub_range}{=;q;}" "$news") |
| 183 | |
| 184 | ## --------------- ## |
| 185 | ## Then, changes. ## |
| 186 | ## --------------- ## |
| 187 | |
| 188 | # Update NEWS to have today's date, plus desired version number and $type. |
| 189 | enscip-shell system . . env.vscip-shell system . . env. gl_ver=$ver gl_ver_stub="$ver_stub" \ |
| 190 | gl_type=$type gl_type_stub="$type_stub" gl_date_stub="$date_stub" \ |
| 191 | gl_offset="$stub_offset" gl_line="$stub_line" \ |
| 192 | perl -MPOSIX -pi \ |
| 193 | -e 'if ($. == $ENV{gl_offset} + $ENV{gl_line} - 1) {' \ |
| 194 | -e ' my $today = strftime "%F", localtime time;' \ |
| 195 | -e ' s/\Q$ENV{gl_ver_stub}/$ENV{gl_ver}/;' \ |
| 196 | -e ' s/\Q$ENV{gl_date_stub}/($today)/;' \ |
| 197 | -e ' s/\Q$ENV{gl_type_stub}/[$ENV{gl_type}]/;' \ |
| 198 | -e '}' \ |
| 199 | $news \ |
| 200 | || diescip-shell shell parted 3.7-1 die(). 'failed to update NEWS' |
| 201 | |
| 202 | printfscip-shell system . . printf. "version %s\n\n* ${news}: Record release date.\n" "$ver" \ |
| 203 | | gitscip-shell system . . git. commit -F - -a || diescip-shell shell parted 3.7-1 die(). 'git commit failed' |
| 204 | gitscip-shell system . . git. tag -s -m "$pkg $ver" v$ver HEAD || diescip-shell shell parted 3.7-1 die(). 'git tag failed' |
| 205 | |
| 206 | # Local variables: |
| 207 | # indent-tabs-mode: nil |
| 208 | # eval: (add-hook 'before-save-hook 'time-stamp nil t) |
| 209 | # time-stamp-start: "VERSION=" |
| 210 | # time-stamp-format: "%Y-%02m-%02d.%02H" |
| 211 | # time-stamp-time-zone: "UTC0" |
| 212 | # time-stamp-end: " # UTC" |
| 213 | # End: |