From f8bc389ae5cc8e52dff177fb316e63a28cb39418 Mon Sep 17 00:00:00 2001 From: Paolo Donadeo Date: Fri, 10 Jul 2026 00:13:35 +0200 Subject: [PATCH] ci: derive binary version from git describe instead of a hardcoded string main.go's version var now defaults to "dev" for local builds and is overridden at build time via -ldflags "-X main.version=...". The release workflow computes VERSION with `git describe --tags --always --dirty` (fetch-depth: 0 so tags are available) and injects it into the Go build inside the container. --- .gitea/workflows/release.yml | 7 ++++++- main.go | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index acccbcc..3c94d96 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -26,11 +26,16 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Build (${{ matrix.arch }}) run: | set -o pipefail + VERSION="$(git describe --tags --always --dirty)" + echo "Version: $VERSION" + # Crea il container senza avviarlo CID=$(docker create \ --platform ${{ matrix.platform }} \ @@ -46,7 +51,7 @@ jobs: docker exec "$CID" sh -c " ${{ matrix.upx_install }} export CGO_ENABLED=0 - go build -trimpath -ldflags='-s -w' -o /src/dist/todotxt2remind . + go build -trimpath -ldflags='-s -w -X main.version=$VERSION' -o /src/dist/todotxt2remind . upx /src/dist/todotxt2remind " 2>&1 | cat diff --git a/main.go b/main.go index 1a9494f..62c3a6a 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ var ( outputFile string debug bool indent int - version = "v3.0.0" + version = "dev" // overridden at build time via -ldflags "-X main.version=..." ) func main() {