Skip to content

Commit 423598b

Browse files
Merge pull request #44 from ben-kaufman/auto-bump-on-release
Auto bump version on release with build.sh
2 parents 9b80e2f + e22908a commit 423598b

File tree

2 files changed

+106
-3
lines changed

2 files changed

+106
-3
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,16 @@
451451
./build.sh python # Python only
452452
```
453453

454+
### Release Builds (with version bump)
455+
The `-r/--release` flag bumps versions in `Cargo.toml`, `Package.swift`, and `gradle.properties`, then builds.
456+
Defaults to patch version bump; use `--major`/`-M` or `--minor`/`-m` for other increments.
457+
458+
```
459+
./build.sh -r ios # Bump patch (default) and build iOS
460+
./build.sh -r --minor android # Bump minor and build Android
461+
./build.sh -r -M all # Bump major and build all platforms
462+
```
463+
454464
### Run examples
455465
```
456466
cargo run --bin example

build.sh

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,99 @@
11
#!/bin/bash
22

3-
# Save as build.sh
4-
case "$1" in
3+
bump_version() {
4+
local bump_type="$1"
5+
6+
# Read current version from Cargo.toml
7+
local current_version=$(grep '^version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
8+
9+
if [ -z "$current_version" ]; then
10+
echo "Error: Could not find version in Cargo.toml"
11+
exit 1
12+
fi
13+
14+
# Parse version into parts (x.y.z)
15+
IFS='.' read -ra VERSION_PARTS <<< "$current_version"
16+
local major="${VERSION_PARTS[0]}"
17+
local minor="${VERSION_PARTS[1]}"
18+
local patch="${VERSION_PARTS[2]}"
19+
20+
# Increment based on bump type
21+
case "$bump_type" in
22+
major)
23+
major=$((major + 1))
24+
minor=0
25+
patch=0
26+
;;
27+
minor)
28+
minor=$((minor + 1))
29+
patch=0
30+
;;
31+
patch)
32+
patch=$((patch + 1))
33+
;;
34+
*)
35+
echo "Error: Unknown bump type: $bump_type (must be major, minor, or patch)"
36+
exit 1
37+
;;
38+
esac
39+
40+
local new_version="${major}.${minor}.${patch}"
41+
42+
echo "Bumping $bump_type version from $current_version to $new_version"
43+
44+
# Update Cargo.toml
45+
sed -i '' "s/^version = \".*\"/version = \"$new_version\"/" Cargo.toml
46+
47+
# Update Package.swift
48+
sed -i '' "s/let tag = \"v.*\"/let tag = \"v$new_version\"/" Package.swift
49+
50+
# Update gradle.properties
51+
sed -i '' "s/^version=.*/version=$new_version/" bindings/android/gradle.properties
52+
53+
echo "Version bumped to $new_version in all files"
54+
}
55+
56+
BUILD_TARGET=""
57+
DO_RELEASE=false
58+
BUMP_TYPE="patch"
59+
60+
while [[ $# -gt 0 ]]; do
61+
case $1 in
62+
-r|--release)
63+
DO_RELEASE=true
64+
shift
65+
;;
66+
--major|-M)
67+
BUMP_TYPE="major"
68+
shift
69+
;;
70+
--minor|-m)
71+
BUMP_TYPE="minor"
72+
shift
73+
;;
74+
--patch|-p)
75+
BUMP_TYPE="patch"
76+
shift
77+
;;
78+
ios|android|python|all)
79+
BUILD_TARGET="$1"
80+
shift
81+
;;
82+
*)
83+
echo "Usage: $0 [-r|--release] [--major|-M|--minor|-m|--patch|-p] {ios|android|python|all}"
84+
echo " Version bump defaults to patch if --release is specified"
85+
exit 1
86+
;;
87+
esac
88+
done
89+
90+
# Bump version if release flag is set
91+
if [ "$DO_RELEASE" = true ]; then
92+
bump_version "$BUMP_TYPE"
93+
fi
94+
95+
# Build based on target
96+
case "$BUILD_TARGET" in
597
"ios")
698
./build_ios.sh
799
;;
@@ -15,7 +107,8 @@ case "$1" in
15107
./build_ios.sh && ./build_android.sh && ./build_python.sh
16108
;;
17109
*)
18-
echo "Usage: $0 {ios|android|python|all}"
110+
echo "Usage: $0 [-r|--release] [--major|-M|--minor|-m|--patch|-p] {ios|android|python|all}"
111+
echo " Version bump defaults to patch if --release is specified"
19112
exit 1
20113
;;
21114
esac

0 commit comments

Comments
 (0)