Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ builds:
- CGO_ENABLED=0
ldflags:
- -X github.com/openshift/rosa/pkg/info.Build={{ .ShortCommit }}
- -X github.com/openshift/rosa/pkg/info.DefaultVersion={{ .Version }}
goos:
- linux
- windows
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ export CGO_ENABLED=0
# Unset GOFLAG for CI and ensure we've got nothing accidently set
unexport GOFLAGS

# Version from the exact tag on HEAD; empty (uses the fallback in pkg/info/info.go)
# when HEAD is not tagged.
VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null | sed 's/^v//')

.PHONY: rosa
rosa:
go build -ldflags="-X github.com/openshift/rosa/pkg/info.Build=$(shell git rev-parse --short HEAD)" ./cmd/rosa
go build -ldflags="-X github.com/openshift/rosa/pkg/info.Build=$(shell git rev-parse --short HEAD) $(if $(VERSION),-X github.com/openshift/rosa/pkg/info.DefaultVersion=$(VERSION),)" ./cmd/rosa

.PHONY: test
test:
Expand All @@ -55,7 +59,7 @@ coverage-changed-files:

.PHONY: install
install:
go install -ldflags="-X github.com/openshift/rosa/pkg/info.Build=$(shell git rev-parse --short HEAD)" ./cmd/rosa
go install -ldflags="-X github.com/openshift/rosa/pkg/info.Build=$(shell git rev-parse --short HEAD) $(if $(VERSION),-X github.com/openshift/rosa/pkg/info.DefaultVersion=$(VERSION),)" ./cmd/rosa

.PHONY: fmt
fmt: $(GCI)
Expand Down
7 changes: 6 additions & 1 deletion hack/build_cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ oses=(darwin linux windows)
mkdir -p releases

build_release() {
# Resolve exact tag on HEAD (stable or prerelease). Prerelease builds
# intentionally report the prerelease version (e.g. 1.2.66-rc1).
release_version=$(git describe --tags --exact-match 2>/dev/null || true)
release_version=${release_version#v}

for os in "${oses[@]}"
do
for arch in "${archs[@]}"
Expand All @@ -19,7 +24,7 @@ do
fi
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
GOOS="${os}" GOARCH="${arch}" go build -ldflags="-X github.com/openshift/rosa/pkg/info.Build=$(git rev-parse --short HEAD)" -o "${tmpdir}/rosa${extension}" ./cmd/rosa
GOOS="${os}" GOARCH="${arch}" go build -ldflags="-X github.com/openshift/rosa/pkg/info.Build=$(git rev-parse --short HEAD)${release_version:+ -X github.com/openshift/rosa/pkg/info.DefaultVersion=${release_version}}" -o "${tmpdir}/rosa${extension}" ./cmd/rosa
tar -czf "releases/rosa_${os}_${arch}.tar.gz" -C "${tmpdir}" "rosa${extension}"
(
cd "${tmpdir}" && \
Expand Down
7 changes: 5 additions & 2 deletions pkg/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ limitations under the License.

package info

const DefaultVersion = "1.2.65"
// DefaultVersion is the CLI version. For release builds it is overridden via
// -ldflags with the value derived from the git tag. The fallback here is kept
// current by an automated post-release workflow.
var DefaultVersion = "1.2.65"

// Build contains the short Git SHA of the CLI at the point it was build. Set via `-ldflags` at build time
// Build contains the short Git SHA of the CLI at the point it was built. Set via `-ldflags` at build time.
var Build = "local"

const DefaultUserAgent = "ROSACLI"