-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·100 lines (85 loc) · 2.98 KB
/
deploy.sh
File metadata and controls
executable file
·100 lines (85 loc) · 2.98 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
#!/usr/bin/env bash
# Cut a microcode release.
#
# Usage:
# ./deploy.sh # auto-bump patch (0.1.0 -> 0.1.1)
# ./deploy.sh 0.2.0 # explicit version
# ./deploy.sh --minor # bump minor
# ./deploy.sh --major # bump major
# ./deploy.sh --dry-run # show what would happen
#
# Side effects:
# 1. Updates `version` in Cargo.toml
# 2. Refreshes Cargo.lock
# 3. Commits "release vX.Y.Z"
# 4. Tags vX.Y.Z (annotated)
# 5. Pushes main + tag
# 6. The GitHub Actions release workflow takes over: it builds platform
# binaries, packages them, and uploads to the GitHub release.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
cd "$ROOT"
red() { printf '\033[31m%s\033[0m' "$*"; }
green() { printf '\033[32m%s\033[0m' "$*"; }
err() { echo "$(red error:) $*" >&2; exit 1; }
info() { echo "$(green ::) $*"; }
DRY_RUN=0
BUMP=patch
EXPLICIT_VERSION=
while [ $# -gt 0 ]; do
case "$1" in
--dry-run) DRY_RUN=1 ;;
--major) BUMP=major ;;
--minor) BUMP=minor ;;
--patch) BUMP=patch ;;
-h|--help) sed -n '2,20p' "$0" ; exit 0 ;;
-*) err "unknown flag: $1" ;;
*) EXPLICIT_VERSION="$1" ;;
esac
shift
done
# Sanity: clean tree and on main.
[ -z "$(git status --porcelain)" ] || err "working tree is dirty; commit or stash first"
branch="$(git rev-parse --abbrev-ref HEAD)"
[ "$branch" = "main" ] || err "must release from 'main' (currently on '$branch')"
# Resolve current version from Cargo.toml.
current="$(grep -E '^version\s*=' Cargo.toml | head -n1 | sed -E 's/.*"([^"]+)".*/\1/')"
[ -n "$current" ] || err "could not parse current version from Cargo.toml"
if [ -n "$EXPLICIT_VERSION" ]; then
next="$EXPLICIT_VERSION"
else
IFS='.' read -r MAJ MIN PAT <<<"$current"
case "$BUMP" in
major) next="$((MAJ+1)).0.0" ;;
minor) next="$MAJ.$((MIN+1)).0" ;;
patch) next="$MAJ.$MIN.$((PAT+1))" ;;
esac
fi
info "current: $current → next: $next"
[ "$current" != "$next" ] || err "next == current; nothing to do"
if [ "$DRY_RUN" = "1" ]; then
echo "(dry-run) would:"
echo " - update Cargo.toml to version = \"$next\""
echo " - cargo build to refresh Cargo.lock"
echo " - commit 'release v$next'"
echo " - git tag -a v$next -m 'v$next'"
echo " - git push origin main && git push origin v$next"
exit 0
fi
# Update Cargo.toml.
if [ "$(uname)" = "Darwin" ]; then
sed -i '' -E "s/^version = \"$current\"/version = \"$next\"/" Cargo.toml
else
sed -i -E "s/^version = \"$current\"/version = \"$next\"/" Cargo.toml
fi
info "running cargo build to refresh Cargo.lock"
cargo build --release >/dev/null
git add Cargo.toml Cargo.lock 2>/dev/null || git add Cargo.toml
git commit -m "release v$next"
git tag -a "v$next" -m "v$next"
info "pushing"
git push origin main
git push origin "v$next"
info "tag v$next pushed. CI will build and upload release assets."
echo
echo "Watch the run: https://github.com/$(git remote get-url origin | sed -E 's#(git@|https://)github.com[:/](.+)\.git#\2#' )/actions"