author | Olivier Brunel
<jjk@jjacky.com> 2023-12-23 22:28:55 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2024-01-09 18:16:31 UTC |
parent | 051303be6d82b280b6191843ac351d8eefa9204e |
libcomain | +8 | -3 |
mkrelease | +85 | -35 |
diff --git a/libcomain b/libcomain index ec59e93..13f43a0 100644 --- a/libcomain +++ b/libcomain @@ -348,11 +348,16 @@ loaddeps() getchangelog() { + if test $# -eq 1 && test $1 -gt 0; then + n=1 + else + n=2 + fi if test ! -f meta/HISTORY; then return; fi - cat meta/HISTORY | awk ' + cat meta/HISTORY | awk -v n=$n ' BEGIN { i=0 } -$1=="#" { if (++i>2) exit } -{ if ($1 != "#" && i==2) print } +$1=="#" { if (++i>n) exit } +{ if ($1 != "#" && i==n) print } ' } diff --git a/mkrelease b/mkrelease index 2e5cb45..a8d99e9 100755 --- a/mkrelease +++ b/mkrelease @@ -19,14 +19,54 @@ major=$(echo $ver | cut -d. -f1) minor=$(echo $ver | cut -d. -f2) rev=$(echo $ver | cut -d. -f3) +if test $(expr match "$rev" "[0-9]\+rc") -gt 0; then + rc="$(echo $rev | sed -e 's/^.*rc//')" + rev="$(echo $rev | sed -e 's/rc.*$//')" +else + rc=0 +fi + case "$1" in - major) major=$(($major + 1)); minor=0; rev=0 ;; - minor) minor=$(($minor + 1)); rev=0 ;; - rev) rev=$(($rev + 1)) ;; - *) error 1 "you need to specify 'major', 'minor' or 'rev'" + rel) test $rc -eq 0 && error 1 "current version not an rc" + rc=0 ;; + major) major=$(($major + 1)); minor=0; rev=0 ; rc=0 ;; + minor) minor=$(($minor + 1)); rev=0 ; rc=0 ;; + rev) rev=$(($rev + 1)) ; rc=0 ;; + rc) + if test $rc -gt 0; then + (( ++rc )) + else + error 2 "current version not an rc; try major|minor|rev rc" + fi + ;; + *) error 1 "you need to specify 'major', 'minor', 'rev', 'rc' or 'rel'" esac +shift + +if test $# -eq 1; then + if test "$1" = "rc"; then + test $rc -gt 0 && error 2 "cannot use rc on rc" + (( ++rc )) + else + error 1 "invalid argument: $1" + fi + shift +fi + +test $rc -gt 0 && rev="${rev}rc$rc" + +test $# -eq 0 || error 1 "Too many arguments" new=$major.$minor.$rev + +printf "Bumping $ver to $new ? [yN] " +read a +case "$a" in + [Yy]) ;; + ""|[Nn]) exit 0 ;; + *) error 3 "invalid answer" ;; +esac + echo " => bumping $ver to $new..." date="$(date +%Y-%m-%d)" @@ -44,7 +84,7 @@ if ! test "$(git show-ref --heads --hash dev)" = "$was_master"; then echo "Ignoring that dev and master differ..." was_master= else - error 1 "dev and master differ (-f to ignore)" + error 4 "dev and master differ (-f to ignore)" fi fi @@ -54,34 +94,38 @@ elif ! git xxx -q; then echo " -> Might be things left to do..." git xxx echo "Use -f to force the release anyway." - exit 1 + exit 5 fi -echo " -> Checking for new man pages..." -git diff --name-only --diff-filter=A $(cat meta/version) -- doc \ - | while read -r file ; do - echo " * Updating $file..." - { head -n 2 "$file"; echo "% $prjname $new"; echo "% $date"; tail -n +3 "$file"; } > "$file.tmp" - mv -f "$file.tmp" "$file" -done - -echo " -> Checking for modified man pages..." -git diff --name-only --diff-filter=M $(cat meta/version) -- doc \ - | while read -r file ; do - echo " * Updating $file..." - { head -n 2 "$file"; echo "% $prjname $new"; echo "% $date"; tail -n +5 "$file"; } > "$file.tmp" - mv -f "$file.tmp" "$file" -done +if test $rc -eq 0; then + + echo " -> Checking for new man pages..." + git diff --name-only --diff-filter=A $(cat meta/version) -- doc \ + | while read -r file ; do + echo " * Updating $file..." + { head -n 2 "$file"; echo "% $prjname $new"; echo "% $date"; tail -n +3 "$file"; } > "$file.tmp" + mv -f "$file.tmp" "$file" + done + + echo " -> Checking for modified man pages..." + git diff --name-only --diff-filter=M $(cat meta/version) -- doc \ + | while read -r file ; do + echo " * Updating $file..." + { head -n 2 "$file"; echo "% $prjname $new"; echo "% $date"; tail -n +5 "$file"; } > "$file.tmp" + mv -f "$file.tmp" "$file" + done + + if test -n "$(git status -s)"; then + echo " -> Adding automatic changes..." + git add -e -- doc + fi -if test -n "$(git status -s)"; then - echo " -> Adding automatic changes..." - git add -e -- doc -fi +fi # rc == 0 echo " -> Updating meta/HISTORY" line="# version $new [released on $date]" if test ! -e meta/HISTORY; then - cat >meta/HISTORY.tmp <<EOF + test $rc -eq 0 && cat >meta/HISTORY.tmp <<EOF # Current development - Nothing yet. @@ -93,7 +137,7 @@ EOF else exec 5>&1 >meta/HISTORY.tmp head -2 meta/HISTORY - cat <<EOF + test $rc -eq 0 && cat <<EOF - Nothing yet. $line @@ -101,15 +145,17 @@ $line EOF git log --reverse --no-decorate \ --format='- %s%n%w(,2,2)%+b%nThanks to %an <%ae>%n%n' \ - $(cat meta/version)..master \ + $ver..master \ | awk -vskip=0 '/Thanks to Olivier Brunel/ { skip=1; next } // { if (skip) { skip=0 } else { print } }' tail -n +3 meta/HISTORY exec 1>&5 5<&- fi -mv -f meta/HISTORY{.tmp,} -echo " -> Review updated HISTORY..." -${EDITOR:vim} meta/HISTORY +if test -e meta/HISTORY.tmp; then + mv -f meta/HISTORY{.tmp,} + echo " -> Review updated HISTORY..." + ${EDITOR:vim} meta/HISTORY +fi echo " -> Updating meta/version : $new" echo $new > meta/version @@ -121,12 +167,16 @@ echo " -> Commit changes..." git add meta/{version,released-on,HISTORY} git commit -m "Release version $new" -echo " -> Tag & fast-forward" -git checkout release -git merge --ff-only master +if test $rc -eq 0; then + echo " -> Tag & fast-forward release" + git checkout release + git merge --ff-only master +else + echo " -> Tag" +fi git tag -a $new -m "Release version $new -$(getchangelog)" +$(getchangelog $rc)" if test -n "$was_master"; then echo " -> Reset dev & rebase dev-wip..."