Skip to content

Commit 000a086

Browse files
committed
Add automated version bumping script
- Added scripts/bump-version.sh to streamline version updates across the repository. - The script updates Cargo.toml files, Cargo.lock, and the README.md with the provided version number. - Includes validation to ensure the new version follows semver conventions.
1 parent ee0fc9e commit 000a086

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

scripts/bump-version.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
NEW_VERSION="${1:-${NEW_VERSION:-${VERSION:-}}}"
5+
if [ -z "${NEW_VERSION}" ]; then
6+
echo "usage: make version NEW_VERSION=0.1.1" >&2
7+
exit 1
8+
fi
9+
10+
if ! [[ "${NEW_VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$ ]]; then
11+
echo "error: NEW_VERSION must look like semver (for example 0.1.1 or 1.0.0-rc.1)" >&2
12+
exit 1
13+
fi
14+
15+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16+
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
17+
cd "${REPO_ROOT}"
18+
19+
if ! command -v perl >/dev/null 2>&1; then
20+
echo "error: perl is required for version bump replacements" >&2
21+
exit 1
22+
fi
23+
24+
CURRENT_VERSION="$(awk -F '"' '/^version = "/ { print $2; exit }' trigrep-cli/Cargo.toml)"
25+
if [ -z "${CURRENT_VERSION}" ]; then
26+
echo "error: could not detect current version from trigrep-cli/Cargo.toml" >&2
27+
exit 1
28+
fi
29+
30+
if [ "${CURRENT_VERSION}" = "${NEW_VERSION}" ]; then
31+
echo "version is already ${NEW_VERSION}" >&2
32+
exit 0
33+
fi
34+
35+
export CURRENT_VERSION
36+
export NEW_VERSION
37+
38+
perl -i -pe 's/version = "\Q$ENV{CURRENT_VERSION}\E"/version = "$ENV{NEW_VERSION}"/g' \
39+
trigrep-cli/Cargo.toml \
40+
trigrep-index/Cargo.toml
41+
42+
perl -0777 -i -pe 's/(name = "trigrep-cli"\nversion = ")\Q$ENV{CURRENT_VERSION}\E(")/$1$ENV{NEW_VERSION}$2/; s/(name = "trigrep-index"\nversion = ")\Q$ENV{CURRENT_VERSION}\E(")/$1$ENV{NEW_VERSION}$2/;' \
43+
Cargo.lock
44+
45+
perl -i -pe 's/v\Q$ENV{CURRENT_VERSION}\E/v$ENV{NEW_VERSION}/g' README.md
46+
47+
echo "bumped version: ${CURRENT_VERSION} -> ${NEW_VERSION}" >&2
48+
echo "updated: trigrep-cli/Cargo.toml, trigrep-index/Cargo.toml, Cargo.lock, README.md" >&2

0 commit comments

Comments
 (0)