From 1f6ad87ae72e0a7d5ad88dd2b94caf9928857a55 Mon Sep 17 00:00:00 2001 From: Jon Langevin Date: Thu, 21 May 2026 02:01:20 -0400 Subject: [PATCH 1/2] fix: preserve wfctl release version --- .github/workflows/release.yml | 14 ++++++++++++++ cmd/wfctl/main.go | 14 +++++++++++++- cmd/wfctl/main_test.go | 20 ++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a1f11f99..29044d1e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -333,3 +333,17 @@ jobs: repository: ${{ matrix.repo }} event-type: workflow-release client-payload: '{"version": "${{ env.TAG_NAME }}"}' + + notify-workflow-registry: + name: Notify workflow-registry + runs-on: ubuntu-latest + needs: release + if: ${{ !contains(inputs.tag_name || github.ref_name, '-') }} + steps: + - name: Trigger registry manifest sync + uses: peter-evans/repository-dispatch@v4 + with: + token: ${{ secrets.repo_dispatch_token }} + repository: GoCodeAlone/workflow-registry + event-type: workflow-release + client-payload: '{"workflow": "${{ github.repository }}", "version": "${{ env.TAG_NAME }}"}' diff --git a/cmd/wfctl/main.go b/cmd/wfctl/main.go index ecc00100..8ca35715 100644 --- a/cmd/wfctl/main.go +++ b/cmd/wfctl/main.go @@ -28,7 +28,19 @@ import ( //go:embed wfctl.yaml var wfctlConfigBytes []byte -var version = buildVersion() +// version is set by release builds via: +// +// go build -ldflags "-X main.version=vX.Y.Z" +// +// Keep the declaration as a constant string initializer so the linker can +// override it. init falls back to Go build metadata for module-installed builds. +var version = "dev" + +func init() { + if version == "dev" { + version = buildVersion() + } +} func buildVersion() string { if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "" && info.Main.Version != "(devel)" { diff --git a/cmd/wfctl/main_test.go b/cmd/wfctl/main_test.go index 44be4d52..669eb5f7 100644 --- a/cmd/wfctl/main_test.go +++ b/cmd/wfctl/main_test.go @@ -6,6 +6,7 @@ import ( "flag" "fmt" "os" + "os/exec" "path/filepath" "strings" "testing" @@ -85,6 +86,25 @@ func TestBuildVersionStripsDirtyMarker(t *testing.T) { } } +func TestLinkedVersionOverridesBuildInfo(t *testing.T) { + exe := filepath.Join(t.TempDir(), "wfctl") + build := exec.Command("go", "build", "-o", exe, "-ldflags", "-X main.version=v9.9.9", ".") + build.Env = append(os.Environ(), "GOWORK=off") + if out, err := build.CombinedOutput(); err != nil { + t.Fatalf("go build wfctl: %v\n%s", err, out) + } + + run := exec.Command(exe, "--version") + run.Env = append(os.Environ(), "WFCTL_NO_UPDATE_CHECK=1", "CI=true") + out, err := run.CombinedOutput() + if err != nil { + t.Fatalf("wfctl --version: %v\n%s", err, out) + } + if got := strings.TrimSpace(string(out)); got != "v9.9.9" { + t.Fatalf("linked version = %q, want v9.9.9", got) + } +} + func writeTestConfig(t *testing.T, dir, name, content string) string { t.Helper() path := filepath.Join(dir, name) From b925bd1df93a1d974d5f62d8e3f69e89f3a9262d Mon Sep 17 00:00:00 2001 From: Jon Langevin Date: Thu, 21 May 2026 02:15:38 -0400 Subject: [PATCH 2/2] test: use platform-specific wfctl binary name --- cmd/wfctl/main_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/wfctl/main_test.go b/cmd/wfctl/main_test.go index 669eb5f7..54407f7a 100644 --- a/cmd/wfctl/main_test.go +++ b/cmd/wfctl/main_test.go @@ -8,6 +8,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "strings" "testing" @@ -87,7 +88,11 @@ func TestBuildVersionStripsDirtyMarker(t *testing.T) { } func TestLinkedVersionOverridesBuildInfo(t *testing.T) { - exe := filepath.Join(t.TempDir(), "wfctl") + exeName := "wfctl" + if runtime.GOOS == "windows" { + exeName += ".exe" + } + exe := filepath.Join(t.TempDir(), exeName) build := exec.Command("go", "build", "-o", exe, "-ldflags", "-X main.version=v9.9.9", ".") build.Env = append(os.Environ(), "GOWORK=off") if out, err := build.CombinedOutput(); err != nil {