From 9b1165a49a4eca4d0f098f42a57efff1a5aae4da Mon Sep 17 00:00:00 2001 From: shoemoney Date: Tue, 23 Jun 2026 13:31:54 -0500 Subject: [PATCH] =?UTF-8?q?feat(release):=20arm64/arm=20targets=20+=20Forg?= =?UTF-8?q?ejo=20release=20one-shot=20+=20CI=20workflows=20=F0=9F=93=A6?= =?UTF-8?q?=F0=9F=A4=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - build-release.sh: add linux/arm64 (Raspberry Pi!) + linux/arm targets — the curl|sh install on a clean Pi needs a real arm64 asset to download. - scripts/release.sh: one-shot local release. Cross-compiles, then creates/updates the Forgejo release and uploads de-versioned assets (devbox__) that install.sh fetches directly. No CI runner required. - .forgejo + .github CI workflows: go vet + build + test -race on push/PR; on vX.Y.Z tag, build-release + publish. GitHub's runs on hosted runners today. - docker-compose: pull the published hub image by default; --build for local source. --- .forgejo/workflows/ci.yml | 20 +++++++++ .forgejo/workflows/release.yml | 23 ++++++++++ .github/workflows/ci.yml | 21 ++++++++++ .github/workflows/release.yml | 41 ++++++++++++++++++ docker-compose.yml | 7 ++-- scripts/build-release.sh | 3 +- scripts/release.sh | 77 ++++++++++++++++++++++++++++++++++ 7 files changed, 188 insertions(+), 4 deletions(-) create mode 100644 .forgejo/workflows/ci.yml create mode 100644 .forgejo/workflows/release.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml create mode 100755 scripts/release.sh diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml new file mode 100644 index 0000000..077d10b --- /dev/null +++ b/.forgejo/workflows/ci.yml @@ -0,0 +1,20 @@ +# Forgejo Actions CI — runs once a runner is registered (act_runner with a +# `linux`/`ubuntu-latest` label). Until then it's inert, no harm. +name: CI +on: + push: + branches: [main] + pull_request: + +jobs: + vet-build-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: true + - run: go vet ./... + - run: go build ./... + - run: go test ./... -race diff --git a/.forgejo/workflows/release.yml b/.forgejo/workflows/release.yml new file mode 100644 index 0000000..58c9e41 --- /dev/null +++ b/.forgejo/workflows/release.yml @@ -0,0 +1,23 @@ +# On `vX.Y.Z` tag push: cross-compile every target and publish the Forgejo +# release with installer-named assets. Reuses scripts/release.sh so the local +# one-shot and CI never drift. Needs a runner + a RELEASE_TOKEN secret (a +# Forgejo token with write:repository). Until both exist, run release.sh by hand. +name: Release +on: + push: + tags: ['v*'] + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # tags + history for `git describe` + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: true + - run: ./scripts/release.sh "${{ github.ref_name }}" + env: + FORGEJO_TOKEN: ${{ secrets.RELEASE_TOKEN }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..faa316c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,21 @@ +# GitHub Actions mirror of .forgejo/workflows/ci.yml. This one runs on GitHub's +# hosted runners today (Forgejo's waits on a self-hosted runner), so it's what +# actually gates PRs green/red on the github mirror. +name: CI +on: + push: + branches: [main] + pull_request: + +jobs: + vet-build-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: true + - run: go vet ./... + - run: go build ./... + - run: go test ./... -race diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b801999 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,41 @@ +# On `vX.Y.Z` tag push: cross-compile every target and attach installer-named +# assets to a GitHub release (mirror of the Forgejo release). Point install.sh at +# this with DEVBOX_RELEASE_URL=https://github.com//devbox/releases/download/. +name: Release +on: + push: + tags: ['v*'] + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: true + - name: Build all targets + run: VERSION="${{ github.ref_name }}" ./scripts/build-release.sh + - name: De-version asset names (match install.sh) + run: | + cd dist + for f in devbox_*_* devbox-hub_*_*; do + [ -f "$f" ] || continue + ext=""; case "$f" in *.exe) ext=".exe"; f="${f%.exe}";; esac + arch="${f##*_}"; rest="${f%_*}"; os="${rest##*_}"; bin="${rest%_*}"; bin="${bin%_*}" + mv "$f$ext" "${bin}_${os}_${arch}${ext}" + done + ls -la + - name: Publish GitHub release + env: + GH_TOKEN: ${{ github.token }} + run: | + gh release create "${{ github.ref_name }}" dist/* \ + --title "${{ github.ref_name }}" \ + --generate-notes diff --git a/docker-compose.yml b/docker-compose.yml index 8e305b4..23b3cd9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,7 @@ # devbox hub — drop-in for a NAS (TrueNAS SCALE, Synology, unRAID, any Docker host). # -# docker compose up -d --build # hub on :8088, data persisted, self-healing +# docker compose up -d # pulls the published image, hub on :8088 +# docker compose up -d --build # build from local source instead # docker compose exec hub devbox-hub token --data /data # mint a join token # docker compose logs -f hub # @@ -8,9 +9,9 @@ services: hub: + # Published image is the default; `--build` rebuilds from the local source tree. + image: git.shoemoney.ai/shoemoney/devbox-hub:latest build: . - # Prefer a published image once you have one: - # image: git.shoemoney.ai/shoemoney/devbox-hub:latest container_name: devbox-hub restart: unless-stopped # keep-alive + auto-restart + recover (crash & reboot) ports: diff --git a/scripts/build-release.sh b/scripts/build-release.sh index 412ad01..a8d451f 100755 --- a/scripts/build-release.sh +++ b/scripts/build-release.sh @@ -10,7 +10,8 @@ VERSION="${VERSION:-$(git describe --tags --always --dirty 2>/dev/null || echo d LDFLAGS="-s -w -X main.version=$VERSION" BINS=(devbox devbox-hub) -TARGETS=(linux/amd64 darwin/arm64 darwin/amd64 windows/amd64) +# linux/arm64 = Raspberry Pi 5/4/3 (64-bit) + arm Macs' Linux VMs; linux/arm = 32-bit Pi OS. +TARGETS=(linux/amd64 linux/arm64 linux/arm darwin/arm64 darwin/amd64 windows/amd64) rm -rf dist && mkdir -p dist diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 0000000..ca2d1f9 --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +set -euo pipefail + +# One-shot local release to Forgejo. No CI runner required. +# +# ./scripts/release.sh # (re)publish the moving 'latest' release from HEAD +# ./scripts/release.sh v1.0.0 # cut a versioned release (creates the git tag at HEAD) +# +# Builds every target via build-release.sh, then creates/updates the Forgejo release +# and uploads assets under the *de-versioned* names install.sh downloads: +# devbox__ devbox-hub__ (+ .exe on windows) + SHA256SUMS +# +# Auth: ~/.config/forgejo/token (or $FORGEJO_TOKEN). Override host/repo with +# FORGEJO_API / REPO if you ever move the remote. + +cd "$(dirname "$0")/.." + +TAG="${1:-latest}" +API="${FORGEJO_API:-https://git.shoemoney.ai/api/v1}" +REPO="${REPO:-shoemoney/devbox}" +TOKEN="${FORGEJO_TOKEN:-$(cat ~/.config/forgejo/token 2>/dev/null || true)}" +[ -n "$TOKEN" ] || { echo "🛑 no Forgejo token (set FORGEJO_TOKEN or ~/.config/forgejo/token)" >&2; exit 1; } + +auth=(-H "Authorization: token $TOKEN") +api() { curl -fsSL "${auth[@]}" "$@"; } + +# 1. Build. A real tag stamps its name into the binary; 'latest' uses git-describe. +if [ "$TAG" = latest ]; then + ./scripts/build-release.sh +else + VERSION="$TAG" ./scripts/build-release.sh +fi + +COMMIT=$(git rev-parse HEAD) + +# 2. Drop any existing release+tag with this name so we recreate cleanly (latest is a +# moving target; re-cutting a vX.Y.Z is rare but should be idempotent too). +old_id=$(api "$API/repos/$REPO/releases/tags/$TAG" 2>/dev/null \ + | python3 -c 'import sys,json;print(json.load(sys.stdin).get("id",""))' 2>/dev/null || true) +if [ -n "${old_id:-}" ]; then + echo "↻ replacing existing release '$TAG' (id $old_id)" + curl -fsSL -X DELETE "${auth[@]}" "$API/repos/$REPO/releases/$old_id" || true +fi +# Move the lightweight tag to HEAD for 'latest'; leave real version tags alone if present. +if [ "$TAG" = latest ]; then + curl -fsSL -X DELETE "${auth[@]}" "$API/repos/$REPO/tags/$TAG" >/dev/null 2>&1 || true +fi + +# 3. Create the release (Forgejo creates the tag at $COMMIT if it doesn't exist). +prerelease=$([ "$TAG" = latest ] && echo true || echo false) +body=$(printf 'devbox %s — built %s from `%s`.\n\nInstall: `curl -fsSL https://git.shoemoney.ai/shoemoney/devbox/raw/branch/main/install.sh | sh`' "$TAG" "$(date -u +%Y-%m-%dT%H:%MZ)" "${COMMIT:0:7}") +rel_id=$(api -X POST "$API/repos/$REPO/releases" \ + -H 'Content-Type: application/json' \ + -d "$(python3 -c 'import json,sys; t,c,b,p=sys.argv[1:5]; print(json.dumps({"tag_name":t,"target_commitish":c,"name":t,"body":b,"draft":False,"prerelease":p=="true"}))' "$TAG" "$COMMIT" "$body" "$prerelease")" \ + | python3 -c 'import sys,json;print(json.load(sys.stdin)["id"])') +echo "✅ release '$TAG' created (id $rel_id)" + +# 4. Upload de-versioned assets. dist names are ___[.exe]. +upload() { + local f="$1" base ext arch rest os bin name + base=$(basename "$f"); ext="" + case "$base" in *.exe) ext=".exe"; base="${base%.exe}";; esac + arch="${base##*_}"; rest="${base%_*}" + os="${rest##*_}"; bin="${rest%_*}"; bin="${bin%_*}" # strip version component + name="${bin}_${os}_${arch}${ext}" + echo " ⬆ $name" + api -X POST "$API/repos/$REPO/releases/$rel_id/assets?name=$name" \ + -F "attachment=@$f" >/dev/null +} +for f in dist/devbox_* dist/devbox-hub_*; do [ -f "$f" ] && upload "$f"; done +# checksums keep their plain name +echo " ⬆ SHA256SUMS" +api -X POST "$API/repos/$REPO/releases/$rel_id/assets?name=SHA256SUMS" \ + -F "attachment=@dist/SHA256SUMS" >/dev/null + +echo +echo "🎉 https://git.shoemoney.ai/$REPO/releases/tag/$TAG"