Vectrum
Sign In

Merge build.sh releases: -r publishes on Vectrum, -v sets the version

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
JjohannSocommitted 2 parents 2e4890f 91fc25acommit6ec9d8f

Showing 2 changed files with 129 additions and 1 deletion.

Merge commit — showing changes against the first parent.

+12−0README.mdView File
@@ -299,6 +299,18 @@ paths set there for each agent's first instance. Threads and the project list li
299299 `~/.local/share/vectrum-code` (`threads/`, `state.json`); threads started without a project run
300300 in its `scratch` folder.
301301
302+ ## Build and release
303+
304+ `./build.sh` builds the release binary and an AppImage into `build/`. `-v 0.1.2` first sets the
305+ version (in `Cargo.toml` and `Cargo.lock`, committed as "Version 0.1.2"), and `--release` (or
306+ `-r`) publishes the build on Vectrum: it tags the commit with the version, pushes the tag, and
307+ uploads the AppImage, the binary and `SHA256SUMS`, which publishes the release. So
308+ `./build.sh -v 0.1.2 -r` makes and publishes 0.1.2. Releasing needs a clean working tree, a
309+ version not tagged yet, and a read & write API token in `VECTRUM_TOKEN` or
310+ `~/.config/vectrum/token`; the version commit stays on your branch until you push it.
311+ `VECTRUM_URL` (`https://vectrum.cc`) and `VECTRUM_REPO` (from the origin remote) pick where
312+ it goes.
313+
302314 ## Layout
303315
304316 - `src/claude.rs`: spawns and owns the agent process, `claude`, `pi` or `jcode api --stdio`
+117−1build.shView File
@@ -5,8 +5,43 @@
55 #
66 # appimagetool is used from $PATH if present, otherwise downloaded once into
77 # build/.tools. Set APPIMAGETOOL=/path/to/appimagetool to use a specific one.
8+ #
9+ # Options:
10+ # -v, --version X set the version to X (0.1.2) first: updates Cargo.toml
11+ # and Cargo.lock and commits them as "Version X"
12+ # -r, --release then publish the build as a release on Vectrum: tag the
13+ # commit with the version, push the tag, and upload the
14+ # AppImage, the binary and SHA256SUMS (the first upload
15+ # publishes the release). Each release needs a new version.
16+ # -h, --help show this
17+ #
18+ # So ./build.sh -v 0.1.2 -r makes and publishes version 0.1.2. Releasing reads:
19+ # VECTRUM_TOKEN a read & write API token (vec_…); otherwise read from
20+ # ~/.config/vectrum/token (or $VECTRUM_TOKEN_FILE)
21+ # VECTRUM_URL the server, https://vectrum.cc by default
22+ # VECTRUM_REPO owner/repo, taken from the origin remote by default
823 set -euo pipefail
924
25+ log() { printf '\033[1;34m==>\033[0m %s\n' "$*"; }
26+ die() { printf '\033[1;31mxx\033[0m %s\n' "$*" >&2; exit 1; }
27+
28+ RELEASE=0
29+ NEW_VERSION=""
30+ while (( $# )); do
31+ case "$1" in
32+ -r|--release) RELEASE=1 ;;
33+ -v|--version)
34+ [[ $# -ge 2 ]] || die "$1 needs a version, like $1 0.1.2"
35+ NEW_VERSION="$2"
36+ shift
37+ ;;
38+ --version=*) NEW_VERSION="${1#*=}" ;;
39+ -h|--help) sed -n '2,/^set -euo/p' "$0" | sed '$d; s/^# \{0,1\}//'; exit 0 ;;
40+ *) printf 'Unknown option: %s (try --help)\n' "$1" >&2; exit 2 ;;
41+ esac
42+ shift
43+ done
44+
1045 ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1146 BUILD="$ROOT/build"
1247 TOOLS="$BUILD/.tools"
@@ -17,7 +52,55 @@ PRETTY="Vectrum Code"
1752 VERSION="$(sed -n 's/^version *= *"\(.*\)"/\1/p' "$ROOT/Cargo.toml" | head -n1)"
1853 ARCH="$(uname -m)"
1954
20- log() { printf '\033[1;34m==>\033[0m %s\n' "$*"; }
55+ dirty() { [[ -n "$(git -C "$ROOT" status --porcelain)" ]]; }
56+
57+ # Stops if tag $1 already names a commit other than $2 (any commit, if $2 is
58+ # empty), here or on origin. Sets REMOTE_TAG and LOCAL_TAG.
59+ check_tag() {
60+ REMOTE_TAG="$(git -C "$ROOT" ls-remote origin "refs/tags/$1^{}" "refs/tags/$1" | awk 'NR==1 || /\^\{\}$/ {sha=$1} END {print sha}')"
61+ LOCAL_TAG="$(git -C "$ROOT" rev-parse -q --verify "refs/tags/$1^{commit}" || true)"
62+ for tagged in "$REMOTE_TAG" "$LOCAL_TAG"; do
63+ [[ -z "$tagged" || "$tagged" == "$2" ]] ||
64+ die "$1 is already tagged at ${tagged:0:7}; pick a new version with -v"
65+ done
66+ }
67+
68+ # ── 0. Version and release checks, before spending time on a build ───────────
69+ if (( RELEASE )); then
70+ SERVER="${VECTRUM_URL:-https://vectrum.cc}"
71+ SERVER="${SERVER%/}"
72+ TOKEN_FILE="${VECTRUM_TOKEN_FILE:-$HOME/.config/vectrum/token}"
73+ TOKEN="${VECTRUM_TOKEN:-}"
74+ if [[ -z "$TOKEN" && -r "$TOKEN_FILE" ]]; then
75+ TOKEN="$(tr -d '[:space:]' < "$TOKEN_FILE")"
76+ fi
77+ [[ -n "$TOKEN" ]] || die "No API token: set VECTRUM_TOKEN or save a read & write token to $TOKEN_FILE"
78+ # ssh://git@git.vectrum.cc:2222/vectrum/code.git, https://…/vectrum/code → vectrum/code
79+ REPO="${VECTRUM_REPO:-$(git -C "$ROOT" remote get-url origin | sed -E 's#\.git$##; s#^.*[:/]([^/:]+/[^/:]+)$#\1#')}"
80+ [[ "$REPO" == */* ]] || die "Couldn't tell the repository from the origin remote; set VECTRUM_REPO=owner/repo"
81+ fi
82+
83+ if [[ -n "$NEW_VERSION" && "$NEW_VERSION" != "$VERSION" ]]; then
84+ [[ "$NEW_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]] ||
85+ die "$NEW_VERSION isn't a version like 0.1.2"
86+ ! dirty || die "Commit or stash your changes first: the new version is committed on its own"
87+ if (( RELEASE )); then
88+ check_tag "$NEW_VERSION" ""
89+ fi
90+ log "Version $VERSION → $NEW_VERSION"
91+ sed -i "0,/^version *= *\".*\"/s//version = \"$NEW_VERSION\"/" "$ROOT/Cargo.toml"
92+ cargo update --workspace --offline --quiet --manifest-path "$ROOT/Cargo.toml"
93+ git -C "$ROOT" commit -q -m "Version $NEW_VERSION" -- Cargo.toml Cargo.lock
94+ VERSION="$NEW_VERSION"
95+ fi
96+
97+ if (( RELEASE )); then
98+ TAG="$VERSION"
99+ ! dirty || die "Commit or stash your changes first: a release is built from a commit"
100+ HEAD="$(git -C "$ROOT" rev-parse HEAD)"
101+ check_tag "$TAG" "$HEAD"
102+ log "Releasing $TAG of $REPO on $SERVER from ${HEAD:0:7}"
103+ fi
21104
22105 # ── 1. Binary ────────────────────────────────────────────────────────────────
23106 log "Building $NAME $VERSION (release, $ARCH)"
@@ -84,3 +167,36 @@ APPIMAGE_EXTRACT_AND_RUN=1 ARCH="$ARCH" "$APPIMAGETOOL" --no-appstream "$APPDIR"
84167 rm -rf "$APPDIR"
85168
86169 log "AppImage: ${OUT#"$ROOT"/}"
170+
171+ # ── 5. Release ───────────────────────────────────────────────────────────────
172+ if (( RELEASE )); then
173+ STAGE="$BUILD/release-$TAG"
174+ rm -rf "$STAGE"
175+ mkdir -p "$STAGE"
176+ cp "$OUT" "$STAGE/"
177+ cp "$BUILD/$NAME" "$STAGE/$NAME-$VERSION-$ARCH"
178+ (cd "$STAGE" && sha256sum -- * > SHA256SUMS)
179+
180+ if [[ -z "$LOCAL_TAG" ]]; then
181+ git -C "$ROOT" tag -a "$TAG" -m "$PRETTY $VERSION" "$HEAD"
182+ fi
183+ if [[ -z "$REMOTE_TAG" ]]; then
184+ log "Pushing tag $TAG"
185+ git -C "$ROOT" push -q origin "refs/tags/$TAG"
186+ fi
187+
188+ # The checksums go last, so the release never shows them alone.
189+ for name in "$(basename "$OUT")" "$NAME-$VERSION-$ARCH" SHA256SUMS; do
190+ file="$STAGE/$name"
191+ log "Uploading $name"
192+ # The token goes in through a file descriptor, so it never shows in ps.
193+ if ! reply="$(curl -sS --fail-with-body -T "$file" -H @<(printf 'Authorization: Bearer %s\n' "$TOKEN") \
194+ "$SERVER/$REPO/releases/download/$TAG/$name" 2>&1)"; then
195+ die "Uploading $name failed: $reply (run the same command again to retry)"
196+ fi
197+ done
198+ log "Released: $SERVER/$REPO/releases/tag/$TAG"
199+ fi
200+ if [[ -n "$NEW_VERSION" ]] && [[ -n "$(git -C "$ROOT" log --oneline '@{upstream}..HEAD' 2>/dev/null || echo unpushed)" ]]; then
201+ log "The version commit is only on your $(git -C "$ROOT" branch --show-current) branch here: git push to share it"
202+ fi