|
| 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 | +if [ ! -f "${RELEASERC}" ]; then |
| 39 | + echo "Error: release config '${RELEASERC}' not found for package '${PACKAGE}'" |
| 40 | + exit 1 |
| 41 | +fi |
| 42 | + |
| 43 | +# Find latest tag for this major version |
| 44 | +LATEST_TAG=$(git tag --list "${TAG_PATTERN}" --sort=-version:refname | head -1) |
| 45 | + |
| 46 | +if [ -z "$LATEST_TAG" ]; then |
| 47 | + echo "Error: no tags found matching '${TAG_PATTERN}'" |
| 48 | + echo "" |
| 49 | + echo "Available tags for @uipath/${PACKAGE}:" |
| 50 | + git tag --list "@uipath/${PACKAGE}@*" --sort=-version:refname | head -5 |
| 51 | + exit 1 |
| 52 | +fi |
| 53 | + |
| 54 | +echo "Latest tag: ${LATEST_TAG}" |
| 55 | +echo "Branch: ${BRANCH}" |
| 56 | +echo "Channel: ${CHANNEL}" |
| 57 | +echo "" |
| 58 | + |
| 59 | +# Check if branch already exists |
| 60 | +if git show-ref --verify --quiet "refs/heads/${BRANCH}" 2>/dev/null || \ |
| 61 | + git show-ref --verify --quiet "refs/remotes/origin/${BRANCH}" 2>/dev/null; then |
| 62 | + echo "Error: branch '${BRANCH}' already exists" |
| 63 | + exit 1 |
| 64 | +fi |
| 65 | + |
| 66 | +if ! command -v jq &> /dev/null; then |
| 67 | + echo "Error: jq is required. Please install jq using your package manager (e.g. 'brew install jq' on macOS) and try again." |
| 68 | + exit 1 |
| 69 | +fi |
| 70 | + |
| 71 | +# Create branch from tag |
| 72 | +git checkout -b "${BRANCH}" "${LATEST_TAG}" |
| 73 | + |
| 74 | +# Update .releaserc.json — insert the maintenance branch entry immediately before |
| 75 | +# "main", preserving order of all existing branches (other maintenance branches, |
| 76 | +# prereleases that come after main, etc.). If an entry for this branch already |
| 77 | +# exists, it's replaced in place. |
| 78 | +jq --arg name "${BRANCH}" \ |
| 79 | + --arg range "${MAJOR}.x" \ |
| 80 | + --arg channel "${CHANNEL}" \ |
| 81 | + ' |
| 82 | + .branches as $existing |
| 83 | + | { name: $name, range: $range, channel: $channel } as $entry |
| 84 | + | ($existing | map((type == "object" and .name == $name) or . == $name) | index(true)) as $existing_idx |
| 85 | + | ($existing | map((type == "object" and .name == "main") or . == "main") | index(true)) as $main_idx |
| 86 | + | if $existing_idx != null then |
| 87 | + .branches = ($existing | .[0:$existing_idx] + [$entry] + .[$existing_idx+1:]) |
| 88 | + elif $main_idx != null then |
| 89 | + .branches = ($existing | .[0:$main_idx] + [$entry] + .[$main_idx:]) |
| 90 | + else |
| 91 | + .branches = ($existing + [$entry]) |
| 92 | + end |
| 93 | + ' \ |
| 94 | + "${RELEASERC}" > "${RELEASERC}.tmp" && mv "${RELEASERC}.tmp" "${RELEASERC}" |
| 95 | + |
| 96 | +echo "✓ Updated ${RELEASERC}" |
| 97 | +echo "" |
| 98 | + |
| 99 | +# Commit the change |
| 100 | +git add "${RELEASERC}" |
| 101 | +git commit -m "ci(${PACKAGE}): configure maintenance branch for ${MAJOR}.x [skip ci]" |
| 102 | + |
| 103 | +echo "" |
| 104 | +echo "✓ Branch '${BRANCH}' created and configured" |
| 105 | +echo "" |
| 106 | +echo "Next steps:" |
| 107 | +echo "" |
| 108 | +echo " 1. Push the branch:" |
| 109 | +echo " git push -u origin '${BRANCH}'" |
| 110 | +echo "" |
| 111 | +echo " 2. On main, update ${RELEASERC} to add this entry" |
| 112 | +echo " BEFORE \"main\" in the branches array:" |
| 113 | +echo "" |
| 114 | +echo " {\"name\": \"${BRANCH}\", \"range\": \"${MAJOR}.x\", \"channel\": \"${CHANNEL}\"}" |
| 115 | +echo "" |
| 116 | +echo " Example .releaserc.json branches on main:" |
| 117 | +echo " \"branches\": [" |
| 118 | +echo " {\"name\": \"${BRANCH}\", \"range\": \"${MAJOR}.x\", \"channel\": \"${CHANNEL}\"}," |
| 119 | +echo " \"main\"" |
| 120 | +echo " ]" |
0 commit comments