veilidchat/version_bump.sh
Ethan Hindmarsh #YOLO #Ally.lol a1a6872e3f update version bump logic
2025-06-06 21:58:13 -05:00

73 lines
1.9 KiB
Bash
Executable file

#!/usr/bin/env bash
# Fail out if any step has an error
set -e
if [ "$1" == "patch" ]; then
echo Bumping patch version
PART=patch
elif [ "$1" == "minor" ]; then
echo Bumping minor version
PART=minor
elif [ "$1" == "major" ]; then
echo Bumping major version
PART=major
elif [ "$1" == "build" ]; then
echo Bumping build code
PART=build
else
echo Unsupported part! Specify 'build', 'patch', 'minor', or 'major'
exit 1
fi
# Function to increment the build code
increment_buildcode() {
local current_version=$1
local major_minor_patch=${current_version%+*}
local buildcode=${current_version#*+}
local new_buildcode=$((buildcode + 1))
echo "${major_minor_patch}+${new_buildcode}"
}
# Function to get the current version from pubspec.yaml
get_current_version() {
awk '/^version: / { print $2 }' pubspec.yaml
}
# Function to update the version in pubspec.yaml
update_version() {
local new_version=$1
if [[ "$OSTYPE" == "darwin"* ]]; then
SED_CMD="sed -i ''"
else
SED_CMD="sed -i"
fi
eval "$SED_CMD 's/version: .*/version: ${new_version}/' pubspec.yaml"
}
current_version=$(get_current_version)
echo "Current Version: $current_version"
if [ "$PART" == "build" ]; then
final_version=$(increment_buildcode $current_version)
else
# Bump the major, minor, or patch version using bump2version
bump2version --current-version $current_version $PART
new_version_base=$(get_current_version)
buildcode=${current_version#*+}
intermediate_version="${new_version_base%+*}+${buildcode}"
final_version=$(increment_buildcode $intermediate_version)
fi
# Update pubspec.yaml with the final version
update_version $final_version
# Print the final version
echo "New Version: $final_version"
#git add pubspec.yaml
#git commit -m "Bump version to $final_version"
#git tag "v$final_version"