Skip to content

Commit 51c6d75

Browse files
committed
set to release tag and fill if empty
Signed-off-by: Troy Connor <[email protected]>
1 parent e6fb8d3 commit 51c6d75

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

.github/workflows/release.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
name: Upload binaries to release
1515
runs-on: ubuntu-latest
1616
steps:
17+
- name: Set env
18+
run: echo "RELEASE_TAG=${GITHUB_REF:10}" >> $GITHUB_ENV
1719
- name: Check out code
1820
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag=v4.2.2
1921
- name: Calculate go version

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export GOPROXY
3939
# Active module mode, as we use go modules to manage dependencies
4040
export GO111MODULE=on
4141

42-
BRANCHVERSION := $(shell git symbolic-ref --short HEAD)
4342
# Hosts running SELinux need :z added to volume mounts
4443
SELINUX_ENABLED := $(shell cat /sys/fs/selinux/enforce 2> /dev/null || echo 0)
4544

@@ -175,7 +174,7 @@ release-binary: $(RELEASE_DIR)
175174
-v "$$(pwd):/workspace$(DOCKER_VOL_OPTS)" \
176175
-w /workspace/tools/setup-envtest \
177176
golang:$(GO_VERSION) \
178-
go build -a -trimpath -ldflags "-X 'main.BranchVersion=$(BRANCHVERSION)' -extldflags '-static'" \
177+
go build -a -trimpath -ldflags "-X 'main.BranchVersion=$(RELEASE_TAG)' -extldflags '-static'" \
179178
-o ./out/$(RELEASE_BINARY) ./
180179

181180
## --------------------------------------

tools/setup-envtest/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var (
5353
index = flag.String("index", remote.DefaultIndexURL, "index to discover envtest binaries")
5454

5555
// BranchVersion is the current setup-envtest branch that is used for the binary version of setup-envtest.
56-
BranchVersion = "unknown"
56+
BranchVersion = ""
5757
)
5858

5959
// TODO(directxman12): handle interrupts?

tools/setup-envtest/workflows/workflows.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"fmt"
99
"io"
10+
"runtime/debug"
1011

1112
"github.com/go-logr/logr"
1213

@@ -95,5 +96,14 @@ type Version struct {
9596

9697
// Do executes the workflow.
9798
func (v Version) Do(env *envp.Env) {
99+
version := "(unknown)"
100+
if v.BinaryVersion == "" {
101+
info, ok := debug.ReadBuildInfo()
102+
if ok && info != nil && info.Main.Version != "" {
103+
// binary has been built with module support.
104+
version = info.Main.Version
105+
}
106+
v.BinaryVersion = version
107+
}
98108
fmt.Fprintf(env.Out, "setup-envtest version: %s\n", v.BinaryVersion)
99109
}

tools/setup-envtest/workflows/workflows_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"io/fs"
1010
"path/filepath"
11+
"runtime/debug"
1112
"sort"
1213
"strings"
1314

@@ -447,11 +448,20 @@ var _ = Describe("Workflows", func() {
447448
Describe("version", func() {
448449
It("should print out the version based on the Binary Version", func() {
449450
v := wf.Version{
450-
BinaryVersion: "release-0.18",
451+
BinaryVersion: "v0.18.2",
451452
}
452453
v.Do(env)
453454
Expect(out.String()).ToNot(BeEmpty())
454-
Expect(out.String()).To(Equal("setup-envtest version: release-0.18\n"))
455+
Expect(out.String()).To(Equal("setup-envtest version: v0.18.2\n"))
456+
})
457+
458+
It("should print out the version if the RELEASE_TAG is empty", func() {
459+
v := wf.Version{}
460+
v.Do(env)
461+
info, ok := debug.ReadBuildInfo()
462+
Expect(ok).To(BeTrue())
463+
Expect(out.String()).ToNot(BeEmpty())
464+
Expect(out.String()).To(Equal(fmt.Sprintf("setup-envtest version: %s\n", info.Main.Version)))
455465
})
456466
})
457467

0 commit comments

Comments
 (0)