Skip to content

Commit

Permalink
Autogenerate Version=<git revision>-<build time> (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
gshilin-sdb authored Nov 16, 2022
1 parent 7c3d5cc commit 086db00
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,4 @@ jobs:
f"/repos/{repository}/releases/{release}/assets?name={asset}"
),
)
response.raise_for_status()
response.raise_for_status()
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@ OUTPUT_DIR :=_output
# Constants
GOPATH := $(shell go env GOPATH)

# Version
revision:=$(shell git rev-parse --short HEAD)
build_time:=$(shell date +%D@%T)
version_stamp:=$(revision)-$(build_time)
# Set the linker flags so that the version will be included in the binaries:
import_path:=github.com/openshift-online/ocm-support-cli
ldflags:=-X $(import_path)/pkg/info.VersionStamp=$(version_stamp)

build: clean
go build -o ocm-support ./cmd/ocm-support || exit 1
go build -o ocm-support -ldflags="$(ldflags)" ./cmd/ocm-support || exit 1

install: clean
go build -o $(GOPATH)/bin/ocm-support ./cmd/ocm-support || exit 1
go build -o $(GOPATH)/bin/ocm-support -ldflags="$(ldflags)" ./cmd/ocm-support || exit 1

clean:
rm -f ocm-support

cmds:
for cmd in $$(ls cmd); do \
go build "./cmd/$${cmd}" || exit 1; \
go build -ldflags="$(ldflags)" "./cmd/$${cmd}" || exit 1; \
done

ensureOCM:
Expand Down
2 changes: 1 addition & 1 deletion cmd/ocm-support/version/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ var Cmd = &cobra.Command{
}

func run(cmd *cobra.Command, argv []string) {
_, _ = fmt.Fprintf(os.Stdout, "%s\n", info.Version)
_, _ = fmt.Fprintf(os.Stdout, "%s (build %s)\n", info.Version, info.VersionStamp)
}
2 changes: 2 additions & 0 deletions pkg/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ package info

// Version of the ocm-support-cli
const Version = "0.1.0"

var VersionStamp string

0 comments on commit 086db00

Please sign in to comment.