|
root / scripts / bump-version.sh
bump-version.sh Bash 87 lines 2.6 KB
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
#
# Bump the canonical Coral version.
#
# Usage: ./scripts/bump-version.sh <new-version>
#
# Rewrites in lock-step:
#   - reef.toml        (canonical; read by scripts/make-release.sh and CI)
#   - src/main.reef    (the fn version() runtime constant)
#
# Does NOT auto-commit or tag. Review with `hg diff`, then commit and tag
# by hand (see the printed instructions).
#
# Modeled on zyginit/scripts/bump-version.sh.
#

set -e

# This script uses GNU sed extensions (-i without backup suffix, 0,/addr/
# first-match range). Bumps are cut on a Linux dev host, not on Hammerhead;
# fail fast if invoked elsewhere so the breakage isn't a cryptic sed error.
case "$(uname -s)" in
    Linux) ;;
    *)
        echo "error: bump-version.sh requires GNU sed (Linux dev host)" >&2
        echo "       detected: $(uname -s)" >&2
        exit 1
        ;;
esac

if [ $# -ne 1 ]; then
    echo "usage: $0 <new-version>" >&2
    exit 1
fi

NEW="$1"

# Validate semver shape (no pre-release suffix).
echo "$NEW" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$' || {
    echo "error: '$NEW' is not in MAJOR.MINOR.PATCH form" >&2
    exit 1
}

SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
ROOT=$(dirname "$SCRIPT_DIR")
cd "$ROOT"

CURRENT=$(grep '^version' reef.toml | head -1 | sed 's/.*"\([^"]*\)".*/\1/')
if [ -z "$CURRENT" ]; then
    echo "error: could not read current version from reef.toml" >&2
    exit 1
fi

if [ "$CURRENT" = "$NEW" ]; then
    echo "error: version is already $NEW" >&2
    exit 1
fi

echo "coral: bumping $CURRENT -> $NEW"

# 1. reef.toml — rewrite the first 'version = "..."' (the [package] table).
# $NEW is safe inside the substitution: the semver regex above guarantees
# digits + dots only — no '/' or '&' to misinterpret.
echo "  rewriting reef.toml"
sed -i "0,/^version = \"[^\"]*\"/s//version = \"$NEW\"/" reef.toml

# 2. src/main.reef — rewrite the return inside `fn version()` only, so no
#    other string-returning function is touched.
echo "  rewriting src/main.reef (fn version)"
sed -i "/^fn version()/,/^end version/ s/return \"[^\"]*\"/return \"$NEW\"/" src/main.reef

# Sanity check: both sources now agree on $NEW.
TOML_V=$(grep '^version' reef.toml | head -1 | sed 's/.*"\([^"]*\)".*/\1/')
MAIN_V=$(sed -n '/^fn version()/,/^end version/ s/.*return "\([^"]*\)".*/\1/p' src/main.reef | head -1)
if [ "$TOML_V" != "$NEW" ] || [ "$MAIN_V" != "$NEW" ]; then
    echo "error: post-bump mismatch (reef.toml='$TOML_V', main.reef='$MAIN_V', expected '$NEW')" >&2
    exit 1
fi

echo
echo "summary of changes:"
hg diff --stat reef.toml src/main.reef || true
echo
echo "review with 'hg diff', then commit and tag:"
echo "  hg ci -m 'Bump version to $NEW'"
echo "  hg tag v$NEW"