From 7ebed0f0aa1deffb8999594a89e4be97a7671b52 Mon Sep 17 00:00:00 2001 From: Axodouble Date: Tue, 12 May 2026 06:57:08 +0000 Subject: [PATCH] Added building and release tagging based builds --- .gitea/workflows/release.yaml | 58 +++++++++++++++++++++++++++++++++++ README.md | 19 ++++++++++++ cmd/qu/main.go | 6 +++- internal/cli/cli.go | 6 ++-- 4 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 .gitea/workflows/release.yaml diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml new file mode 100644 index 0000000..c8445ac --- /dev/null +++ b/.gitea/workflows/release.yaml @@ -0,0 +1,58 @@ +name: Release + +# Fires when a version tag is pushed (e.g. `git tag v0.1.0 && git push --tags`). +# Runs the test suite as a release gate, builds static Linux binaries +# for amd64 + arm64, and attaches them to a Gitea release named after +# the tag. +on: + push: + tags: + - 'v*' + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + check-latest: true + cache: true + + - name: Test + run: go test -race ./... + + - name: Build binaries + env: + CGO_ENABLED: '0' + run: | + set -euo pipefail + VERSION="${GITHUB_REF_NAME}" + mkdir -p dist + for arch in amd64 arm64; do + out="dist/qu-${VERSION}-linux-${arch}" + echo "building ${out}" + GOOS=linux GOARCH="${arch}" \ + go build \ + -trimpath \ + -ldflags "-s -w -X main.version=${VERSION}" \ + -o "${out}" \ + ./cmd/qu + done + (cd dist && sha256sum qu-* > SHA256SUMS) + ls -lh dist + + - name: Publish release + uses: https://gitea.com/actions/release-action@main + with: + files: |- + dist/qu-* + dist/SHA256SUMS + api_key: '${{ secrets.GITHUB_TOKEN }}' diff --git a/README.md b/README.md index 7f1610a..1d69939 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,25 @@ Requires Go 1.23 or newer. go build -o qu ./cmd/qu ``` +To stamp the version into the binary: + +```sh +go build -ldflags "-X main.version=v0.1.0" -o qu ./cmd/qu +qu --version +``` + +## Releases + +Pushing a tag matching `v*` triggers `.gitea/workflows/release.yaml`, +which runs the test suite, cross-compiles static Linux binaries for +amd64 and arm64, and publishes them as a Gitea release with a +`SHA256SUMS` file alongside. + +```sh +git tag v0.1.0 +git push --tags +``` + ## Set up a 3-node cluster On each host: diff --git a/cmd/qu/main.go b/cmd/qu/main.go index 971300f..150103f 100644 --- a/cmd/qu/main.go +++ b/cmd/qu/main.go @@ -13,8 +13,12 @@ import ( "git.cer.sh/axodouble/quptime/internal/cli" ) +// version is stamped at link time via `-ldflags "-X main.version=..."`. +// Falls back to "dev" for unreleased builds. +var version = "dev" + func main() { - if err := cli.NewRootCommand().Execute(); err != nil { + if err := cli.NewRootCommand(version).Execute(); err != nil { fmt.Fprintln(os.Stderr, "error:", err) os.Exit(1) } diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 2b9ecf9..6a459fa 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -8,11 +8,13 @@ package cli import "github.com/spf13/cobra" -// NewRootCommand returns the full cobra tree. -func NewRootCommand() *cobra.Command { +// NewRootCommand returns the full cobra tree. version is the build +// stamp surfaced via `qu --version`; pass "dev" when unset. +func NewRootCommand(version string) *cobra.Command { root := &cobra.Command{ Use: "qu", Short: "Quorum-based uptime monitor", + Version: version, SilenceUsage: true, SilenceErrors: true, }