File tree Expand file tree Collapse file tree 5 files changed +26
-5
lines changed Expand file tree Collapse file tree 5 files changed +26
-5
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change @@ -39,7 +39,6 @@ export GOPROXY
3939# Active module mode, as we use go modules to manage dependencies
4040export GO111MODULE =on
4141
42- BRANCHVERSION := $(shell git symbolic-ref --short HEAD)
4342# Hosts running SELinux need :z added to volume mounts
4443SELINUX_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# # --------------------------------------
Original file line number Diff line number Diff line change 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?
Original file line number Diff line number Diff line change 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.
9798func (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 not been built with module support or doesn't contain a version.
104+ version = info .Main .Version
105+ }
106+ v .BinaryVersion = version
107+ }
98108 fmt .Fprintf (env .Out , "setup-envtest version: %s\n " , v .BinaryVersion )
99109}
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments