forked from cyrus-and/zizzania
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·147 lines (118 loc) · 4.99 KB
/
Copy pathrelease.sh
File metadata and controls
executable file
·147 lines (118 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env bash
# release.sh — bump version, tag, compute SHA256, update Homebrew formula
#
# Usage: ./release.sh <version>
# Example: ./release.sh 0.10.0
#
# Assumes:
# - All code changes and CHANGES file are committed and on master
# - Working tree is clean
# - Remote is 'origin'
# - Tap repo lives at TAP_DIR (default: sibling directory homebrew-airsnare)
set -euo pipefail
VERSION="${1:?Usage: $0 <version>}"
TAG="v${VERSION}"
YEAR=$(date +%Y)
REPO_URL="https://github.com/rtulke/airsnare"
TARBALL_URL="${REPO_URL}/archive/refs/tags/${TAG}.tar.gz"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TAP_DIR="${TAP_DIR:-${SCRIPT_DIR}/../homebrew-airsnare}"
# -----------------------------------------------------------------------
# Preflight checks
# -----------------------------------------------------------------------
if [[ -n "$(git status --porcelain)" ]]; then
echo "Error: working tree is dirty — commit or stash changes first." >&2
exit 1
fi
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "${CURRENT_BRANCH}" != "master" ]]; then
echo "Error: not on master (currently on '${CURRENT_BRANCH}')." >&2
exit 1
fi
if git rev-parse "${TAG}" >/dev/null 2>&1; then
echo "Error: tag ${TAG} already exists." >&2
exit 1
fi
if [[ ! -d "${TAP_DIR}/.git" ]]; then
echo "Error: tap repo not found at '${TAP_DIR}'." >&2
echo " Clone or create it first, or set TAP_DIR=/path/to/homebrew-airsnare" >&2
exit 1
fi
if [[ -n "$(git -C "${TAP_DIR}" status --porcelain)" ]]; then
echo "Error: tap repo at '${TAP_DIR}' has uncommitted changes." >&2
exit 1
fi
# -----------------------------------------------------------------------
# 1. Update src/release.h
# -----------------------------------------------------------------------
echo "→ Updating src/release.h (version=${VERSION}, year=${YEAR})"
sed -i '' "s/#define ZZ_VERSION \"[^\"]*\"/#define ZZ_VERSION \"${VERSION}\"/" src/release.h
sed -i '' "s/#define ZZ_YEAR \"[^\"]*\"/#define ZZ_YEAR \"${YEAR}\"/" src/release.h
# -----------------------------------------------------------------------
# 2. Commit version bump
# -----------------------------------------------------------------------
git add src/release.h
git commit -m "Bump version to ${VERSION}"
# -----------------------------------------------------------------------
# 3. Create tag and push branch + tag
# -----------------------------------------------------------------------
echo "→ Creating tag ${TAG} and pushing"
git tag "${TAG}"
git push origin master "${TAG}"
# -----------------------------------------------------------------------
# 4. Compute SHA256 (retry until GitHub serves the tarball)
# -----------------------------------------------------------------------
echo "→ Waiting for GitHub tarball (up to 60 s)..."
SHA256=""
TMPFILE=$(mktemp)
for i in $(seq 1 12); do
if curl -sfL -o "${TMPFILE}" "${TARBALL_URL}"; then
SHA256=$(shasum -a 256 "${TMPFILE}" | awk '{print $1}')
break
fi
echo " attempt ${i}/12 — not yet available, retrying in 5 s..."
sleep 5
done
rm -f "${TMPFILE}"
if [[ -z "${SHA256}" ]]; then
echo "" >&2
echo "Error: could not download tarball after 12 attempts." >&2
echo "Compute SHA256 manually and update Formula/airsnare.rb:" >&2
echo " curl -sL ${TARBALL_URL} | shasum -a 256" >&2
exit 1
fi
echo " SHA256: ${SHA256}"
# -----------------------------------------------------------------------
# 5. Update Homebrew formula
# -----------------------------------------------------------------------
echo "→ Updating Formula/airsnare.rb"
sed -i '' "s|url \"[^\"]*\"|url \"${TARBALL_URL}\"|" Formula/airsnare.rb
sed -i '' "s|sha256 \"[^\"]*\"|sha256 \"${SHA256}\"|" Formula/airsnare.rb
# -----------------------------------------------------------------------
# 6. Commit and push updated formula
# -----------------------------------------------------------------------
git add Formula/airsnare.rb
git commit -m "Formula: update to ${TAG}"
git push origin master
# -----------------------------------------------------------------------
# 7. Update homebrew-airsnare tap repo
# -----------------------------------------------------------------------
echo "→ Updating tap repo at ${TAP_DIR}"
sed -i '' "s|url \"[^\"]*\"|url \"${TARBALL_URL}\"|" "${TAP_DIR}/Formula/airsnare.rb"
sed -i '' "s|sha256 \"[^\"]*\"|sha256 \"${SHA256}\"|" "${TAP_DIR}/Formula/airsnare.rb"
git -C "${TAP_DIR}" add Formula/airsnare.rb
git -C "${TAP_DIR}" commit -m "Update to ${TAG}"
git -C "${TAP_DIR}" push origin master
# -----------------------------------------------------------------------
echo ""
echo "✓ Release ${TAG} complete."
echo ""
echo " Main repo : ${REPO_URL}"
echo " Tap repo : $(git -C "${TAP_DIR}" remote get-url origin 2>/dev/null || echo "${TAP_DIR}")"
echo ""
echo "Install / upgrade with:"
echo " brew tap rtulke/airsnare"
echo " brew install rtulke/airsnare/airsnare"
echo ""
echo "Or to upgrade an existing install:"
echo " brew update && brew upgrade airsnare"