Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ dist/
.pnpm-debug.log

.claude/settings.json
.release-temp/
108 changes: 108 additions & 0 deletions scripts/finalize-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env bash
set -e

# Finalize release after PR merge
# Usage: ./scripts/finalize-release.sh [version]
# Example: ./scripts/finalize-release.sh v1.0.2

VERSION="${1}"
MAIN_BRANCH="${MAIN_BRANCH:-main}"

if [[ -z "$VERSION" ]]; then
# Try to read from saved state
if [[ -f .release-temp/pending-version ]]; then
VERSION=$(cat .release-temp/pending-version)
IS_PRERELEASE=$(cat .release-temp/is-prerelease)
echo "📦 Finalizing release: $VERSION"
else
echo "❌ Usage: ./scripts/finalize-release.sh [version]"
echo " Example: ./scripts/finalize-release.sh v1.0.2"
exit 1
fi
else
# Add 'v' prefix if not present
if [[ ! "$VERSION" =~ ^v ]]; then
VERSION="v$VERSION"
fi
IS_PRERELEASE=false
fi

# Check if gh CLI is installed
if ! command -v gh &> /dev/null; then
echo "❌ GitHub CLI (gh) is not installed."
exit 1
fi

# Ensure we're on main branch
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "$CURRENT_BRANCH" != "$MAIN_BRANCH" ]]; then
echo "⚠️ Not on $MAIN_BRANCH branch. Switching..."
git checkout "$MAIN_BRANCH"
fi

# Pull latest changes
echo "📥 Pulling latest merged changes..."
git pull

# Verify the version in package.json matches
PACKAGE_VERSION="v$(node -p "require('./package.json').version")"
if [[ "$PACKAGE_VERSION" != "$VERSION" ]]; then
echo "❌ Version mismatch!"
echo " Expected: $VERSION"
echo " package.json: $PACKAGE_VERSION"
echo ""
echo " Make sure the release PR has been merged."
exit 1
fi

# Get current commit
CURRENT_COMMIT=$(git rev-parse HEAD)
echo "📌 Tagging commit: $CURRENT_COMMIT"

# Create and push tag
echo "🏷️ Creating tag $VERSION..."
git tag -a "$VERSION" -m "Release $VERSION"
git push origin "$VERSION"

# Generate release notes
echo ""
echo "📝 Generating release notes..."

# Try to get previous tag
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")

if [[ -n "$PREVIOUS_TAG" ]]; then
COMPARE_LINK="https://github.com/waynebrantley/port-manager/compare/${PREVIOUS_TAG}...${VERSION}"
AUTO_NOTES="## What's Changed

Full changelog: $COMPARE_LINK"
else
AUTO_NOTES="Release $VERSION"
fi

# Create GitHub Release
echo "🎉 Creating GitHub Release..."

if [[ "$IS_PRERELEASE" == "true" ]]; then
gh release create "$VERSION" \
--title "$VERSION" \
--notes "$AUTO_NOTES" \
--prerelease
else
gh release create "$VERSION" \
--title "$VERSION" \
--notes "$AUTO_NOTES"
fi

# Clean up temp files
rm -rf .release-temp

echo ""
echo "✅ Release $VERSION finalized successfully!"
echo " 🏷️ Tag: $VERSION"
echo " 📦 npm package will be published automatically via GitHub Actions"
echo " 🔗 View release: https://github.com/waynebrantley/port-manager/releases/tag/$VERSION"
echo ""
echo "🔍 Monitor publish workflow:"
echo " https://github.com/waynebrantley/port-manager/actions"
echo ""
128 changes: 90 additions & 38 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ set -e
# Usage: ./scripts/release.sh [patch|minor|major|beta|alpha]

RELEASE_TYPE="${1:-patch}"
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
MAIN_BRANCH="${MAIN_BRANCH:-main}"

echo "🚀 Creating $RELEASE_TYPE release from branch: $CURRENT_BRANCH"
echo "🚀 Creating $RELEASE_TYPE release"
echo ""

# Check if gh CLI is installed
Expand All @@ -20,6 +20,9 @@ if ! command -v gh &> /dev/null; then
exit 1
fi

# Get current branch
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)

# Check if there are uncommitted changes
if [[ -n $(git status -s) ]]; then
echo "❌ You have uncommitted changes. Please commit or stash them first."
Expand All @@ -29,22 +32,33 @@ fi

# Ensure we're up to date
echo "📥 Pulling latest changes..."
git pull --rebase
git pull

# Run tests first
echo "🧪 Running tests..."
pnpm test

# Bump version and create tag
echo "📦 Bumping version..."
# Determine release type and validate branch
echo "📦 Preparing $RELEASE_TYPE release from branch: $CURRENT_BRANCH"
case "$RELEASE_TYPE" in
patch|minor|major)
# Stable releases must be from main branch
if [[ "$CURRENT_BRANCH" != "$MAIN_BRANCH" ]]; then
echo "❌ Stable releases must be from the $MAIN_BRANCH branch."
echo " Current branch: $CURRENT_BRANCH"
echo " For pre-releases from feature branches, use: beta or alpha"
exit 1
fi
NEW_VERSION=$(npm version $RELEASE_TYPE --no-git-tag-version)
IS_PRERELEASE=false
BASE_BRANCH="$MAIN_BRANCH"
;;
beta|alpha)
# Pre-releases can be from any branch
echo "💡 Creating pre-release from branch: $CURRENT_BRANCH"
NEW_VERSION=$(npm version prerelease --preid=$RELEASE_TYPE --no-git-tag-version)
IS_PRERELEASE=true
BASE_BRANCH="$CURRENT_BRANCH"
;;
*)
echo "❌ Invalid release type: $RELEASE_TYPE"
Expand All @@ -53,51 +67,89 @@ case "$RELEASE_TYPE" in
;;
esac

# Remove 'v' prefix from version for commit message
VERSION=${NEW_VERSION#v}

echo "📝 New version: $NEW_VERSION"

# Commit version change
# Commit version change on current branch
git add package.json
git commit -m "Release $NEW_VERSION"

# Create and push tag
git tag "$NEW_VERSION"
git push origin "$CURRENT_BRANCH"
git push origin "$NEW_VERSION"
# For stable releases from main, use PR workflow
if [[ "$IS_PRERELEASE" == "false" ]]; then
# Create release branch
RELEASE_BRANCH="release/$NEW_VERSION"
git checkout -b "$RELEASE_BRANCH"

# Generate release notes
echo ""
echo "📋 Enter release notes (press Ctrl+D when done):"
echo " (or leave empty for auto-generated notes)"
echo ""
# Push branch
echo "📤 Pushing release branch..."
git push -u origin "$RELEASE_BRANCH"

NOTES=$(cat)
# Create PR
echo "📋 Creating pull request..."
PR_BODY="Release $NEW_VERSION

if [[ -z "$NOTES" ]]; then
NOTES="Release $NEW_VERSION"
fi
## Changes
Version bump from release script.

# Create GitHub Release
echo ""
echo "🎉 Creating GitHub Release..."
## Post-merge
After this PR is merged, run \`./scripts/finalize-release.sh\` to create the tag and GitHub release."

if [[ "$IS_PRERELEASE" == "true" ]]; then
gh release create "$NEW_VERSION" \
--title "$NEW_VERSION" \
--notes "$NOTES" \
--prerelease \
--target "$CURRENT_BRANCH"
PR_URL=$(gh pr create \
--title "Release $NEW_VERSION" \
--body "$PR_BODY" \
--base "$MAIN_BRANCH" \
--head "$RELEASE_BRANCH")

echo ""
echo "✅ Release PR created: $PR_URL"
echo ""
echo "📋 Next steps:"
echo " 1. Wait for tests to pass"
echo " 2. Merge the PR (squash merge)"
echo " 3. Run: ./scripts/finalize-release.sh $NEW_VERSION"
echo ""

# Save release info for finalize script
mkdir -p .release-temp
echo "$NEW_VERSION" > .release-temp/pending-version
echo "$IS_PRERELEASE" > .release-temp/is-prerelease
echo "$PR_URL" > .release-temp/pr-url

echo "💡 Tip: The finalize script will create the tag and GitHub release after merge."
echo ""
else
# For pre-releases, create tag and release immediately
echo "📤 Pushing changes and creating release..."
git push origin "$CURRENT_BRANCH"

# Create and push tag
echo "🏷️ Creating tag $NEW_VERSION..."
git tag -a "$NEW_VERSION" -m "Release $NEW_VERSION"
git push origin "$NEW_VERSION"

# Create GitHub Release
echo "🎉 Creating GitHub pre-release..."

RELEASE_NOTES="Pre-release $NEW_VERSION from branch \`$CURRENT_BRANCH\`

## Installation
\`\`\`bash
npm install @wbrantley/port-manager@next
\`\`\`"

gh release create "$NEW_VERSION" \
--title "$NEW_VERSION" \
--notes "$NOTES" \
--notes "$RELEASE_NOTES" \
--prerelease \
--target "$CURRENT_BRANCH"
fi

echo ""
echo "✅ Release $NEW_VERSION created successfully!"
echo " 📦 npm package will be published automatically via GitHub Actions"
echo " 🔗 View release: https://github.com/waynebrantley/port-manager/releases/tag/$NEW_VERSION"
echo ""
echo ""
echo "✅ Pre-release $NEW_VERSION created successfully!"
echo " 🏷️ Tag: $NEW_VERSION"
echo " 🌿 Branch: $CURRENT_BRANCH"
echo " 📦 npm package will be published automatically via GitHub Actions"
echo " 🔗 View release: https://github.com/waynebrantley/port-manager/releases/tag/$NEW_VERSION"
echo ""
echo "🔍 Monitor publish workflow:"
echo " https://github.com/waynebrantley/port-manager/actions"
echo ""
fi