hexabot/bump-version.sh

61 lines
1.4 KiB
Bash
Raw Normal View History

2024-12-10 10:47:04 +00:00
#!/bin/bash
# Ensure script exits on any command failure
set -e
# Check if a release type argument is provided
if [ -z "$1" ]; then
echo "Usage: $0 <release-type>"
echo "release-type: patch | minor"
exit 1
fi
RELEASE_TYPE=$1
ROOT_DIR=$(pwd)
if [[ "$RELEASE_TYPE" != "patch" && "$RELEASE_TYPE" != "minor" ]]; then
echo "Invalid release type. Use 'patch' or 'minor'."
exit 1
fi
echo "Executing release: $RELEASE_TYPE"
# Execute the appropriate npm release command
if [[ "$RELEASE_TYPE" == "patch" ]]; then
npm run release:patch
elif [[ "$RELEASE_TYPE" == "minor" ]]; then
npm run release:minor
fi
# Retrieve the new version from package.json
2024-12-10 11:39:49 +00:00
NEW_VERSION=$(jq -r '.version' "$ROOT_DIR/api/package.json")
2024-12-10 10:47:04 +00:00
if [ -z "$NEW_VERSION" ]; then
2024-12-10 11:39:49 +00:00
echo "Failed to retrieve the version from api/package.json."
2024-12-10 10:47:04 +00:00
exit 1
fi
2024-12-10 11:39:49 +00:00
# Function to update version in a package.json
update_version() {
local file=$1
echo "Updating version in $file to $NEW_VERSION"
jq --arg newVersion "$NEW_VERSION" '.version = $newVersion' "$file" > tmp.$$.json && mv tmp.$$.json "$file"
}
# Update root package.json
if [[ -f "$ROOT_DIR/package.json" ]]; then
update_version "$ROOT_DIR/package.json"
fi
2024-12-10 10:47:04 +00:00
# Commit and push changes
echo "Committing and pushing changes..."
git add .
git commit -m "build: v$NEW_VERSION"
# Add git tag
echo "Tagging version v$NEW_VERSION"
git tag "v$NEW_VERSION"
git push origin main --tags
echo "Release ($RELEASE_TYPE) completed successfully."