|
| 1 | +#!/usr/bin/env bash |
| 2 | +# release — bump version, tag, push, and print the sha256 for the Homebrew tap. |
| 3 | +# |
| 4 | +# Usage: |
| 5 | +# ./release 0.6.0 |
| 6 | +# ./release patch (0.5.0 → 0.5.1) |
| 7 | +# ./release minor (0.5.0 → 0.6.0) |
| 8 | +# ./release major (0.5.0 → 1.0.0) |
| 9 | + |
| 10 | +set -euo pipefail |
| 11 | + |
| 12 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 13 | +HDI="$SCRIPT_DIR/hdi" |
| 14 | + |
| 15 | +# ── Read current version ──────────────────────────────────────────────────── |
| 16 | + |
| 17 | +current=$(grep -m1 '^VERSION=' "$HDI" | sed 's/VERSION="//;s/"//') |
| 18 | + |
| 19 | +if [[ -z "$current" ]]; then |
| 20 | + echo "Error: could not read VERSION from hdi" >&2 |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | + |
| 24 | +# ── Resolve new version ───────────────────────────────────────────────────── |
| 25 | + |
| 26 | +if [[ -z "${1:-}" ]]; then |
| 27 | + echo "Usage: ./release <version|patch|minor|major>" >&2 |
| 28 | + echo "Current version: $current" >&2 |
| 29 | + exit 1 |
| 30 | +fi |
| 31 | + |
| 32 | +IFS='.' read -r major minor patch <<< "$current" |
| 33 | + |
| 34 | +case "$1" in |
| 35 | + patch) new="$major.$minor.$((patch + 1))" ;; |
| 36 | + minor) new="$major.$((minor + 1)).0" ;; |
| 37 | + major) new="$((major + 1)).0.0" ;; |
| 38 | + *) new="$1" ;; |
| 39 | +esac |
| 40 | + |
| 41 | +tag="v$new" |
| 42 | + |
| 43 | +# ── Safety checks ─────────────────────────────────────────────────────────── |
| 44 | + |
| 45 | +if [[ "$new" == "$current" ]]; then |
| 46 | + echo "Error: version is already $current" >&2 |
| 47 | + exit 1 |
| 48 | +fi |
| 49 | + |
| 50 | +if git tag -l "$tag" | grep -q .; then |
| 51 | + echo "Error: tag $tag already exists" >&2 |
| 52 | + exit 1 |
| 53 | +fi |
| 54 | + |
| 55 | +if [[ -n "$(git status --porcelain)" ]]; then |
| 56 | + echo "Error: working tree is not clean — commit or stash first" >&2 |
| 57 | + exit 1 |
| 58 | +fi |
| 59 | + |
| 60 | +# ── Bump, commit, tag, push ───────────────────────────────────────────────── |
| 61 | + |
| 62 | +echo "Releasing: $current → $new ($tag)" |
| 63 | + |
| 64 | +sed -i.bak "s/^VERSION=\"$current\"/VERSION=\"$new\"/" "$HDI" && rm -f "$HDI.bak" |
| 65 | +git add hdi |
| 66 | +git commit -m "Bump version to $new" |
| 67 | +git tag "$tag" |
| 68 | +git push origin HEAD --tags |
| 69 | + |
| 70 | +# ── Print sha256 for Homebrew tap ─────────────────────────────────────────── |
| 71 | + |
| 72 | +echo "" |
| 73 | +echo "Waiting for tarball to be available..." |
| 74 | +tarball_url="https://github.com/grega/hdi/archive/refs/tags/$tag.tar.gz" |
| 75 | + |
| 76 | +# Retry a few times — GitHub may take a moment after the push |
| 77 | +for i in 1 2 3 4 5; do |
| 78 | + sha=$(curl -sfL "$tarball_url" | shasum -a 256 | awk '{print $1}') |
| 79 | + if [[ -n "$sha" ]]; then |
| 80 | + echo "" |
| 81 | + echo "Update homebrew-tap Formula/hdi.rb:" |
| 82 | + echo " url \"$tarball_url\"" |
| 83 | + echo " sha256 \"$sha\"" |
| 84 | + exit 0 |
| 85 | + fi |
| 86 | + sleep 2 |
| 87 | +done |
| 88 | + |
| 89 | +echo "Warning: could not fetch tarball — check $tarball_url manually" >&2 |
| 90 | +exit 1 |
0 commit comments