Skip to content

Commit

Permalink
chore: setup build-info package and env variables in Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
vprasanth committed Mar 9, 2021
1 parent 666d061 commit a0e4bf1
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
#!/usr/bin/env make

# setup variables
NAME := auth0-cli
PKG := github.com/auth0/$(NAME)
BUILDINFOPKG := $(PKG)/internal/build-info

## setup variables for build-info
BUILDUSER := $(shell whoami)
BUILDTIME := $(shell date -u '+%Y-%m-%d %H:%M:%S')
VERSION := $(GITCOMMIT)
#BUILDVERSION := $(shell git describe --exact-match --abbrev=0)
GITCOMMIT := $(shell git rev-parse --short HEAD)

GITUNTRACKEDCHANGES := $(shell git status --porcelain --untracked-files=no)
ifneq ($(GITUNTRACKEDCHANGES),)
GITCOMMIT := $(GITCOMMIT)-dirty
endif

GITBRANCH ?= $(shell git rev-parse --verify --abbrev-ref HEAD)
CTIMEVAR = -X '$(BUILDINFOPKG).Version=$(VERSION)' \
-X '$(BUILDINFOPKG).Revision=$(GITCOMMIT)' \
-X '$(BUILDINFOPKG).Branch=$(GITBRANCH)' \
-X '$(BUILDINFOPKG).BuildUser=$(BUILDUSER)' \
-X '$(BUILDINFOPKG).BuildDate=$(BUILDTIME)'


generate:
go generate ./...
.PHONY: generate
Expand Down
40 changes: 40 additions & 0 deletions internal/build-info/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package buildinfo

import (
"runtime"
)

var (
Version string
Revision string
Branch string
BuildUser string
BuildDate string
GoVersion = runtime.Version()
)

type BuildInfo struct {
Version string
Revision string
Branch string
BuildUser string
BuildDate string
GoVersion string
}

// NewDefaultBuildInfo returns the build information obtained from ldflags
func NewDefaultBuildInfo() BuildInfo {
return NewBuildInfo(Version, Branch, BuildDate, BuildUser, GoVersion, Revision)
}

// NewBuildInfo returns an object with the build information
func NewBuildInfo(version, branch, buildDate, buildUser, goVersion, revision string) BuildInfo {
return BuildInfo{
Version: version,
Branch: branch,
BuildDate: buildDate,
BuildUser: buildUser,
GoVersion: goVersion,
Revision: revision,
}
}

0 comments on commit a0e4bf1

Please sign in to comment.