hub/.forgejo/workflows/release.yml
trvon 0d7a219c5d
Some checks failed
release / build (push) Failing after 2m13s
hub: operator CLI with signed self-update
2026-11-10 20:32:32 -07:00

98 lines
4.5 KiB
YAML

# hub CI and release lane.
#
# Test lane: push to ci/**, pull requests, or manual run -> go vet, go test, python probe tests. Nothing is uploaded.
# Release lane: push a tag v* -> the same, then static linux-amd64 and darwin-arm64 binaries are built with the tag
# version, a draft release gets each binary and its .sha256, and is published only if everything passed.
#
# Trust anchor: the signed annotated tag, not this workflow. `hub self-update` verifies the tag signature against pinned
# fingerprints and the asset sha256 itself (docs/releasing.md). Cut tags with scripts/release.sh.
# Forgejo reads .forgejo/workflows and then ignores .github/workflows.
name: release
concurrency:
group: release-${{ github.sha }}
# Never cancel a tag/release run; only a branch run for the same sha may be superseded.
cancel-in-progress: ${{ github.ref_type != 'tag' }}
on:
workflow_dispatch:
push:
branches: ["ci/**"]
tags: ["v*"]
pull_request:
jobs:
build:
runs-on: docker
timeout-minutes: 30
container:
image: debian:trixie
env:
CI: "true"
CGO_ENABLED: "0"
GOTOOLCHAIN: auto # go.mod needs a newer Go than debian ships; the stock go fetches the pinned toolchain via the Go module proxy
steps:
- name: Checkout
env:
TOKEN: ${{ github.token }}
run: |
apt-get update -q && apt-get install -y -q --no-install-recommends git ca-certificates curl python3 gnupg golang-go file >/dev/null
git init -q . && git -c http.extraHeader="Authorization: token $TOKEN" fetch -q --depth 50 --tags \
"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git" "$GITHUB_SHA"
git checkout -q FETCH_HEAD
git log -1 --format='building %H %s'
go version
- name: Vet and test
run: |
go vet ./...
go test -count=1 ./...
python3 -m unittest discover -s probe -p "test_*.py"
- name: Build, stamp, check version
run: |
if [ "$GITHUB_REF_TYPE" = "tag" ]; then
version=${GITHUB_REF_NAME#v}
echo "$version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$' || { echo "tag $GITHUB_REF_NAME is not vX.Y.Z" >&2; exit 1; }
else
version="0.0.0-ci+g$(git rev-parse --short=12 HEAD)"
fi
mkdir -p dist
for target in linux-amd64 darwin-arm64; do
goos=${target%-*}; goarch=${target#*-}
name="hub-${version}-${target}"
GOOS=$goos GOARCH=$goarch go build -trimpath \
-ldflags "-s -w -X git.trevon.dev/trevon/hub/internal/version.Version=${version}" \
-o "dist/$name" ./cmd/hub
(cd dist && sha256sum "$name" > "$name.sha256")
done
reported=$(dist/hub-${version}-linux-amd64 version)
if [ "$reported" != "hub ${version}" ]; then
echo "linux binary reports '$reported', expected 'hub ${version}'" >&2
exit 1
fi
file dist/hub-${version}-linux-amd64 dist/hub-${version}-darwin-arm64
cat dist/*.sha256
- name: Create draft release and upload
if: github.ref_type == 'tag'
env:
TOKEN: ${{ secrets.RELEASE_TOKEN || github.token }}
run: |
api="$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY"
body=$(python3 -c 'import json,os; t=os.environ["GITHUB_REF_NAME"]; print(json.dumps({"tag_name": t, "name": t, "draft": True, "body": "hub " + t + ". Install or update with `hub self-update`; it verifies the signed tag and the .sha256 assets."}))')
curl -sf -X POST -H "Authorization: token $TOKEN" -H 'Content-Type: application/json' -d "$body" "$api/releases" > release.json
id=$(python3 -c 'import json; print(json.load(open("release.json"))["id"])')
echo "draft release id=$id"
for f in dist/*; do
curl -sf -X POST -H "Authorization: token $TOKEN" -F "attachment=@$f" \
"$api/releases/$id/assets?name=$(basename "$f")" >/dev/null
echo "uploaded $(basename "$f")"
done
echo "$id" > release.id
- name: Publish release
if: github.ref_type == 'tag'
env:
TOKEN: ${{ secrets.RELEASE_TOKEN || github.token }}
run: |
id=$(cat release.id)
curl -sf -X PATCH -H "Authorization: token $TOKEN" -H 'Content-Type: application/json' \
-d '{"draft": false}' "$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY/releases/$id" >/dev/null
echo "published release $id"