From af9fd33b2ac06d3ed5673e6f40e022a63a82b67a Mon Sep 17 00:00:00 2001 From: Snider Date: Sun, 1 Feb 2026 06:21:12 +0000 Subject: [PATCH] fix(release): add proper release workflow with version injection - Make AppVersion injectable via ldflags at build time - Replace GoReleaser with simple GitHub Actions workflow - Build for linux/darwin/windows on amd64/arm64 - Generate checksums.txt for integrity verification - Inject version from git tag into binary Fixes #37 Co-Authored-By: Claude Opus 4.5 --- .github/workflows/dev-release.yml | 3 +- .github/workflows/release.yml | 90 ++++++++++++++++++++++++------- pkg/cli/app.go | 7 ++- 3 files changed, 77 insertions(+), 23 deletions(-) diff --git a/.github/workflows/dev-release.yml b/.github/workflows/dev-release.yml index da50623a..a718f454 100644 --- a/.github/workflows/dev-release.yml +++ b/.github/workflows/dev-release.yml @@ -44,7 +44,8 @@ jobs: run: | EXT="" if [ "$GOOS" = "windows" ]; then EXT=".exe"; fi - go build -trimpath -ldflags="-s -w" -o core-${GOOS}-${GOARCH}${EXT} ./cmd/core + VERSION="dev-$(git rev-parse --short HEAD)" + go build -trimpath -ldflags="-s -w -X github.com/host-uk/core/pkg/cli.AppVersion=${VERSION}" -o core-${GOOS}-${GOARCH}${EXT} . - name: Upload artifact uses: actions/upload-artifact@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 419d0d88..4ba585ce 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: release +name: Release on: push: @@ -9,28 +9,78 @@ permissions: contents: write jobs: - goreleaser: + build: + runs-on: ubuntu-latest + strategy: + matrix: + include: + - goos: linux + goarch: amd64 + - goos: linux + goarch: arm64 + - goos: darwin + goarch: amd64 + - goos: darwin + goarch: arm64 + - goos: windows + goarch: amd64 + - goos: windows + goarch: arm64 + + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.24' + check-latest: true + + - name: Get version from tag + id: version + run: echo "VERSION=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT + + - name: Build CLI + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + CGO_ENABLED: '0' + run: | + EXT="" + if [ "$GOOS" = "windows" ]; then EXT=".exe"; fi + go build -trimpath \ + -ldflags="-s -w -X github.com/host-uk/core/pkg/cli.AppVersion=${{ steps.version.outputs.VERSION }}" \ + -o core-${GOOS}-${GOARCH}${EXT} . + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: core-${{ matrix.goos }}-${{ matrix.goarch }} + path: core-* + + release: + needs: build runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + + - name: Download all artifacts + uses: actions/download-artifact@v4 with: - fetch-depth: 0 - - uses: actions/setup-go@v5 - with: - go-version: '1.25' - check-latest: true - - name: Set up Node (for GUI builds if needed) - uses: actions/setup-node@v4 - with: - node-version: '22' - - name: Install Wails (optional) + path: artifacts + merge-multiple: true + + - name: Generate checksums run: | - go install github.com/wailsapp/wails/v3/cmd/wails3@latest || true - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v6 - with: - distribution: goreleaser - version: latest - args: release --clean + cd artifacts + sha256sum core-* > checksums.txt + cat checksums.txt + + - name: Create release env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release create ${{ github.ref_name }} \ + --title "${{ github.ref_name }}" \ + --generate-notes \ + artifacts/* diff --git a/pkg/cli/app.go b/pkg/cli/app.go index 9a3c0a09..0215a882 100644 --- a/pkg/cli/app.go +++ b/pkg/cli/app.go @@ -11,10 +11,13 @@ import ( const ( // AppName is the CLI application name. AppName = "core" - // AppVersion is the CLI application version. - AppVersion = "0.1.0" ) +// AppVersion is set at build time via ldflags: +// +// go build -ldflags="-X github.com/host-uk/core/pkg/cli.AppVersion=v1.0.0" +var AppVersion = "dev" + // Main initialises and runs the CLI application. // This is the main entry point for the CLI. // Exits with code 1 on error.