ZDDC/zddc/release.sh
ZDDC 408a1a0571 refactor: HTML tools live in website/releases/ as static files + symlink hierarchy
Rolls back the HTML-tool side of the Codeberg-as-canonical refactor
(commits 2dc9ad2, b28c4ae, bdac8dc) in favor of a simpler model:
per-version HTML files committed under website/releases/ as immutable
real files; partial-version pins (<tool>_v<X.Y>.html, <tool>_v<X>.html)
and channel mirrors (<tool>_<channel>.html) are checked-in symlinks.
Docker-tag pattern: :1.2.3 is pinned, :1.2 floats, :1 floats further,
:stable floats furthest.

URL scheme — every URL resolves to actual HTML via the symlink chain;
no JS indirection, no manifest.json, no Caddy regex-rewrite:

  /releases/<tool>_v<X.Y.Z>.html    exact version (real file)
  /releases/<tool>_v<X.Y>.html      latest patch within X.Y.* (symlink)
  /releases/<tool>_v<X>.html        latest within X.*.* (symlink)
  /releases/<tool>_stable.html      current stable (symlink)
  /releases/<tool>_beta.html        current beta (symlink to stable when no
                                    active beta; real file when beta is in flight)
  /releases/<tool>_alpha.html       current alpha (similar — symlink to beta
                                    or stable when no active alpha)

Cascade rule (in shared/build-lib.sh promote_release):
  --release [version] (stable cut) → write per-version file; refresh 5
                                     symlinks (_v<X.Y>, _v<X>, _stable,
                                     _beta, _alpha) → new versioned file;
                                     tag <tool>-v<X.Y.Z>.
  --release beta                   → overwrite <tool>_beta.html with real
                                     bytes; cascade _alpha.html → _beta.html
                                     (symlink). No tag — channel URLs are
                                     stable URLs by design; counters defeat
                                     that.
  --release alpha                  → overwrite <tool>_alpha.html with real
                                     bytes. No tag, no other side-effects.
  Plain `sh tool/build.sh`         → dist/ only. No website/releases/
                                     side-effect, no commit.

Code changes:

- .gitignore — drop website/releases/*.html and website/releases/zddc-server-*
  exclusions; HTML tool files are tracked again. Replace the comment with
  the new model description.
- shared/build-lib.sh — drop next_prerelease (no -alpha.N / -beta.N counter
  tags). Drop the Codeberg-upload path for HTML tools (no longer sourcing
  publish-codeberg-release.sh from build-lib). promote_release rewritten
  with two helpers: _promote_stable (per-version file + 5 symlinks + tag)
  and _promote_channel (overwrite mirror + cascade alpha→beta on beta cut).
- zddc/release.sh — drop alpha/beta channel path entirely; binaries publish
  only on stable cuts. zddc-server's beta/alpha builds-from-source via the
  helm charts (next phase) — no binary distribution needed for those channels.
- bootstrap/level2.html.tmpl — drop manifest.json fetch; resolve ?v= to a
  static URL via the symlink chain. New suffixFor() handles channel names,
  exact versions, and partial-version pins (?v=0.0, ?v=0). Same logic in
  level1.html.tmpl already works because the local-staging files (e.g.
  ../<tool>_v0.0.html) exist via the same symlink scheme.
- build.sh build_releases_index — revert to filesystem scan of
  website/releases/ instead of Codeberg API call. Drop manifest.json
  generation. Per-tool sections list channel chips + per-version pin links;
  zddc-server section links to Codeberg release pages directly.
- tests/build-label.spec.js — fix the channel-label regex to match the
  pre-release-semver format introduced in commit 9459139 ("v0.0.3-alpha · ...").
  Pre-existing test failure that wasn't caught at the time.

Storage:

- 30 new committed files under website/releases/ — 10 real (per-version) +
  20 symlinks (5 tools × 4 partial/channel variants, plus alpha as a real
  file by default).
- Initial state: stable v0.0.2 across all 5 tools; alpha/beta/v0.0/v0
  symlinks all point at <tool>_v0.0.2.html.
- manifest.json deleted (no longer needed).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 09:40:16 -05:00

146 lines
4.8 KiB
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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<version>.
# 3. Cross-compile binaries (linux/darwin/windows × amd64/arm64) into
# zddc/dist/zddc-server-<os>-<arch>[.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 [<version>]
No args patch-bump from the latest clean zddc-server-vX.Y.Z tag.
<version> 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)"