Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"}'
14 changes: 13 additions & 1 deletion cmd/wfctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)" {
Expand Down
25 changes: 25 additions & 0 deletions cmd/wfctl/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"flag"
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -85,6 +87,29 @@ func TestBuildVersionStripsDirtyMarker(t *testing.T) {
}
}

func TestLinkedVersionOverridesBuildInfo(t *testing.T) {
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 {
Comment thread
intel352 marked this conversation as resolved.
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)
Expand Down
Loading