Skip to content

Commit 3aee80e

Browse files
caxu-rhacornett21
authored andcommitted
Print version information when using --version flag
Signed-off-by: Caleb Xu <[email protected]>
1 parent 9ddf921 commit 3aee80e

File tree

8 files changed

+178
-46
lines changed

8 files changed

+178
-46
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ARG OS
1212
# Build the preflight binary
1313
COPY . /go/src/preflight-trigger
1414
WORKDIR /go/src/preflight-trigger
15-
RUN make build
15+
RUN make build RELEASE_TAG=${release_tag}
1616

1717

1818
FROM registry.access.redhat.com/ubi9/ubi-micro:latest

Makefile

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ export CONTAINER_ENGINE ?= podman
88
export BIN_NAME
99
export REGISTRY ?= quay.io
1010
export REGISTRY_NAMESPACE ?= opdev
11+
VERSION=$(shell git rev-parse HEAD)
1112
export RELEASE_TAG ?= "0.0.0"
1213

1314

1415
.PHONY: binary-build
1516
binary-build:
16-
$(CONTAINER_ENGINE) run --rm -v $(PWD):/usr/src/$(BIN_NAME) -w /usr/src/$(BIN_NAME) -e GOOS=linux -e GOARCH=amd64 docker.io/library/golang:alpine go build -o $(BIN_NAME)
17+
$(CONTAINER_ENGINE) run --rm -v $(PWD):/usr/src/$(BIN_NAME) -w /usr/src/$(BIN_NAME) -e GOOS=linux -e GOARCH=amd64 docker.io/library/golang:alpine go build -ldflags "-X github.com/redhat-openshift-ecosystem/preflight-trigger/version.commit=$(VERSION) -X github.com/redhat-openshift-ecosystem/preflight-trigger/version.version=$(RELEASE_TAG)" -o $(BIN_NAME)
1718

1819
.PHONY: image-build
1920
image-build:
@@ -25,7 +26,7 @@ image-push:
2526

2627
.PHONY: build
2728
build:
28-
CGO_ENABLED=0 go build -o $(BIN_NAME) main.go
29+
CGO_ENABLED=0 go build -ldflags "-X github.com/redhat-openshift-ecosystem/preflight-trigger/version.commit=$(VERSION) -X github.com/redhat-openshift-ecosystem/preflight-trigger/version.version=$(RELEASE_TAG)" -o $(BIN_NAME) main.go
2930
@ls | grep -e '^preflight-trigger$$' &> /dev/null
3031

3132
.PHONY: vet
@@ -46,12 +47,18 @@ fmt: gofumpt
4647
lint: golangci-lint ## Run golangci-lint linter checks.
4748
$(GOLANGCI_LINT) run
4849

50+
.PHONY: test
51+
test:
52+
go test -v $$(go list ./...) \
53+
-ldflags "-X github.com/redhat-openshift-ecosystem/preflight-trigger/version.commit=bar -X github.com/redhat-openshift-ecosystem/preflight-trigger/version.version=foo"
54+
4955
.PHONY: cover
5056
cover:
5157
go test -v \
52-
$$(go list ./...) \
53-
-race \
54-
-cover -coverprofile=coverage.out
58+
$$(go list ./...) \
59+
-ldflags "-X github.com/redhat-openshift-ecosystem/preflight-trigger/version.commit=bar -X github.com/redhat-openshift-ecosystem/preflight-trigger/version.version=foo" \
60+
-race \
61+
-cover -coverprofile=coverage.out
5562

5663
GOFUMPT = $(shell pwd)/bin/gofumpt
5764
gofumpt: ## Download envtest-setup locally if necessary.

cmd/root.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010

1111
"github.com/spf13/cobra"
1212
configflagutil "sigs.k8s.io/prow/pkg/flagutil/config"
13+
14+
"github.com/redhat-openshift-ecosystem/preflight-trigger/version"
1315
)
1416

1517
type FlagsData struct {
@@ -58,9 +60,10 @@ var CommandFlags FlagsData
5860

5961
// rootCmd represents the base command when called without any subcommands
6062
var rootCmd = &cobra.Command{
61-
Use: "preflight-trigger",
62-
Short: "Create on-demand preflight jobs in openshift-ci system",
63-
Long: ``,
63+
Use: "preflight-trigger",
64+
Short: "Create on-demand preflight jobs in openshift-ci system",
65+
Long: ``,
66+
Version: version.Version.String(),
6467
}
6568

6669
// Execute adds all child commands to the root command and sets flags appropriately.

go.mod

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ require (
77
github.com/ghodss/yaml v1.0.0
88
github.com/gobuffalo/envy v1.10.2
99
github.com/google/go-github/v56 v56.0.0
10+
github.com/onsi/ginkgo/v2 v2.27.2
11+
github.com/onsi/gomega v1.38.2
1012
github.com/openshift/api v0.0.0-20251015135203-5d856d3e8354
1113
github.com/spf13/afero v1.15.0
1214
github.com/spf13/cobra v1.10.1
@@ -32,6 +34,7 @@ require (
3234
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.48.1 // indirect
3335
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.48.1 // indirect
3436
github.com/GoogleCloudPlatform/testgrid v0.0.123 // indirect
37+
github.com/Masterminds/semver/v3 v3.4.0 // indirect
3538
github.com/ProtonMail/go-crypto v1.3.0 // indirect
3639
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f // indirect
3740
github.com/andygrunwald/go-jira v1.17.0 // indirect
@@ -84,11 +87,12 @@ require (
8487
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
8588
github.com/go-kit/log v0.2.1 // indirect
8689
github.com/go-logfmt/logfmt v0.5.1 // indirect
87-
github.com/go-logr/logr v1.4.2 // indirect
90+
github.com/go-logr/logr v1.4.3 // indirect
8891
github.com/go-logr/stdr v1.2.2 // indirect
8992
github.com/go-openapi/jsonpointer v0.21.0 // indirect
9093
github.com/go-openapi/jsonreference v0.20.2 // indirect
9194
github.com/go-openapi/swag v0.23.0 // indirect
95+
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
9296
github.com/gogo/protobuf v1.3.2 // indirect
9397
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
9498
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
@@ -99,7 +103,7 @@ require (
99103
github.com/google/gnostic-models v0.7.0 // indirect
100104
github.com/google/go-cmp v0.7.0 // indirect
101105
github.com/google/go-querystring v1.1.0 // indirect
102-
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
106+
github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 // indirect
103107
github.com/google/s2a-go v0.1.9 // indirect
104108
github.com/google/uuid v1.6.0 // indirect
105109
github.com/google/wire v0.6.0 // indirect
@@ -156,24 +160,25 @@ require (
156160
go.yaml.in/yaml/v3 v3.0.4 // indirect
157161
go4.org v0.0.0-20201209231011-d4a079459e60 // indirect
158162
gocloud.dev v0.40.0 // indirect
159-
golang.org/x/crypto v0.39.0 // indirect
163+
golang.org/x/crypto v0.45.0 // indirect
160164
golang.org/x/exp v0.0.0-20250207012021-f9890c6ad9f3 // indirect
161-
golang.org/x/mod v0.26.0 // indirect
162-
golang.org/x/net v0.41.0 // indirect
165+
golang.org/x/mod v0.29.0 // indirect
166+
golang.org/x/net v0.47.0 // indirect
163167
golang.org/x/oauth2 v0.27.0 // indirect
164-
golang.org/x/sync v0.16.0 // indirect
165-
golang.org/x/sys v0.33.0 // indirect
166-
golang.org/x/term v0.32.0 // indirect
167-
golang.org/x/text v0.28.0 // indirect
168+
golang.org/x/sync v0.18.0 // indirect
169+
golang.org/x/sys v0.38.0 // indirect
170+
golang.org/x/term v0.37.0 // indirect
171+
golang.org/x/text v0.31.0 // indirect
168172
golang.org/x/time v0.10.0 // indirect
173+
golang.org/x/tools v0.38.0 // indirect
169174
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
170175
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
171176
google.golang.org/api v0.223.0 // indirect
172177
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 // indirect
173178
google.golang.org/genproto/googleapis/api v0.0.0-20250303144028-a0af3efb3deb // indirect
174179
google.golang.org/genproto/googleapis/rpc v0.0.0-20250303144028-a0af3efb3deb // indirect
175180
google.golang.org/grpc v1.72.1 // indirect
176-
google.golang.org/protobuf v1.36.6 // indirect
181+
google.golang.org/protobuf v1.36.7 // indirect
177182
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
178183
gopkg.in/fsnotify.v1 v1.4.7 // indirect
179184
gopkg.in/inf.v0 v0.9.1 // indirect

0 commit comments

Comments
 (0)