-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·117 lines (97 loc) · 3.89 KB
/
Copy pathrelease.sh
File metadata and controls
executable file
·117 lines (97 loc) · 3.89 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
#!/usr/bin/env bash
set -euo pipefail
# cuts a new release: bumps version in package.json / tauri.conf.json / Cargo.toml,
# commits, tags vX.Y.Z, and pushes the tag. the release.yml workflow then builds,
# signs, and publishes a draft github release with latest.json.
#
# usage:
# ./release.sh patch # 0.1.0 -> 0.1.1
# ./release.sh minor # 0.1.0 -> 0.2.0
# ./release.sh major # 0.1.0 -> 1.0.0
# ./release.sh 0.4.2 # explicit
# ./release.sh minor --push # skip the confirm prompt before pushing
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
info() { echo -e "${BLUE}ℹ${NC} $1"; }
ok() { echo -e "${GREEN}✓${NC} $1"; }
warn() { echo -e "${YELLOW}⚠${NC} $1"; }
err() { echo -e "${RED}✗${NC} $1"; }
fail() { err "$1"; exit 1; }
cd "$(dirname "$0")" || fail "could not cd to script directory"
BUMP=""
AUTO_PUSH=false
RELEASE_BRANCH="main"
for arg in "$@"; do
case "$arg" in
--push) AUTO_PUSH=true ;;
patch|minor|major) BUMP="$arg" ;;
[0-9]*.[0-9]*.[0-9]*) BUMP="$arg" ;;
*) fail "unknown argument: $arg" ;;
esac
done
[ -n "$BUMP" ] || fail "specify patch | minor | major | X.Y.Z"
has_cmd() { command -v "$1" &>/dev/null; }
has_cmd git || fail "git not found"
has_cmd node || fail "node not found"
# preflight: clean tree on the release branch
git rev-parse --is-inside-work-tree &>/dev/null || fail "not a git repo"
current_branch="$(git branch --show-current)"
[ "$current_branch" = "$RELEASE_BRANCH" ] || warn "on '$current_branch', not '$RELEASE_BRANCH'"
[ -z "$(git status --porcelain)" ] || fail "working tree not clean — commit or stash first"
CUR="$(node -p "require('./package.json').version")"
[ -n "$CUR" ] || fail "could not read current version from package.json"
if [[ "$BUMP" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
NEW="$BUMP"
else
IFS='.' read -r maj min pat <<< "$CUR"
case "$BUMP" in
major) maj=$((maj+1)); min=0; pat=0 ;;
minor) min=$((min+1)); pat=0 ;;
patch) pat=$((pat+1)) ;;
esac
NEW="$maj.$min.$pat"
fi
[ "$NEW" != "$CUR" ] || fail "new version equals current ($CUR)"
git rev-parse "v$NEW" &>/dev/null && fail "tag v$NEW already exists"
info "bumping $CUR -> $NEW"
# json files: rewrite via node to keep formatting stable
set_json_version() {
local f="$1"
node -e '
const fs = require("fs");
const f = process.argv[1], v = process.argv[2];
const j = JSON.parse(fs.readFileSync(f, "utf8"));
j.version = v;
fs.writeFileSync(f, JSON.stringify(j, null, 2) + "\n");
' "$f" "$NEW"
ok "updated $f"
}
set_json_version package.json
set_json_version src-tauri/tauri.conf.json
# cargo.toml: replace only the first version line (the [package] one)
sed -i "0,/^version = \".*\"/s//version = \"$NEW\"/" src-tauri/Cargo.toml
ok "updated src-tauri/Cargo.toml"
# keep Cargo.lock in sync without a full network resolve
if has_cmd cargo; then
(cd src-tauri && cargo update -p openarc-studio --precise "$NEW" --offline 2>/dev/null) || \
warn "could not refresh Cargo.lock offline — run 'cargo build' before pushing if it complains"
fi
echo ""
git --no-pager diff --stat
echo ""
if [ "$AUTO_PUSH" = false ]; then
read -rp "commit, tag v$NEW, and push to origin/$current_branch? [y/N] " reply
[[ "$reply" =~ ^[Yy]$ ]] || { git checkout -- . ; fail "aborted — changes reverted"; }
fi
git add package.json src-tauri/tauri.conf.json src-tauri/Cargo.toml src-tauri/Cargo.lock 2>/dev/null || \
git add package.json src-tauri/tauri.conf.json src-tauri/Cargo.toml
git commit -m "release: v$NEW"
git tag -a "v$NEW" -m "openarc-studio v$NEW"
ok "committed and tagged v$NEW"
git push origin "$current_branch"
git push origin "v$NEW"
ok "pushed — watch the build: https://github.com/SearchSavior/openarc-studio/actions"
info "the workflow creates a DRAFT release; review it, then publish to ship the update"