File tree 5 files changed +94
-1
lines changed
5 files changed +94
-1
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@692973e3d937129bcbf40652eb9f2f61becf3332 # tag=v4.1.7
19
21
- name : Calculate go version
Original file line number Diff line number Diff line change @@ -178,7 +178,8 @@ release-binary: $(RELEASE_DIR)
178
178
-v " $$ (pwd):/workspace$( DOCKER_VOL_OPTS) " \
179
179
-w /workspace \
180
180
golang:$(GO_VERSION ) \
181
- go build -a -trimpath -ldflags " -extldflags '-static'" \
181
+ go build -a -trimpath \
182
+ -ldflags " -extldflags '-static' -X sigs.k8s.io/controller-tools/pkg/version.version=$( RELEASE_TAG) " \
182
183
-o ./out/$(RELEASE_BINARY ) ./cmd/controller-gen
183
184
184
185
# # --------------------------------------
Original file line number Diff line number Diff line change @@ -22,8 +22,16 @@ import (
22
22
"runtime/debug"
23
23
)
24
24
25
+ // version to be set using ldflags:
26
+ // -ldflags "-X sigs.k8s.io/controller-tools/pkg/version.version=v1.0.0"
27
+ // falls back to module information is unset
28
+ var version = ""
29
+
25
30
// Version returns the version of the main module
26
31
func Version () string {
32
+ if version != "" {
33
+ return version
34
+ }
27
35
info , ok := debug .ReadBuildInfo ()
28
36
if ! ok || info == nil || info .Main .Version == "" {
29
37
// binary has not been built with module support or doesn't contain a version.
Original file line number Diff line number Diff line change
1
+ /*
2
+ Copyright 2024 The Kubernetes Authors.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ package version
18
+
19
+ import (
20
+ "testing"
21
+
22
+ . "github.com/onsi/ginkgo"
23
+ . "github.com/onsi/gomega"
24
+ )
25
+
26
+ func TestVersioning (t * testing.T ) {
27
+ RegisterFailHandler (Fail )
28
+ RunSpecs (t , "Test Version Suite" )
29
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ Copyright 2024 The Kubernetes Authors.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ package version
18
+
19
+ import (
20
+ . "github.com/onsi/ginkgo"
21
+ . "github.com/onsi/gomega"
22
+ )
23
+
24
+ var _ = Describe ("TestVersion" , func () {
25
+ tests := []struct {
26
+ name string
27
+ version string
28
+ expected string
29
+ }{
30
+ {
31
+ name : "empty returns unknown" ,
32
+ version : "" ,
33
+ expected : "(unknown)" ,
34
+ },
35
+ {
36
+ name : "set to a value returns it" ,
37
+ version : "1.2.3" ,
38
+ expected : "1.2.3" ,
39
+ },
40
+ }
41
+ for _ , tc := range tests {
42
+ It ("Version set to " + tc .name , func () {
43
+ versionBackup := version
44
+ defer func () {
45
+ version = versionBackup
46
+ }()
47
+ version = tc .version
48
+ result := Version ()
49
+ Expect (result ).To (Equal (tc .expected ))
50
+ })
51
+ }
52
+ })
53
+
You can’t perform that action at this time.
0 commit comments