|
1 | 1 | # THIS SECTION OF THE CODE HANDLES THE PROCESS OF RELEASING. |
2 | 2 | # NOTE: you have to be on the correct branch to run this script and release. |
| 3 | + |
| 4 | +# Usage: ./release.sh <rc-number> |
| 5 | +# Example 1: ./release.sh 3 |
| 6 | +# - This will create a release branch (locally), update version numbers, commit, and tag the release as 0.3.0-rc3. |
| 7 | +# Example 2: ./release.sh 200-signed |
| 8 | +# - This will create a release branch (locally), update version numbers, commit, and tag the release as 0.3.0-rc200-signed. |
| 9 | +# - NOTE: The package.json and pyproject.toml files will be updated as "0.3.0-rc200". |
| 10 | + |
| 11 | +#!/bin/bash |
| 12 | +set -e # Exit on error |
| 13 | + |
| 14 | +# Always run from project root (one level up from script location) |
| 15 | +cd "$(dirname "$0")/.." |
| 16 | + |
| 17 | +echo "📁 Running from: $(pwd)" |
| 18 | + |
| 19 | +# Step 1: Get the RC number from user |
| 20 | +if [ -z "$1" ]; then |
| 21 | + echo "Usage: ./release.sh <rc-number> (e.g., ./release.sh 3)" |
| 22 | + exit 1 |
| 23 | +fi |
| 24 | + |
| 25 | +RC_VALUE=$1 |
| 26 | +VERSION="0.3.0-rc$RC_VALUE" |
| 27 | +BRANCH="release/030-rc$RC_VALUE" |
| 28 | + |
| 29 | +echo "🚀 Starting release for version $VERSION" |
| 30 | + |
| 31 | +# Step 2: Check if branch exists locally and delete if not currently checked out |
| 32 | +if git show-ref --quiet refs/heads/"$BRANCH"; then |
| 33 | + CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) |
| 34 | + if [ "$CURRENT_BRANCH" = "$BRANCH" ]; then |
| 35 | + echo "❌ Cannot delete the current branch '$BRANCH'. Please checkout another branch first." |
| 36 | + exit 1 |
| 37 | + else |
| 38 | + echo "🔁 Deleting existing local branch '$BRANCH'..." |
| 39 | + git branch -D "$BRANCH" |
| 40 | + fi |
| 41 | +fi |
| 42 | + |
| 43 | +# Step 3: Create and switch to the new branch |
| 44 | +git checkout -b "$BRANCH" |
| 45 | + |
| 46 | +# Step 4: Extract RC number for version fields (strip suffixes like -signed, -ea, -ga) |
| 47 | +RC_NUMBER=$(echo "$RC_VALUE" | sed -E 's/^([0-9]+).*/\1/') |
| 48 | +VERSION_FIELD="0.3.0-rc$RC_NUMBER" |
| 49 | + |
| 50 | +# Step 4: Update package.json |
| 51 | +if [ -f package.json ]; then |
| 52 | + echo "📝 Updating package.json version to $VERSION_FIELD..." |
| 53 | + jq ".version = \"$VERSION_FIELD\"" package.json > tmp.json && mv tmp.json package.json |
| 54 | +else |
| 55 | + echo "❌ package.json not found!" |
| 56 | + exit 1 |
| 57 | +fi |
| 58 | + |
| 59 | +# Step 5: Update pyproject.toml |
| 60 | +if [ -f pyproject.toml ]; then |
| 61 | + echo "📝 Updating pyproject.toml version to $VERSION_FIELD..." |
| 62 | + sed -i '' -E "s/^version = \".*\"/version = \"$VERSION_FIELD\"/" pyproject.toml |
| 63 | +else |
| 64 | + echo "❌ pyproject.toml not found!" |
| 65 | + exit 1 |
| 66 | +fi |
| 67 | + |
| 68 | +# Step 6: Commit changes locally |
| 69 | +git add package.json pyproject.toml |
| 70 | + |
| 71 | +if git diff --cached --quiet; then |
| 72 | + echo "ℹ️ Nothing to commit. Working tree clean." |
| 73 | +else |
| 74 | + git commit -m "chore: release $VERSION" |
| 75 | +fi |
| 76 | + |
| 77 | +# Step 7: Delete existing tag if it exists locally and remotely |
| 78 | +if git tag | grep -q "v$VERSION"; then |
| 79 | + echo "🔁 Deleting existing local tag 'v$VERSION'..." |
| 80 | + git tag -d "v$VERSION" |
| 81 | +fi |
| 82 | + |
| 83 | +if git ls-remote --tags origin | grep -q "refs/tags/v$VERSION"; then |
| 84 | + echo "🔁 Deleting existing remote tag 'v$VERSION'..." |
| 85 | + git push origin --delete "v$VERSION" |
| 86 | +fi |
| 87 | + |
| 88 | +# Step 8: Tag the release |
| 89 | +git tag "v$VERSION" |
| 90 | + |
| 91 | +# Step 9: Push the tag to remote |
| 92 | +git push origin "v$VERSION" |
| 93 | + |
| 94 | +echo "✅ Release $VERSION completed and tagged!" |
0 commit comments