diff --git a/release.sh b/release.sh index 4428c49..9af5097 100755 --- a/release.sh +++ b/release.sh @@ -1,6 +1,21 @@ #!/bin/bash +set -euo pipefail -$REPO="laravel/stream" +REPO="laravel/stream" +BRANCH="main" + +# Ensure we are on correct branch and the working tree is clean +CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) +if [ "$CURRENT_BRANCH" != "$BRANCH" ]; then + echo "Error: must be on $BRANCH branch (current: $CURRENT_BRANCH)" >&2 + exit 1 +fi + +if [ -n "$(git status --porcelain)" ]; then + echo "Error: working tree is not clean. Commit or stash changes before releasing." >&2 + git status --porcelain + exit 1 +fi get_current_version() { local package_json=$1 @@ -51,16 +66,35 @@ fi git pull -echo "Starting package version management..." - -root_package_json="packages/react/package.json" -current_version=$(get_current_version "$root_package_json") +ROOT_PACKAGE_JSON="packages/react/package.json" +CURRENT_VERSION=$(get_current_version "$ROOT_PACKAGE_JSON") echo "" -echo "Current version: $current_version" +echo "Current version: $CURRENT_VERSION" echo "" -read -p "Update version? (patch/minor/major): " version_type -echo "" +echo "Select version bump type:" +echo "1) patch (bug fixes)" +echo "2) minor (new features)" +echo "3) major (breaking changes)" +echo + +read -p "Enter your choice (1-3): " choice + +case $choice in + 1) + RELEASE_TYPE="patch" + ;; + 2) + RELEASE_TYPE="minor" + ;; + 3) + RELEASE_TYPE="major" + ;; + *) + echo "❌ Invalid choice. Exiting." + exit 1 + ;; +esac for package_dir in packages/*; do if [ -d "$package_dir" ]; then @@ -68,7 +102,7 @@ for package_dir in packages/*; do cd $package_dir - update_version "$package_dir" "$version_type" + update_version "$package_dir" "$RELEASE_TYPE" cd ../.. @@ -76,7 +110,8 @@ for package_dir in packages/*; do fi done -new_version=$(get_current_version "$root_package_json") +NEW_VERSION=$(get_current_version "$ROOT_PACKAGE_JSON") +TAG="v$NEW_VERSION" echo "Updating lock file..." pnpm i @@ -86,13 +121,13 @@ echo "Staging package.json files..." git add "**/package.json" echo "" -git commit -m "$new_version" -git tag -a "$new_version" -m "$new_version" +git commit -m "$TAG" +git tag -a "$TAG" -m "$TAG" git push git push --tags -gh release create "$new_version" --generate-notes +gh release create "$TAG" --generate-notes --fail-on-no-commits echo "" -echo "✅ Release $new_version completed successfully, publishing kicked off in CI." -echo "🔗 https://github.com/$REPO/releases/tag/$new_version" +echo "✅ Release $TAG completed successfully, publishing kicked off in CI." +echo "🔗 https://github.com/$REPO/releases/tag/$TAG"