#!/bin/sh # release.sh — cut a zddc-server stable release: tag, cross-compile # binaries, publish them as assets to a Codeberg release. # # Usage: # sh zddc/release.sh # patch++ from latest stable tag # sh zddc/release.sh 0.1.0 # explicit version (X.Y.Z) # # Why stable-only: zddc-server publishes binaries only on stable cuts. # Beta/alpha channels of zddc-server have no binary distribution — the # helm/zddc-server-{prod,dev} charts in this repo build from source at # deploy time, so any commit on main is buildable. There's no # cascade/symlink layer for binaries; if you need a specific build, # pin the chart's commit ref. # # Prerequisites: # - Go 1.24+ on PATH. # - $CODEBERG_TOKEN exported, scoped to write the VARASYS/ZDDC repo. # - curl, jq, git. # # What it does: # 1. Derive version: explicit arg, or patch-bumped from latest clean # zddc-server-vX.Y.Z tag. # 2. Tag the current commit zddc-server-v. # 3. Cross-compile binaries (linux/darwin/windows × amd64/arm64) into # zddc/dist/zddc-server--[.exe]. Native Go. # 4. Upload each binary as a release asset on Codeberg. # 5. Print the operator's next steps (push the tag). # # The script does NOT push the tag itself — that's a deliberate `git push` # you do after reviewing. set -eu usage() { cat >&2 <<'EOF' usage: release.sh [] No args patch-bump from the latest clean zddc-server-vX.Y.Z tag. explicit X.Y.Z (e.g. 0.1.0). EOF exit 1 } case "${1:-}" in -h | --help) usage ;; esac EXPLICIT_VERSION="${1:-}" if [ -z "${CODEBERG_TOKEN:-}" ]; then echo "error: CODEBERG_TOKEN must be exported in the environment" >&2 echo " (Codeberg user → Settings → Applications → generate a token" >&2 echo " with scope sufficient to create releases on VARASYS/ZDDC.)" >&2 exit 1 fi SCRIPT_DIR=$(cd "$(dirname "$0")/.." && pwd) TAG_PREFIX="zddc-server-v" REPO="VARASYS/ZDDC" # Source build-lib.sh for _validate_semver. It requires root_dir set; # pointing at the repo root works. root_dir="$SCRIPT_DIR" . "$SCRIPT_DIR/shared/build-lib.sh" . "$SCRIPT_DIR/shared/publish-codeberg-release.sh" # --- Determine version ----------------------------------------------------- if [ -n "$EXPLICIT_VERSION" ]; then _validate_semver "$EXPLICIT_VERSION" VERSION="$EXPLICIT_VERSION" else _latest=$(git -C "$SCRIPT_DIR" tag --list "${TAG_PREFIX}*" 2>/dev/null \ | grep -E "^${TAG_PREFIX}[0-9]+\.[0-9]+\.[0-9]+\$" \ | sed "s|^${TAG_PREFIX}||" \ | sort -V \ | tail -1) [ -n "$_latest" ] || _latest="0.0.0" _major="${_latest%%.*}" _rest="${_latest#*.}" _minor="${_rest%%.*}" _patch="${_rest#*.}" VERSION="${_major}.${_minor}.$((_patch + 1))" fi GIT_TAG="${TAG_PREFIX}${VERSION}" echo "=== zddc-server stable release ===" echo "Version: $VERSION" echo "Git tag: $GIT_TAG" echo # --- Tag the commit (idempotent: skip if the tag already points here) ----- if git -C "$SCRIPT_DIR" rev-parse -q --verify "refs/tags/$GIT_TAG" >/dev/null; then _existing=$(git -C "$SCRIPT_DIR" rev-list -n 1 "$GIT_TAG") _head=$(git -C "$SCRIPT_DIR" rev-parse HEAD) if [ "$_existing" != "$_head" ]; then echo "error: tag $GIT_TAG already exists at $_existing, but HEAD is $_head" >&2 echo " refusing to overwrite. Resolve manually." >&2 exit 1 fi echo "(tag $GIT_TAG already at HEAD)" else git -C "$SCRIPT_DIR" tag "$GIT_TAG" echo "tagged $GIT_TAG" fi # --- Cross-compile binaries (native Go) ------------------------------------ if ! command -v go >/dev/null 2>&1; then echo "error: go not found on PATH" >&2 echo " (install Go 1.24+, or run this script from inside a Go" >&2 echo " container — there's no podman fallback anymore.)" >&2 exit 1 fi DIST="$SCRIPT_DIR/zddc/dist" mkdir -p "$DIST" echo echo "=== Cross-compiling ===" cd "$SCRIPT_DIR/zddc" LDFLAGS="-s -w -X main.version=${VERSION}" for target in linux/amd64 darwin/amd64 darwin/arm64 windows/amd64; do os="${target%/*}" arch="${target#*/}" out="zddc-server-${os}-${arch}" case "$os" in windows) out="${out}.exe" ;; esac echo " building $out" CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" \ go build -trimpath -ldflags="$LDFLAGS" -o "$DIST/$out" ./cmd/zddc-server done cd "$SCRIPT_DIR" # --- Publish to Codeberg --------------------------------------------------- echo echo "=== Publishing to Codeberg release $GIT_TAG ===" publish_codeberg_release "$REPO" "$GIT_TAG" \ "$DIST/zddc-server-linux-amd64" \ "$DIST/zddc-server-darwin-amd64" \ "$DIST/zddc-server-darwin-arm64" \ "$DIST/zddc-server-windows-amd64.exe" echo echo "=== Done ===" echo "Release: https://codeberg.org/$REPO/releases/tag/$GIT_TAG" echo "Git tag: $GIT_TAG (publish with: git push origin $GIT_TAG)"