Skip to content

Commit eab42b4

Browse files
committed
Enable --version flag, release script for automation
1 parent d8a6669 commit eab42b4

3 files changed

Lines changed: 104 additions & 16 deletions

File tree

README.md

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ hdi a All sections
6767

6868
```
6969
-h, --help Show help
70+
-v, --version Show version
7071
-f, --full Show surrounding prose, not just commands
7172
--raw Plain markdown output (no colour, for piping)
7273
--ni, --no-interactive Non-interactive (just print, no picker)
@@ -125,26 +126,16 @@ This outputs `demo.gif` from the tape file.
125126

126127
## Publishing a new release
127128

128-
1. Tag the release and push:
129+
The `release` script bumps the version in `hdi`, commits, tags, pushes, and prints the sha256 for the Homebrew tap:
129130

130131
```bash
131-
git tag v0.x.0
132-
git push origin --tags
132+
./release patch # 0.1.0 → 0.1.1
133+
./release minor # 0.1.0 → 0.2.0
134+
./release major # 0.1.0 → 1.0.0
135+
./release 1.2.3 # explicit version
133136
```
134137

135-
The `release` workflow will automatically build and publish a new release to GitHub when the tag is pushed.
136-
137-
2. Get the sha256 of the release tarball:
138-
139-
```bash
140-
curl -sL https://github.com/grega/hdi/archive/refs/tags/v0.x.0.tar.gz | shasum -a 256 | awk '{print $1}'
141-
```
142-
143-
3. Update the formula in the [homebrew-tap](https://github.com/grega/homebrew-tap) repo (`Formula/hdi.rb`):
144-
- Set `url` to the new tag's tarball URL
145-
- Set `sha256` to the value from step 2
146-
147-
4. Push the tap repo. Users can now get the update via `brew upgrade grega/tap/hdi`.
138+
The `release` workflow will automatically build and publish a GitHub release when the tag is pushed. The script then prints the `url` and `sha256` values to update in the [homebrew-tap](https://github.com/grega/homebrew-tap) repo (`hdi.rb`).
148139

149140
## License
150141

hdi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
set -euo pipefail
2424

25+
# ── Version ─────────────────────────────────────────────────────────────────
26+
VERSION="0.5.0"
27+
2528
# ── Defaults ─────────────────────────────────────────────────────────────────
2629
MODE="default"
2730
FULL=false
@@ -45,6 +48,10 @@ for arg in "$@"; do
4548
--full|-f) FULL=true ;;
4649
--raw) RAW=true; INTERACTIVE="no" ;;
4750
--no-interactive|--ni) INTERACTIVE="no" ;;
51+
--version|-v)
52+
echo "hdi $VERSION"
53+
exit 0
54+
;;
4855
--help|-h)
4956
sed -n '2,/^$/{ s/^# \{0,1\}//; p; }' "$0"
5057
exit 0

release

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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

Comments
 (0)