https://github.com/metal-stack/v
v is a small helper to add version information to your go project.
https://github.com/metal-stack/v
git golang makefile versioning
Last synced: 6 months ago
JSON representation
v is a small helper to add version information to your go project.
- Host: GitHub
- URL: https://github.com/metal-stack/v
- Owner: metal-stack
- License: mit
- Created: 2019-05-30T09:21:30.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-02-27T16:24:02.000Z (almost 5 years ago)
- Last Synced: 2025-02-28T22:13:21.847Z (11 months ago)
- Topics: git, golang, makefile, versioning
- Language: Go
- Size: 9.77 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# v
[](https://github.com/metal-stack/v/actions)
[](https://goreportcard.com/report/github.com/metal-stack/v)
[](https://pkg.go.dev/github.com/metal-stack/v)
[](https://codecov.io/gh/metal-stack/v)
[](https://github.com/metal-stack/v/blob/master/LICENSE)
v simplifies printing version information of an application.
## Quickstart
Add the following to your main.go
```go
package main
import (
"log"
"github.com/metal-stack/v"
)
func main() {
log.Info("application", "version", v.V)
}
```
Modify you build target in the Makefile:
```Makefile
.ONESHELL:
SHA := $(shell git rev-parse --short=8 HEAD)
GITVERSION := $(shell git describe --long --all)
BUILDDATE := $(shell date -Iseconds)
VERSION := $(or ${VERSION},devel)
BINARY := application
${BINARY}: clean test
GGO_ENABLED=0 \
GO111MODULE=on \
go build \
-tags netgo \
-ldflags "-X 'github.com/metal-stack/v.Version=$(VERSION)' \
-X 'github.com/metal-stack/v.Revision=$(GITVERSION)' \
-X 'github.com/metal-stack/v.GitSHA1=$(SHA)' \
-X 'github.com/metal-stack/v.BuildDate=$(BUILDDATE)'" \
-o application
```
Compile and run:
```bash
make application
```
Expected output:
```bash
[...]
INFO[10-29|14:22:34] application version="devel (0b016992), heads/master-0-g0b01699, 2019-05-29T14:22:26+01:00, go1.16"
```