Skip to content

Commit ac24b76

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

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
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: 11 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,15 @@ type Version struct {
9596

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

0 commit comments

Comments
 (0)