]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Version and release scripting
authorMaria Matejka <mq@ucw.cz>
Mon, 14 Apr 2025 13:14:05 +0000 (15:14 +0200)
committerMaria Matejka <mq@ucw.cz>
Tue, 29 Apr 2025 18:28:28 +0000 (20:28 +0200)
Version number moved to a separate file as a primary source of truth.

Added tools/release-commit to make the release process a little bit faster.

Fixes #218

Makefile.in
VERSION [new file with mode: 0644]
doc/Makefile
doc/bird.sgml
tools/gendist
tools/make-archive
tools/release-commit [new file with mode: 0755]
tools/version

index b09d020364723d09d1bc0e301aaed0cc167246b1..321fe817ec94d5bd9755eae5fdf865905070ba5f 100644 (file)
@@ -43,7 +43,9 @@ objdir := @objdir@
 exedir := @exedir@
 
 # Find out which version we are actually building
+# This is rewritten by the release tools by hardcoded version
 VERSION := $(strip $(shell bash $(srcdir)/tools/version))
+
 CFLAGS += -DBIRD_VERSION='"$(VERSION)"'
 
 ifeq ($(objdir),.)
diff --git a/VERSION b/VERSION
new file mode 100644 (file)
index 0000000..5c6fb54
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+2.17
index c176488774706aaf1070cbf9f488b20026fe7056..5a0679b9cf62dde7ac42c513bbcad3931ddd6dd5 100644 (file)
@@ -20,18 +20,18 @@ $(o)prog.sgml: $(srcdir)/tools/progdoc $(objdir)/.dir-stamp
        $(srcdir)/tools/progdoc $(srcdir) $@
 
 $(o)%.sgml: $(s)%.sgml $(objdir)/.dir-stamp
-       cp $< $@
+       sed 's#{{ VERSION }}#$(VERSION)#' <$< >$@
 
 $(o)%.html: $(o)%.sgml
        cd $(dir $@) && $(toolsdir)/linuxdoc -B html $(notdir $<)
 
 ifeq ($(PANDOC),)
-$(o)%.md: $(s)%.sgml
+$(o)%.md: $(o)%.sgml
        @echo "ERROR: No pandoc available, install pandoc to build documentation"
        @false
 else
 LINUXDOC_PANDOC_PARSER := $(srcdir)/tools/linuxdoc.lua
-$(o)%.md: $(s)%.sgml $(LINUXDOC_PANDOC_PARSER) $(objdir)/.dir-stamp
+$(o)%.md: $(o)%.sgml $(LINUXDOC_PANDOC_PARSER) $(objdir)/.dir-stamp
        $(PANDOC) -f $(LINUXDOC_PANDOC_PARSER) -s -t markdown -o $@ $<
 
 $(o)%-singlepage.html: $(o)%.md
index d33c7b34c94a722cc3e9d2c8a06a2497a1888ef4..3b35adffb32f3087a1dc1341b6b563e7c3812a7b 100644 (file)
@@ -1,7 +1,7 @@
 <!doctype birddoc system>
 
 <!--
-       BIRD 2.17 documentation
+       BIRD documentation
 
 This documentation can have 4 forms: sgml (this is master copy), html, ASCII
 text and dvi/postscript (generated from sgml using sgmltools). You should always
@@ -20,7 +20,7 @@ configuration - something in config which is not keyword.
 
 <book>
 
-<title>BIRD 2.17 User's Guide
+<title>BIRD {{ VERSION }} User's Guide
 <author>
 Ondrej Filip <it/&lt;feela@network.cz&gt;/,
 Martin Mares <it/&lt;mj@ucw.cz&gt;/,
index 2caa11696c637aeb7a525ba978f911a3d91c2915..7cb19e03929be5578a36407d3478634f24705062 100755 (executable)
@@ -6,7 +6,7 @@
 #
 
 #VERSION=`grep 'BIRD_VERSION \"' sysdep/config.h | sed '/BIRD_VERSION/!d;s/^.*"\(.*\)"$/\1/'`
-VERSION=`tools/version | sed 's/^v//'`
+VERSION=`tools/version`
 REL=bird-$VERSION
 DREL=bird-doc-$VERSION
 T=/tmp/bird
index 1b3f0df5eb721bb3f1af572dd2607cb67f4e8f60..2f07c3c14bb2c8b01e2d03fd5902dbd1703ba800 100755 (executable)
@@ -47,7 +47,7 @@ pushd $T
   pushd $SRCPKG
 
     # Omit historical documents
-    rm -rf misc rfc doc/slides doc/slt2001 doc/old bird.conf
+    rm -rf rfc doc/slides doc/slt2001 doc/old bird.conf
 
     # Fix the version string
     sed -i 's/^VERSION := .*/VERSION := '${VERSION}'/' Makefile.in
diff --git a/tools/release-commit b/tools/release-commit
new file mode 100755 (executable)
index 0000000..49667c2
--- /dev/null
@@ -0,0 +1,84 @@
+#!/bin/bash
+
+set -e
+
+toplevel=$(readlink -f $(dirname $0)/..)
+current_version=$(<$toplevel/VERSION)
+
+pushd $toplevel > /dev/null
+
+# Enforce clean repository (we are going to commit!)
+if [ $(git status --porcelain -uno | wc -l) != "0" ]; then
+  echo "Dirty repository, commit or stash!"
+  exit 1
+fi
+
+# Enforce no fixups and no WIPs
+tools/git-check-commits
+
+# Compute the new version
+case $1 in
+  patch)
+    new_version=$(awk -F. 'OFS="." { $3+=1; print; }' <<<"$current_version")
+    ;;
+  minor)
+    new_version=$(awk -F. 'OFS="." { $2+=1; if ($1 < 3) print $1,$2; else print $1,$2,0; }' <<<"$current_version")
+    ;;
+  *)
+    echo "Usage: $0 (minor|patch)"
+    echo "Commits the version update commit"
+    exit 2
+esac
+
+file=$(mktemp)
+news=$(mktemp)
+function cleanup() {
+  rm -f $file $news
+}
+trap cleanup EXIT ERR
+
+# Prepare the NEWS file
+echo "## Releasing version $new_version ##" >> $file
+echo -n "########################" >> $file
+sed 's/./#/g' <<<"$new_version" >> $file
+echo >> $file
+news_headline="Version $new_version ($(date +%F))"
+echo $news_headline >> $file
+git log --oneline v$current_version..HEAD | sed -r 's/^([^ ]+) (.*)/# commit \1\n  o \2/' >> $file
+echo >> $file
+echo "# Empty the file to cancel the commit." >> $file
+echo "# Do not change the Version header." >> $file
+
+# Edit the NEWS file
+$(git var GIT_EDITOR) $file
+
+# Collect the result
+if ! egrep -v '^(#.*)?$' $file > $news; then
+  echo "Release canceled"
+  exit 1
+fi
+
+# Check whether the result is correct
+if [ "$news_headline" != "$(head -n1 $news)" ]; then
+  echo "Garbled headline, got $(head -n1 $news)"
+  exit 1
+fi
+
+badlines=$(tail -n+2 $news | grep -v '^  [o ] ' | wc -l)
+if [ "$badlines" != 0 ]; then
+  echo "Garbled news file, offending lines:"
+  tail -n+2 $news | grep -v '^  [o ] '
+  exit 1
+fi
+
+# Do the changes in the repository: NEWS, bird.spec and VERSION
+echo >> $news
+cat NEWS >> $news
+mv $news NEWS
+
+sed -i "s/^Version: $current_version\$/Version: $new_version/" misc/bird.spec
+
+echo $new_version > VERSION
+
+# Commit!
+git commit -m "NEWS and version update" -- NEWS VERSION misc/bird.spec
index d8e14821d95a6ae9985f85962ad7424517a4131f..6e591e34b854a906d0b607b3f0d4bb9c1457415c 100755 (executable)
@@ -1,21 +1,49 @@
-#!/bin/bash
+#!/bin/sh
 
-# Aren't we directly at version?
-TAG=$(git tag | grep -F $(git describe))
-if [ -n "$TAG" ]; then
-  echo $TAG
+set -e
+
+# Get the release version
+toplevel="$(readlink -f $(dirname $0)/../)"
+RELEASE_VERSION=$(cat "$toplevel/VERSION")
+
+# Not in a git repo, or no git installed.
+if ! git status --porcelain > /dev/null; then
+  echo $RELEASE_VERSION
+  exit 0
+fi
+
+# Check VERSION file updates in uncommitted changes
+if git status --porcelain | grep -q '^...VERSION$'; then
+  echo "WARNING: Version file changed and not committed" >&2
+  echo $RELEASE_VERSION
   exit 0
 fi
 
-# Get version tag
-# Uses 'git log ...' insted of 'git tag --merged' to support older distros
-TAG=$(git log --oneline --pretty=format:"%d" \
-    | grep -Eo '^ \(tag:\ v[[:digit:]]+.*(,|\))' \
-    | head -n 1 \
-    | sed -n 's/^ (tag:\ v//p' | sed -n 's/\(,.*\|)\)//p')
+# If clean, check VERSION file updates in the current commit
+if [ $(git status --porcelain -uno | wc -l) = "0" ] && [ $(git show -- VERSION | wc -l) != "0" ]; then
+  echo $RELEASE_VERSION
+  exit 0
+fi
 
+# We'll create a development version number, get the hash
 HASH=$(git rev-parse --short=12 HEAD)
 
+# Find the release
+case "$(git tag -l | grep "^v$RELEASE_VERSION\$" | wc -l | sed -r 's/^ *//;s/ +-//')" in
+  "1") # Already tagged
+    RELEASE_COMMIT=v$RELEASE_VERSION
+    ;;
+  "0") # Not yet tagged
+    RELEASE_COMMIT=$(git log --oneline -- VERSION | sed 's/ .*//')
+    ;;
+  *)
+    echo "ERROR: There are too many matching tags in the repository"
+    git tag -l | grep "^v$RELEASE_VERSION\$"
+    git tag -l | grep "^v$RELEASE_VERSION\$" | wc -l
+    exit 1
+    ;;
+esac
+
 # Add branch info if not passed via command line
 if [ -z "${BRANCH}" ]; then
   # There is also --show-current but it's too new to be portable.
@@ -24,10 +52,10 @@ fi
 
 # Found a branch
 if [ -n "$BRANCH" ]; then
-  LENGTH=$(git log --oneline v$TAG..HEAD | wc -l)
-  echo $TAG+branch.$(echo $BRANCH | sed 's/[^a-zA-Z0-9]/./g').${HASH}
+  LENGTH=$(git log --oneline $RELEASE_COMMIT..HEAD | wc -l)
+  echo $RELEASE_VERSION+branch.$(echo $BRANCH | sed 's/[^a-zA-Z0-9]/./g').${HASH}
   exit 0
 fi
 
-echo $TAG+detached.${HASH}
+echo $RELEASE_VERSION+detached.${HASH}
 exit 0