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 14
14
name : Upload binaries to release
15
15
runs-on : ubuntu-latest
16
16
steps :
17
+ - name : Set env
18
+ run : echo "RELEASE_TAG=${GITHUB_REF:10}" >> $GITHUB_ENV
17
19
- name : Check out code
18
20
uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag=v4.2.2
19
21
- name : Calculate go version
Original file line number Diff line number Diff line change @@ -39,7 +39,6 @@ export GOPROXY
39
39
# Active module mode, as we use go modules to manage dependencies
40
40
export GO111MODULE =on
41
41
42
- BRANCHVERSION := $(shell git symbolic-ref --short HEAD)
43
42
# Hosts running SELinux need :z added to volume mounts
44
43
SELINUX_ENABLED := $(shell cat /sys/fs/selinux/enforce 2> /dev/null || echo 0)
45
44
@@ -175,7 +174,7 @@ release-binary: $(RELEASE_DIR)
175
174
-v " $$ (pwd):/workspace$( DOCKER_VOL_OPTS) " \
176
175
-w /workspace/tools/setup-envtest \
177
176
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'" \
179
178
-o ./out/$(RELEASE_BINARY ) ./
180
179
181
180
# # --------------------------------------
Original file line number Diff line number Diff line change 53
53
index = flag .String ("index" , remote .DefaultIndexURL , "index to discover envtest binaries" )
54
54
55
55
// BranchVersion is the current setup-envtest branch that is used for the binary version of setup-envtest.
56
- BranchVersion = "unknown "
56
+ BranchVersion = ""
57
57
)
58
58
59
59
// TODO(directxman12): handle interrupts?
Original file line number Diff line number Diff line change 7
7
"context"
8
8
"fmt"
9
9
"io"
10
+ "runtime/debug"
10
11
11
12
"github.com/go-logr/logr"
12
13
@@ -95,5 +96,14 @@ type Version struct {
95
96
96
97
// Do executes the workflow.
97
98
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
+ }
98
108
fmt .Fprintf (env .Out , "setup-envtest version: %s\n " , v .BinaryVersion )
99
109
}
Original file line number Diff line number Diff line change 8
8
"fmt"
9
9
"io/fs"
10
10
"path/filepath"
11
+ "runtime/debug"
11
12
"sort"
12
13
"strings"
13
14
@@ -447,11 +448,20 @@ var _ = Describe("Workflows", func() {
447
448
Describe ("version" , func () {
448
449
It ("should print out the version based on the Binary Version" , func () {
449
450
v := wf.Version {
450
- BinaryVersion : "release-0 .18" ,
451
+ BinaryVersion : "v0 .18.2 " ,
451
452
}
452
453
v .Do (env )
453
454
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 )))
455
465
})
456
466
})
457
467
You can’t perform that action at this time.
0 commit comments