-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·324 lines (253 loc) · 9.91 KB
/
Copy pathrelease.sh
File metadata and controls
executable file
·324 lines (253 loc) · 9.91 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#!/usr/bin/env bash
set -euo pipefail
# DriveWipe Local Release Script
# Auto-detects platform, builds release binaries, creates a version tag,
# and uploads to GitHub Releases via the `gh` CLI.
#
# Usage:
# ./release.sh # auto-detect bump, create new release
# ./release.sh patch # force patch bump (0.1.5 -> 0.1.6)
# ./release.sh minor # force minor bump (0.1.5 -> 0.2.0)
# ./release.sh major # force major bump (0.1.5 -> 1.0.0)
# ./release.sh 1.0.0 # set exact version, create new release
# ./release.sh --attach v1.0.0 # build for THIS platform and attach to existing release
#
# The --attach flag is for multi-platform releases:
# 1. Run `./release.sh 1.0.0` on your Mac to create the release
# 2. Run `./release.sh --attach v1.0.0` on your Windows desktop to add Windows binaries
# 3. Run `./release.sh --attach v1.0.0` on a Linux box to add Linux binaries
#
# Requirements: cargo, gh (GitHub CLI, authenticated), git
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT_DIR"
# ── Helpers ─────────────────────────────────────────────────────────────────
die() { echo "ERROR: $*" >&2; exit 1; }
check_tool() {
command -v "$1" &>/dev/null || die "'$1' is required but not found. Install it first."
}
get_current_version() {
grep '^version' crates/drivewipe-core/Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/'
}
bump_version() {
local cur="$1" kind="$2"
local major minor patch
IFS='.' read -r major minor patch <<< "$cur"
case "$kind" in
major) echo "$((major + 1)).0.0" ;;
minor) echo "${major}.$((minor + 1)).0" ;;
patch) echo "${major}.${minor}.$((patch + 1))" ;;
*) echo "$kind" ;; # exact version passthrough
esac
}
set_workspace_version() {
local ver="$1"
for toml in crates/*/Cargo.toml; do
sed -i.bak "s/^version = \".*\"/version = \"${ver}\"/" "$toml"
rm -f "${toml}.bak"
done
}
auto_detect_bump() {
local last_tag
last_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
local range="${last_tag:+${last_tag}..HEAD}"
range="${range:-HEAD}"
if git log "$range" --pretty=%s | grep -qiE '^(feat!|BREAKING)'; then
echo "major"
elif git log "$range" --pretty=%s | grep -qiE '^feat'; then
echo "minor"
else
echo "patch"
fi
}
# ── Platform detection ──────────────────────────────────────────────────────
detect_platform() {
local os arch target suffix archive
case "$(uname -s)" in
Linux*) os="linux" ;;
Darwin*) os="macos" ;;
CYGWIN*|MINGW*|MSYS*) os="windows" ;;
*) die "Unsupported OS: $(uname -s)" ;;
esac
case "$(uname -m)" in
x86_64|amd64) arch="x86_64" ;;
aarch64|arm64) arch="aarch64" ;;
*) die "Unsupported architecture: $(uname -m)" ;;
esac
case "${os}-${arch}" in
linux-x86_64) target="x86_64-unknown-linux-gnu" ;;
linux-aarch64) target="aarch64-unknown-linux-gnu" ;;
macos-x86_64) target="x86_64-apple-darwin" ;;
macos-aarch64) target="aarch64-apple-darwin" ;;
windows-x86_64) target="x86_64-pc-windows-msvc" ;;
windows-aarch64) target="aarch64-pc-windows-msvc" ;;
esac
suffix=""
archive="tar.gz"
if [ "$os" = "windows" ]; then
suffix=".exe"
archive="zip"
fi
echo "${os}|${arch}|${target}|${suffix}|${archive}"
}
# ── Build & Package (shared by both modes) ─────────────────────────────────
build_and_package() {
local tag="$1"
# Ensure target is installed
if ! rustup target list --installed | grep -q "$TARGET"; then
echo "Adding Rust target: $TARGET"
rustup target add "$TARGET"
fi
echo "Building release binaries..."
echo ""
cargo build --release --target "$TARGET" --package drivewipe-cli
echo " [OK] drivewipe built (CLI + TUI + GUI in one binary)"
echo ""
# ── Package ─────────────────────────────────────────────────────────────
DIST_DIR="target/dist"
ARCHIVE_NAME="drivewipe-${tag}-${TARGET}"
rm -rf "$DIST_DIR"
mkdir -p "$DIST_DIR"
cp "target/${TARGET}/release/drivewipe${SUFFIX}" "$DIST_DIR/" || die "CLI binary not found at target/${TARGET}/release/drivewipe${SUFFIX}"
cp install.sh "$DIST_DIR/" 2>/dev/null || true
[ -f LICENSE.md ] && cp LICENSE.md "$DIST_DIR/"
cp README.md "$DIST_DIR/"
echo "Packaging: ${ARCHIVE_NAME}.${ARCHIVE}"
ARCHIVE_PATH="${ROOT_DIR}/${ARCHIVE_NAME}.${ARCHIVE}"
if [ "$ARCHIVE" = "zip" ]; then
(cd "$DIST_DIR" && zip -q "${ARCHIVE_PATH}" ./* )
else
tar czf "${ARCHIVE_PATH}" -C "$DIST_DIR" .
fi
# Generate checksum
CHECKSUM_FILE="${ROOT_DIR}/${ARCHIVE_NAME}.sha256"
if command -v sha256sum &>/dev/null; then
(cd "$(dirname "$ARCHIVE_PATH")" && sha256sum "$(basename "$ARCHIVE_PATH")" > "$CHECKSUM_FILE")
else
(cd "$(dirname "$ARCHIVE_PATH")" && shasum -a 256 "$(basename "$ARCHIVE_PATH")" > "$CHECKSUM_FILE")
fi
echo "Archive: $ARCHIVE_PATH"
echo "Checksum: $CHECKSUM_FILE"
echo ""
}
# ── Main ────────────────────────────────────────────────────────────────────
echo "=== DriveWipe Release Builder ==="
echo ""
# Check tools
check_tool cargo
check_tool gh
check_tool git
# Parse --attach mode
ATTACH_MODE=false
ATTACH_TAG=""
if [ "${1:-}" = "--attach" ]; then
ATTACH_MODE=true
ATTACH_TAG="${2:-}"
if [ -z "$ATTACH_TAG" ]; then
die "Usage: ./release.sh --attach <tag> (e.g. ./release.sh --attach v1.0.0)"
fi
# Normalize: ensure tag starts with 'v'
if [[ "$ATTACH_TAG" != v* ]]; then
ATTACH_TAG="v${ATTACH_TAG}"
fi
fi
# Detect platform
IFS='|' read -r OS ARCH TARGET SUFFIX ARCHIVE <<< "$(detect_platform)"
echo "Platform: $OS ($ARCH)"
echo "Rust target: $TARGET"
echo ""
# ── Attach mode: build + upload to existing release ────────────────────────
if [ "$ATTACH_MODE" = true ]; then
echo "Mode: ATTACH to existing release"
echo "Tag: $ATTACH_TAG"
echo ""
# Verify the release exists
if ! gh release view "$ATTACH_TAG" &>/dev/null; then
die "Release '$ATTACH_TAG' not found on GitHub. Create it first with: ./release.sh <version>"
fi
# Build and package
build_and_package "$ATTACH_TAG"
# Upload artifacts to the existing release
echo "Attaching to release $ATTACH_TAG..."
gh release upload "$ATTACH_TAG" \
"$ARCHIVE_PATH" \
"$CHECKSUM_FILE" \
--clobber
echo ""
echo "=== Attached ${TARGET} build to ${ATTACH_TAG} ==="
echo ""
echo "View at: $(gh release view "$ATTACH_TAG" --json url -q .url)"
# Cleanup
rm -rf "$DIST_DIR"
exit 0
fi
# ── New release mode ───────────────────────────────────────────────────────
# Ensure clean working tree
if [ -n "$(git status --porcelain -- ':(exclude).claude')" ]; then
die "Working tree is dirty. Commit or stash changes first."
fi
# Ensure we're on main
BRANCH=$(git branch --show-current)
if [ "$BRANCH" != "main" ]; then
die "Must be on 'main' branch (currently on '$BRANCH')."
fi
echo "Mode: NEW release"
# Determine version
CURRENT=$(get_current_version)
BUMP_TYPE="${1:-$(auto_detect_bump)}"
if [[ "$BUMP_TYPE" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
NEW_VERSION="$BUMP_TYPE"
else
NEW_VERSION=$(bump_version "$CURRENT" "$BUMP_TYPE")
fi
TAG="v${NEW_VERSION}"
echo "Current version: $CURRENT"
echo "New version: $NEW_VERSION ($BUMP_TYPE)"
echo "Tag: $TAG"
echo ""
# Check tag doesn't already exist
if git rev-parse "$TAG" &>/dev/null; then
die "Tag '$TAG' already exists. Use --attach to add builds: ./release.sh --attach $TAG"
fi
# Build and package
build_and_package "$TAG"
# ── Version bump & tag ──────────────────────────────────────────────────────
echo "Updating workspace version to $NEW_VERSION..."
set_workspace_version "$NEW_VERSION"
git add crates/*/Cargo.toml
git commit -m "chore(release): bump version to ${NEW_VERSION}"
git tag -a "$TAG" -m "Release ${TAG}"
echo "Pushing tag $TAG..."
git push origin main
git push origin "$TAG"
echo ""
# ── GitHub Release ──────────────────────────────────────────────────────────
echo "Creating GitHub release..."
RELEASE_NOTES="## DriveWipe ${TAG}
### Downloads
| Platform | Architecture | Archive |
|---|---|---|
| ${OS} | ${ARCH} | \`${ARCHIVE_NAME}.${ARCHIVE}\` |
*Run \`./release.sh --attach ${TAG}\` on other platforms to add their builds.*
### Contents
- \`drivewipe${SUFFIX}\` — CLI tool
- \`install.sh\` — installer that adds the drivewipe-tui / drivewipe-gui aliases"
RELEASE_NOTES="${RELEASE_NOTES}
### Verify
\`\`\`
shasum -a 256 -c ${ARCHIVE_NAME}.sha256
\`\`\`
"
gh release create "$TAG" \
"$ARCHIVE_PATH" \
"$CHECKSUM_FILE" \
--title "DriveWipe ${TAG}" \
--notes "$RELEASE_NOTES"
echo ""
echo "=== Release $TAG published ==="
echo ""
echo "View at: $(gh release view "$TAG" --json url -q .url)"
echo ""
echo "To add builds from other machines:"
echo " ./release.sh --attach $TAG"
# Cleanup dist
rm -rf "$DIST_DIR"