-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename import to add, add version cmd
- Loading branch information
Showing
35 changed files
with
208 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.idea | ||
.DS_Store | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
MODULE ?= github.com/askolesov/image-vault | ||
PACKAGE ?= ./... | ||
OUTPUT ?= build/ | ||
|
||
VERSION ?= $(shell git describe --tags --abbrev=0 2>/dev/null) | ||
BRANCH ?= $(shell git symbolic-ref -q --short HEAD 2>/dev/null) | ||
COMMIT_HASH ?= $(shell git rev-parse --short HEAD 2>/dev/null) | ||
BUILD_DATE ?= $(shell date +%FT%T%z) | ||
|
||
GOARGS += -v | ||
LDFLAGS += -s -w -X ${MODULE}/pkg/buildinfo.version=${VERSION} \ | ||
-X ${MODULE}/pkg/buildinfo.commitHash=${COMMIT_HASH} \ | ||
-X ${MODULE}/pkg/buildinfo.buildDate=${BUILD_DATE} \ | ||
-X ${MODULE}/pkg/buildinfo.branch=${BRANCH} | ||
|
||
.PHONY: run | ||
run: | ||
go run ${GOARGS} -tags "${GOTAGS}" -ldflags "${LDFLAGS}" ${PACKAGE} | ||
|
||
.PHONY: build | ||
build: | ||
go build ${GOARGS} -tags "${GOTAGS}" -ldflags "${LDFLAGS}" -o ${OUTPUT} ${PACKAGE} | ||
|
||
.PHONY: install | ||
install: | ||
go install ${GOARGS} -tags "${GOTAGS}" -ldflags "${LDFLAGS}" ${PACKAGE} | ||
|
||
.PHONY: test | ||
test: | ||
go test -count=1 -v ./... | ||
|
||
.PHONY: build-clean | ||
build-clean: | ||
rm -rf ${OUTPUT} | ||
|
||
.PHONY: lint | ||
lint: | ||
golangci-lint run -v | ||
|
||
.PHONY: pre-push | ||
pre-push: | ||
go mod tidy | ||
make lint | ||
make test | ||
make build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package buildinfo | ||
|
||
import ( | ||
"runtime" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
// Provisioned by ldflags | ||
var ( | ||
version string | ||
branch string | ||
commitHash string | ||
buildDate string | ||
) | ||
|
||
type BuildInfo struct { | ||
Version string `json:"version"` | ||
Branch string `json:"branch"` | ||
CommitHash string `json:"commit_hash"` | ||
BuildDate string `json:"build_date"` | ||
GoVersion string `json:"go_version"` | ||
GoOS string `json:"go_os"` | ||
GoArch string `json:"go_arch"` | ||
Compiler string `json:"compiler"` | ||
} | ||
|
||
func Get() *BuildInfo { | ||
return &BuildInfo{ | ||
Version: version, | ||
Branch: branch, | ||
CommitHash: commitHash, | ||
BuildDate: buildDate, | ||
GoVersion: runtime.Version(), | ||
GoOS: runtime.GOOS, | ||
GoArch: runtime.GOARCH, | ||
Compiler: runtime.Compiler, | ||
} | ||
} | ||
|
||
// YAML returns build info in compressed yaml format | ||
func (b *BuildInfo) YAML() []byte { | ||
res, err := yaml.Marshal(b) //nolint: musttag | ||
if err != nil { | ||
panic(err) // should never happen | ||
} | ||
|
||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package command | ||
|
||
import ( | ||
"github.com/askolesov/image-vault/pkg/buildinfo" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func GetVersionCmd() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "version", | ||
Short: "Display version information", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
info := buildinfo.Get() | ||
cmd.Println(string(info.YAML())) | ||
return nil | ||
}, | ||
} | ||
} |
Oops, something went wrong.