Skip to content
Closed
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
169 changes: 169 additions & 0 deletions scripts/create-release-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
#!/usr/bin/env bash
# Creates a release PR using Lerna conventional commits
# Publishing happens automatically when PR is merged via GitHub Actions
#
# β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
# β”‚ RELEASE PR WORKFLOW β”‚
# β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
#
# Developer (master)
# β”‚
# β”œβ”€ 1. PRE-FLIGHT CHECKS ──────────────────────────────────┐
# β”‚ β€’ On master branch? β”‚
# β”‚ β€’ Working directory clean? β”‚
# β”‚ β”‚
# β”œβ”€ 2. SYNC & BRANCH ───────────────────────────────────────
# β”‚ β€’ git pull origin master β”‚
# β”‚ β€’ git checkout -b release/pending-TIMESTAMP β”‚
# β”‚ β”‚
# β”œβ”€ 3. INSTALL & VERSION ───────────────────────────────────
# β”‚ β€’ yarn install --frozen-lockfile β”‚
# β”‚ β€’ lerna version --conventional-commits β”‚
# β”‚ β”Œβ”€ Analyzes commits since last git tag: β”‚
# β”‚ β”‚ - feat: β†’ MINOR bump (1.0.0 β†’ 1.1.0) β”‚
# β”‚ β”‚ - fix: β†’ PATCH bump (1.0.0 β†’ 1.0.1) β”‚
# β”‚ β”‚ - BREAKING CHANGE: β†’ MAJOR (1.0.0 β†’ 2.0.0) β”‚
# β”‚ β”‚ - chore/docs/etc β†’ No version change β”‚
# β”‚ β”œβ”€ For each changed package: β”‚
# β”‚ β”‚ β€’ Updates package.json version β”‚
# β”‚ β”‚ β€’ Generates/updates CHANGELOG.md β”‚
# β”‚ └─ Updates lerna.json with new version β”‚
# β”‚ β€’ Extract version from lerna.json β†’ NEW_VERSION β”‚
# β”‚ β”‚
# β”œβ”€ 4. COMMIT & RENAME ─────────────────────────────────────
# β”‚ β€’ git commit -m "chore(release): publish X.X.X" β”‚
# β”‚ β€’ git branch -m release/X.X.X β”‚
# β”‚ β”‚
# β”œβ”€ 5. PUSH TO GITHUB ──────────────────────────────────────
# β”‚ β€’ git push origin release/X.X.X β”‚
# β”‚ β”‚
# └─ 6. SWITCH BACK β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
# β€’ git checkout master
#
# Next Steps (Manual):
# β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
# β”‚ 1. Create PR: release/X.X.X β†’ master β”‚
# β”‚ 2. Review changes (version bumps, changelog) β”‚
# β”‚ 3. Merge PR β”‚
# β”‚ └─> Triggers GitHub Actions: .github/workflows/publish.yml β”‚
# β”‚ β€’ Publishes to npm (company service account) β”‚
# β”‚ β€’ Creates git tags β”‚
# β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
#

set -e

echo "πŸš€ ZCLI Release PR Creator"
echo "================================"
echo ""

# Pre-flight checks
if [[ "$(git branch --show-current)" != "master" ]]; then
printf '❌ Error: Please run this from master branch\n'
exit 1
fi

if [[ -n $(git status --porcelain) ]]; then
printf '❌ Error: You have uncommitted changes. Please commit or stash them first.\n'
exit 1
fi

echo 'πŸ”„ Pulling latest changes from master...'
git pull origin master

echo '🌿 Creating temporary release branch...'
# Create temporary branch - will be renamed after version is determined
TEMP_BRANCH="release/pending-$(date +%Y%m%d-%H%M%S)"
git checkout -b "$TEMP_BRANCH"

echo 'πŸ“¦ Installing dependencies...'
yarn install --frozen-lockfile

echo ''
echo 'πŸ“ Analyzing commits and determining version bump...'
echo ' (using conventional commits since last release)'
echo ''

# Run lerna version without git operations
# This will:
# - Analyze commits since last tag
# - Determine version bump (major/minor/patch)
# - Update package.json files
# - Update lerna.json
# - Generate CHANGELOG.md files
# Note: We use --no-git-tag-version to prevent tag creation
# Tags will be created when PR is merged to master
npx lerna version \
--conventional-commits \
--no-git-tag-version \
--yes \
--preid 'beta'

if [ $? -ne 0 ]; then
echo ''
echo '❌ Lerna version failed. Cleaning up...'
git checkout master
git branch -D "$TEMP_BRANCH" 2>/dev/null || true
exit 1
fi

# Get the new version
NEW_VERSION=$(jq -r '.version' lerna.json)

if [ -z "$NEW_VERSION" ] || [ "$NEW_VERSION" = "null" ]; then
echo ''
echo '❌ Could not determine new version. Cleaning up...'
git checkout master
git branch -D "$TEMP_BRANCH" 2>/dev/null || true
exit 1
fi

# Commit the version changes
echo ''
echo "βœ… Version bumped to: $NEW_VERSION"
echo 'πŸ“ Committing version changes...'
git add .
git commit -m "chore(release): publish $NEW_VERSION"

# Rename branch to use the actual version
RELEASE_BRANCH="release/$NEW_VERSION"
echo "πŸ”„ Renaming branch to: $RELEASE_BRANCH"
git branch -m "$RELEASE_BRANCH"
echo ''

# Get list of changed packages
echo 'πŸ“¦ Packages to be published:'
npx lerna changed --json 2>/dev/null | jq -r '.[].name' | sed 's/^/ - /'
echo ''

# Push branch only
echo '⬆️ Pushing branch to GitHub...'
git push origin "$RELEASE_BRANCH"

if [ $? -ne 0 ]; then
echo ''
echo '❌ Failed to push to GitHub. Please check your permissions.'
exit 1
fi

echo ''
echo '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
echo 'πŸŽ‰ Release branch created successfully!'
echo '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
echo ''
echo "πŸ“‹ Version: $NEW_VERSION"
echo "🌿 Branch: $RELEASE_BRANCH"
echo ''
echo 'Next steps:'
echo '1. Open a PR: https://github.com/zendesk/zcli/compare/'$RELEASE_BRANCH'?expand=1'
echo '2. Review the version bumps and changelog'
echo '3. Merge the PR to trigger automated publishing'
echo ''
echo '⚠️ Publishing to npm will happen automatically when PR is merged!'
echo ' Git tags will be created automatically during the merge process.'
echo ''

# Switch back to master branch
echo 'πŸ”„ Switching back to master branch...'
git checkout master
echo ''
Loading