Debian Codegraph @

tools/bump-version.sh

raw symbols SCIP
1 #!/bin/sh
2 # Bump the project version consistently across the three places that carry it:
3 # CMakeLists.txt -- the single source of truth (current version is read here)
4 # include/cgreen/cgreen.h -- the public CGREEN_VERSION* macros
5 # debian/control -- the packaging Version field
6 #
7 # Usage:
8 # tools/bump-version.sh X.Y.Z set an explicit version
9 # tools/bump-version.sh --patch increment patch (X.Y.Z -> X.Y.Z+1)
10 # tools/bump-version.sh --minor increment minor (X.Y.Z -> X.Y+1.0)
11 # tools/bump-version.sh --major increment major (X.Y.Z -> X+1.0.0)
12 #
13 # The version is propagated, nothing is committed or tagged -- review the diff,
14 # then commit and tag yourself.
15 set -eu
16
17 cd "$(dirname "$0")/.."
18
19 CMAKE=CMakeLists.txt
20 HEADER=include/cgreen/cgreen.h
21 CONTROL=debian/control
22
23 # Current version: the single source of truth is CMakeLists.txt (not the last
24 # git tag, so a bump works even before the previous one has been tagged).
25 cur_major=$(sed -n 's/^set(APPLICATION_VERSION_MAJOR "\([0-9]*\)").*/\1/p' "$CMAKE")
26 cur_minor=$(sed -n 's/^set(APPLICATION_VERSION_MINOR "\([0-9]*\)").*/\1/p' "$CMAKE")
27 cur_patch=$(sed -n 's/^set(APPLICATION_VERSION_PATCH "\([0-9]*\)").*/\1/p' "$CMAKE")
28 if [ -z "$cur_major" ] || [ -z "$cur_minor" ] || [ -z "$cur_patch" ]; then
29 echo "ERROR: could not read current version from $CMAKE" >&2
30 exit 1
31 fi
32
33 case "${1:-}" in
34 --patch) major=$cur_major; minor=$cur_minor; patch=$((cur_patch + 1)) ;;
35 --minor) major=$cur_major; minor=$((cur_minor + 1)); patch=0 ;;
36 --major) major=$((cur_major + 1)); minor=0; patch=0 ;;
37 [0-9]*.[0-9]*.[0-9]*)
38 major=${1%%.*}; rest=${1#*.}; minor=${rest%%.*}; patch=${rest#*.}
39 case "$patch" in
40 ''|*[!0-9]*) echo "ERROR: version must be X.Y.Z (digits only)" >&2; exit 1 ;;
41 esac ;;
42 *) echo "Usage: $0 X.Y.Z | --patch | --minor | --major" >&2; exit 1 ;;
43 esac
44
45 new="$major.$minor.$patch"
46 echo "Bumping $cur_major.$cur_minor.$cur_patch -> $new"
47
48 edit() { # edit <file> <sed-script>
49 sed -E "$2" "$1" > "$1.bump.tmp" && mv "$1.bump.tmp" "$1"
50 }
51
52 edit "$CMAKE" 's/(APPLICATION_VERSION_MAJOR ")[0-9]+(")/\1'"$major"'\2/;
53 s/(APPLICATION_VERSION_MINOR ")[0-9]+(")/\1'"$minor"'\2/;
54 s/(APPLICATION_VERSION_PATCH ")[0-9]+(")/\1'"$patch"'\2/'
55
56 edit "$HEADER" 's/(#define CGREEN_VERSION ")[0-9]+\.[0-9]+\.[0-9]+(")/\1'"$new"'\2/;
57 s/(#define CGREEN_VERSION_MAJOR )[0-9]+/\1'"$major"'/;
58 s/(#define CGREEN_VERSION_MINOR )[0-9]+/\1'"$minor"'/;
59 s/(#define CGREEN_VERSION_PATCH )[0-9]+/\1'"$patch"'/'
60
61 edit "$CONTROL" 's/^(Version: ).*/\1'"$new"'/'
62
63 echo "Updated:"
64 echo " $CMAKE:"; grep -E 'APPLICATION_VERSION_(MAJOR|MINOR|PATCH) "' "$CMAKE" | sed 's/^/ /'
65 echo " $HEADER:"; grep -E '#define CGREEN_VERSION' "$HEADER" | sed 's/^/ /'
66 echo " $CONTROL:"; grep -E '^Version:' "$CONTROL" | sed 's/^/ /'