https://github.com/xwi88/version
add the version info for your program with go build
https://github.com/xwi88/version
api-version build-version build-versioning goversion version
Last synced: 3 months ago
JSON representation
add the version info for your program with go build
- Host: GitHub
- URL: https://github.com/xwi88/version
- Owner: xwi88
- License: mit
- Created: 2020-05-02T12:20:54.000Z (about 5 years ago)
- Default Branch: release
- Last Pushed: 2020-05-25T04:04:30.000Z (about 5 years ago)
- Last Synced: 2025-01-15T17:36:59.238Z (5 months ago)
- Topics: api-version, build-version, build-versioning, goversion, version
- Language: Go
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# version
go build with version## usage
```makefile
# Makefile to build the command lines and tests in this project.
# This Makefile doesn't consider Windows Environment. If you use it in Windows, please be careful.SHELL := /bin/bash
#BASEDIR = $(shell pwd)
BASEDIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))# add following lines before go build!
versionDir = github.com/xwi88/versiongitBranch = $(shell git symbolic-ref --short -q HEAD)
ifeq ($(gitBranch),)
gitTag = $(shell git describe --always --tags --abbrev=0)
endifbuildTime = $(shell date "+%FT%T%z")
gitCommit = $(shell git rev-parse HEAD)
gitTreeState = $(shell if git status|grep -q 'clean';then echo clean; else echo dirty; fi)# -ldflags flags accept a space-separated list of arguments to pass to an underlying tool during the build.
ldflags="-X ${versionDir}.gitBranch=${gitBranch} -X ${versionDir}.gitTag=${gitTag} \
-X ${versionDir}.buildTime=${buildTime} -X ${versionDir}.gitCommit=${gitCommit} \
-X ${versionDir}.gitTreeState=${gitTreeState}"```
`go build -ldflags ${ldflags} `