# Attaches binaries to a release when a version tag is pushed. # # Without this a release is a git tag, and installing llmgw on a node means # having a Go toolchain and the source. The onboarding script copies a binary # from wherever it is run, which works and quietly makes whoever runs it the # build server. name: Release on: push: tags: ["v*"] workflow_dispatch: jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: # Tags are what the version string is built from, and a shallow clone # has none of them. fetch-depth: 0 - uses: actions/setup-go@v5 with: go-version-file: go.mod cache: true - name: Build run: | set -euo pipefail version="${GITHUB_REF_NAME:-$(git describe --tags --always)}" mkdir -p dist # CGO_ENABLED=0 is the whole point: the binary has to run on a node # whose libc is older than the builder's, and llmgw has no C # dependency — modernc.org/sqlite is pure Go precisely so this stays # true. for target in linux/amd64 linux/arm64 darwin/amd64 darwin/arm64; do os="${target%/*}"; arch="${target#*/}" name="llmgw-${version}-${os}-${arch}" echo "building $name" CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" go build \ -trimpath \ -ldflags "-s -w -X gitea.mynodes.xyz/ilker/llmgw/internal/version.Version=${version}" \ -o "dist/${name}" ./cmd/llmgw (cd dist && sha256sum "${name}" >> checksums.txt) done # Proof the artifact runs at all before it is published. It cannot # test the cross-compiled ones, which is why the native build is # checked rather than assumed. ./dist/llmgw-${version}-linux-amd64 --version cat dist/checksums.txt - name: Attach to the release env: TOKEN: ${{ secrets.GITEA_TOKEN }} run: | set -euo pipefail if [ -z "${TOKEN:-}" ]; then echo "No GITEA_TOKEN secret, so nothing can be uploaded." echo "Add one in the repository's Actions settings with package or" echo "repository write scope; the binaries are in dist/ meanwhile." exit 1 fi tag="${GITHUB_REF_NAME}" api="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}" # The release usually exists already, created by hand with its notes. id=$(curl -sS -H "Authorization: token $TOKEN" "$api/releases/tags/$tag" \ | sed -n 's/.*"id":\([0-9]*\).*/\1/p' | head -1) if [ -z "$id" ]; then echo "creating release $tag" id=$(curl -sS -X POST -H "Authorization: token $TOKEN" \ -H "Content-Type: application/json" \ -d "{\"tag_name\":\"$tag\",\"name\":\"$tag\"}" \ "$api/releases" | sed -n 's/.*"id":\([0-9]*\).*/\1/p' | head -1) fi [ -n "$id" ] || { echo "could not find or create the release" >&2; exit 1; } for f in dist/*; do echo "uploading $(basename "$f")" curl -sS -X POST -H "Authorization: token $TOKEN" \ -F "attachment=@$f" \ "$api/releases/$id/assets?name=$(basename "$f")" >/dev/null done echo "attached $(ls dist | wc -l) files to $tag"