release-fork.fish

  1#!/usr/bin/env fish
  2
  3# Release script for fork tags. Computes the next -fork.N tag from the
  4# latest upstream version, has Crush update the README version string
  5# (amending HEAD), pushes the branch, tags, pushes the tag, then
  6# cross-compiles, packs with UPX, and uploads to the releases server.
  7
  8set -l targets \
  9    linux/amd64 \
 10    linux/arm64 \
 11    darwin/amd64 \
 12    darwin/arm64 \
 13    windows/amd64 \
 14    freebsd/amd64
 15
 16# UPX 5.x dropped macOS support; windows/amd64 is PE32 only and
 17# freebsd/amd64 is ELF32 only, so only Linux targets are packed.
 18set -l pack_targets \
 19    linux-amd64 \
 20    linux-arm64
 21
 22# --- Guards ---
 23
 24set -l branch (git symbolic-ref --short HEAD)
 25if test "$branch" != dev
 26    echo "Error: not on dev branch (on $branch)" >&2
 27    exit 1
 28end
 29
 30if test (git status --porcelain=2 | wc -l) -ne 0
 31    echo "Error: git working tree is dirty" >&2
 32    exit 1
 33end
 34
 35# --- Fetch tags ---
 36
 37git tag -d nightly 2>/dev/null; or true
 38git fetch upstream --tags
 39
 40# --- Compute next fork tag ---
 41
 42set -l upstream_version (git tag -l "v*" | sort -V | tail -1; or echo v0.0.0)
 43set -l existing (git tag -l "$upstream_version-fork.*" | wc -l | string trim)
 44set -l next_num (math $existing + 1)
 45set -l tag "$upstream_version-fork.$next_num"
 46
 47# --- Confirm creation ---
 48
 49read -P "Create fork release $tag? [y/N] " confirm
 50if test "$confirm" != y -a "$confirm" != Y
 51    echo Aborted.
 52    exit 0
 53end
 54
 55# --- Update README via Crush and amend HEAD ---
 56
 57crush run -m kimi-k2.5h "Please update the mentioned version in the top of the README to $tag.
 58You only need to read the first 65 lines for the relevant bits.
 59If the content is already correct, you don't need to do anything.
 60Amend the commit at HEAD, updating its subject/message if necessary.
 61Use the skill."
 62
 63echo
 64git show --stat HEAD
 65
 66# --- Confirm amended commit ---
 67
 68read -P "Proceed with tagging? [y/N] " confirm
 69if test "$confirm" != y -a "$confirm" != Y
 70    echo "Aborting — restoring pre-amend commit."
 71    git reset --hard 'HEAD@{1}'
 72    exit 0
 73end
 74
 75# --- Push branch (force because we amended) ---
 76
 77git push --force-with-lease; or begin
 78    echo "Error: branch push failed" >&2
 79    exit 1
 80end
 81
 82# --- Tag and push ---
 83
 84git tag -a $tag; or begin
 85    echo "Error: tagging failed" >&2
 86    exit 1
 87end
 88
 89git push soft $tag; or begin
 90    echo "Error: tag push failed — deleting local tag" >&2
 91    git tag -d $tag 2>/dev/null
 92    exit 1
 93end
 94
 95echo "Released $tag"
 96
 97# --- Cross-compile ---
 98
 99set -l ldflags "-s -w -X git.secluded.site/crush/internal/version.Version=$tag"
100
101rm -rf dist
102mkdir -p dist
103
104for target in $targets
105    set -l os (echo $target | cut -d/ -f1)
106    set -l arch (echo $target | cut -d/ -f2)
107    set -l ext ""
108    if test "$os" = windows
109        set ext .exe
110    end
111
112    echo "Building $os/$arch..."
113    env CGO_ENABLED=0 GOEXPERIMENT=greenteagc GOOS=$os GOARCH=$arch \
114        go build -o "dist/crush-$tag-$os-$arch$ext" -ldflags "$ldflags"; or begin
115        echo "Error: build failed for $os/$arch" >&2
116        exit 1
117    end
118end
119
120# --- Pack with UPX ---
121
122for suffix in $pack_targets
123    set -l bin "dist/crush-$tag-$suffix"
124    if test -f "$bin"
125        echo "Packing $suffix..."
126        upx -q "$bin"
127    end
128end
129
130# --- Upload ---
131
132fish -c "release upload crush $tag --latest dist/*"
133
134echo "Done — $tag built, packed, and uploaded."