|
| 1 | +#!/bin/bash |
| 2 | +# Create a maintenance branch for an older major version of a package. |
| 3 | +# |
| 4 | +# Usage: scripts/create-maintenance-branch.sh <package-name> <major-version> |
| 5 | +# Example: scripts/create-maintenance-branch.sh apollo-react 3 |
| 6 | +# |
| 7 | +# This script: |
| 8 | +# 1. Finds the latest git tag for @uipath/<package>@<major>.* |
| 9 | +# 2. Creates release/<package>@<major>.x branch from that tag |
| 10 | +# 3. Updates the package's .releaserc.json with maintenance branch config |
| 11 | +# 4. Commits the config change |
| 12 | +# 5. Prints next steps (push, update main's .releaserc.json) |
| 13 | + |
| 14 | +set -euo pipefail |
| 15 | + |
| 16 | +PACKAGE="${1:?Usage: $0 <package-name> <major-version>}" |
| 17 | +MAJOR="${2:?Usage: $0 <package-name> <major-version>}" |
| 18 | + |
| 19 | +if ! [[ "$MAJOR" =~ ^[0-9]+$ ]]; then |
| 20 | + echo "Error: major version must be a number, got '$MAJOR'" |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | + |
| 24 | +TAG_PATTERN="@uipath/${PACKAGE}@${MAJOR}.*" |
| 25 | +BRANCH="release/${PACKAGE}@${MAJOR}.x" |
| 26 | +CHANNEL="release-${MAJOR}.x" |
| 27 | + |
| 28 | +# Find package directory |
| 29 | +if [ -d "packages/${PACKAGE}" ]; then |
| 30 | + RELEASERC="packages/${PACKAGE}/.releaserc.json" |
| 31 | +elif [ -d "web-packages/${PACKAGE}" ]; then |
| 32 | + RELEASERC="web-packages/${PACKAGE}/.releaserc.json" |
| 33 | +else |
| 34 | + echo "Error: package '${PACKAGE}' not found in packages/ or web-packages/" |
| 35 | + exit 1 |
| 36 | +fi |
| 37 | + |
| 38 | +# Find latest tag for this major version |
| 39 | +LATEST_TAG=$(git tag --list "${TAG_PATTERN}" --sort=-version:refname | head -1) |
| 40 | + |
| 41 | +if [ -z "$LATEST_TAG" ]; then |
| 42 | + echo "Error: no tags found matching '${TAG_PATTERN}'" |
| 43 | + echo "" |
| 44 | + echo "Available tags for @uipath/${PACKAGE}:" |
| 45 | + git tag --list "@uipath/${PACKAGE}@*" --sort=-version:refname | head -5 |
| 46 | + exit 1 |
| 47 | +fi |
| 48 | + |
| 49 | +echo "Latest tag: ${LATEST_TAG}" |
| 50 | +echo "Branch: ${BRANCH}" |
| 51 | +echo "Channel: ${CHANNEL}" |
| 52 | +echo "" |
| 53 | + |
| 54 | +# Check if branch already exists |
| 55 | +if git show-ref --verify --quiet "refs/heads/${BRANCH}" 2>/dev/null || \ |
| 56 | + git show-ref --verify --quiet "refs/remotes/origin/${BRANCH}" 2>/dev/null; then |
| 57 | + echo "Error: branch '${BRANCH}' already exists" |
| 58 | + exit 1 |
| 59 | +fi |
| 60 | + |
| 61 | +if ! command -v jq &> /dev/null; then |
| 62 | + echo "Error: jq is required. Install with: brew install jq" |
| 63 | + exit 1 |
| 64 | +fi |
| 65 | + |
| 66 | +# Create branch from tag |
| 67 | +git checkout -b "${BRANCH}" "${LATEST_TAG}" |
| 68 | + |
| 69 | +# Update .releaserc.json — add maintenance branch entry before "main" |
| 70 | +jq --arg name "${BRANCH}" \ |
| 71 | + --arg range "${MAJOR}.x" \ |
| 72 | + --arg channel "${CHANNEL}" \ |
| 73 | + '.branches = [{"name": $name, "range": $range, "channel": $channel}, "main"]' \ |
| 74 | + "${RELEASERC}" > "${RELEASERC}.tmp" && mv "${RELEASERC}.tmp" "${RELEASERC}" |
| 75 | + |
| 76 | +echo "✓ Updated ${RELEASERC}" |
| 77 | +echo "" |
| 78 | + |
| 79 | +# Commit the change |
| 80 | +git add "${RELEASERC}" |
| 81 | +git commit -m "ci(${PACKAGE}): configure maintenance branch for ${MAJOR}.x [skip ci]" |
| 82 | + |
| 83 | +echo "" |
| 84 | +echo "✓ Branch '${BRANCH}' created and configured" |
| 85 | +echo "" |
| 86 | +echo "Next steps:" |
| 87 | +echo "" |
| 88 | +echo " 1. Push the branch:" |
| 89 | +echo " git push -u origin '${BRANCH}'" |
| 90 | +echo "" |
| 91 | +echo " 2. On main, update ${RELEASERC} to add this entry" |
| 92 | +echo " BEFORE \"main\" in the branches array:" |
| 93 | +echo "" |
| 94 | +echo " {\"name\": \"${BRANCH}\", \"range\": \"${MAJOR}.x\", \"channel\": \"${CHANNEL}\"}" |
| 95 | +echo "" |
| 96 | +echo " Example .releaserc.json branches on main:" |
| 97 | +echo " \"branches\": [" |
| 98 | +echo " {\"name\": \"${BRANCH}\", \"range\": \"${MAJOR}.x\", \"channel\": \"${CHANNEL}\"}," |
| 99 | +echo " \"main\"" |
| 100 | +echo " ]" |
0 commit comments