|
| 1 | +#!/usr/bin/env bash |
| 2 | +# release.sh - Prepare and trigger a release |
| 3 | +# |
| 4 | +# Usage: ./scripts/release.sh <version> |
| 5 | +# |
| 6 | +# Examples: |
| 7 | +# ./scripts/release.sh 0.2.1 |
| 8 | +# ./scripts/release.sh 1.0.0 |
| 9 | + |
| 10 | +set -euo pipefail |
| 11 | + |
| 12 | +VERSION="${1:?Usage: ./scripts/release.sh <version>}" |
| 13 | +TAG="v$VERSION" |
| 14 | + |
| 15 | +# Ensure we're in the repo root |
| 16 | +cd "$(dirname "$0")/.." |
| 17 | + |
| 18 | +# Check if version already exists on npm |
| 19 | +echo "Checking if ansilust@$VERSION exists on npm..." |
| 20 | +if npm view "ansilust@$VERSION" --json &>/dev/null; then |
| 21 | + echo "Error: ansilust@$VERSION already exists on npm" |
| 22 | + exit 1 |
| 23 | +fi |
| 24 | + |
| 25 | +# Check for uncommitted changes |
| 26 | +if ! git diff --quiet || ! git diff --cached --quiet; then |
| 27 | + echo "Error: You have uncommitted changes. Please commit or stash them first." |
| 28 | + exit 1 |
| 29 | +fi |
| 30 | + |
| 31 | +# Delete existing tag if present (local and remote) |
| 32 | +if git tag -l "$TAG" | grep -q "$TAG"; then |
| 33 | + echo "Deleting existing local tag $TAG..." |
| 34 | + git tag -d "$TAG" |
| 35 | +fi |
| 36 | + |
| 37 | +if git ls-remote --tags origin | grep -q "refs/tags/$TAG"; then |
| 38 | + echo "Deleting existing remote tag $TAG..." |
| 39 | + git push origin ":refs/tags/$TAG" |
| 40 | +fi |
| 41 | + |
| 42 | +# Update version in packages/ansilust/package.json |
| 43 | +echo "Updating packages/ansilust/package.json to version $VERSION..." |
| 44 | +MAIN_PKG="packages/ansilust/package.json" |
| 45 | +sed -i "s/\"version\": \"[^\"]*\"/\"version\": \"$VERSION\"/" "$MAIN_PKG" |
| 46 | + |
| 47 | +# Update optionalDependencies versions |
| 48 | +sed -i "s/\"ansilust-\([^\"]*\)\": \"[^\"]*\"/\"ansilust-\1\": \"$VERSION\"/g" "$MAIN_PKG" |
| 49 | + |
| 50 | +# Commit the version bump |
| 51 | +echo "Committing version bump..." |
| 52 | +git add "$MAIN_PKG" |
| 53 | +git commit -m "chore: release v$VERSION" |
| 54 | + |
| 55 | +# Create and push tag |
| 56 | +echo "Creating tag $TAG..." |
| 57 | +git tag "$TAG" |
| 58 | + |
| 59 | +echo "Pushing changes and tag..." |
| 60 | +git push |
| 61 | +git push origin "$TAG" |
| 62 | + |
| 63 | +echo "" |
| 64 | +echo "Release $TAG triggered!" |
| 65 | +echo "Watch the workflow at: https://github.com/effect-native/ansilust/actions" |
0 commit comments