-
Notifications
You must be signed in to change notification settings - Fork 25
/
version_update.sh
executable file
·64 lines (48 loc) · 3.3 KB
/
version_update.sh
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
#!/bin/bash
# How to use: `./version_update.sh 0.8.0`
# How to test:
# - Use docker `docker run -it --rm -v $(pwd):/mnt/native_db ubuntu bash`
# - `/mnt/native_db`
# - `./version_update.sh 0.8.0`
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# Bash script to update version for native_db and native_db_macro
# Semantic release version obtained from argument
NEW_VERSION=$1
# Exit if NEW_VERSION is not set
if [ -z "$NEW_VERSION" ]; then
echo "NEW_VERSION argument not set"
exit 1
fi
# Directories containing Cargo.toml files to update
declare -a directories=("." "native_db_macro")
for directory in "${directories[@]}"
do
# Check if Cargo.toml and README.md exist
if [ -f "$directory/Cargo.toml" ] && [ -f "$directory/README.md" ]; then
echo "Updating version in $directory/Cargo.toml to $NEW_VERSION"
# Use sed to find and replace the version string in the Cargo.toml
sed -i -E "s/^version = \"[0-9]+\.[0-9]+\.[0-9]+\"/version = \"$NEW_VERSION\"/g" "$directory/Cargo.toml"
# Update the dependency version for native_db_macro in native_db's Cargo.toml
if [ "$directory" == "." ]; then
sed -i -E "s/native_db_macro = \{ version = \"[0-9]+\.[0-9]+\.[0-9]+\", path = \"native_db_macro\" \}/native_db_macro = { version = \"$NEW_VERSION\", path = \"native_db_macro\" }/g" "$directory/Cargo.toml"
# Extract native_model version from Cargo.toml
NATIVE_MODEL_VERSION=$(grep -oP '(?<=native_model = \{ version = ")[^"]*' "$directory/Cargo.toml")
echo "Updating native_model version in $directory/Cargo.toml to $NATIVE_MODEL_VERSION"
# Use sed to find and replace the version string in the README.md
sed -i -E "s/native_db = \"[0-9]+\.[0-9]+\.[0-9]+\"/native_db = \"$NEW_VERSION\"/g" "$directory/README.md"
sed -i -E "s/native_model = \"[0-9]+\.[0-9]+\.[0-9]+\"/native_model = \"$NATIVE_MODEL_VERSION\"/g" "$directory/README.md"
# Replace on src/metadata/current_version.rs: const CURRENT_VERSION: &str = "x.x.x";
sed -i -E "s/pub const CURRENT_VERSION: \&str = \"[0-9]+\.[0-9]+\.[0-9]+\";/pub const CURRENT_VERSION: \&str = \"$NEW_VERSION\";/g" "$directory/src/metadata/current_version.rs"
# Replace on src/metadata/current_native_model_version.rs: const CURRENT_NATIVE_MODEL_VERSION: &str = "x.x.x";
sed -i -E "s/pub const CURRENT_NATIVE_MODEL_VERSION: \&str = \"[0-9]+\.[0-9]+\.[0-9]+\";/pub const CURRENT_NATIVE_MODEL_VERSION: \&str = \"$NATIVE_MODEL_VERSION\";/g" "$directory/src/metadata/current_native_model_version.rs"
# Replace on tests/metadata/current_version.rs: assert_eq!(metadata.current_native_model_version(), "x.x.x");
sed -i -E "s/assert_eq!\(metadata.current_native_model_version(), \"[0-9]+\.[0-9]+\.[0-9]+\";/assert_eq!\(metadata.current_native_model_version(), \"$NATIVE_MODEL_VERSION\";/g" "$directory/tests/metadata/current_version.rs"
# Replace on tests/metadata/current_version.rs: assert_eq!(metadata.current_native_model_version(), Some("x.x.x"));
sed -i -E "s/assert_eq!\(metadata.current_native_model_version(), Some\(\"[0-9]+\.[0-9]+\.[0-9]+\";/assert_eq!\(metadata.current_native_model_version(), Some\(\"$NATIVE_MODEL_VERSION\";/g" "$directory/tests/metadata/current_version.rs"
fi
fi
done
cd "$DIR/"
# Commit
git commit --all --message "chore: update version to $NEW_VERSION"
git push