-
-
Save jxsl13/528eaa437d90976e02fad9d2536388ac to your computer and use it in GitHub Desktop.
compile git version inside go binary
This file contains hidden or 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
mybinary |
This file contains hidden or 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
package main | |
import "fmt" | |
var Version string | |
var Buildtime string | |
func main() { | |
fmt.Printf("Version: %s\n", Version) | |
fmt.Printf("Buildtime: %s\n", Buildtime) | |
} |
This file contains hidden or 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
SHORT_HASH := $(shell git rev-parse --short HEAD) | |
VERSION := $(shell git describe --tags) | |
BUILDTIME := $(shell date --rfc-email) | |
GOLDFLAGS += -X 'github.com/jxsl13/simple-configo.ShortHash=$(SHORT_HASH)' | |
GOLDFLAGS += -X 'github.com/jxsl13/simple-configo.Version=$(VERSION)' | |
GOLDFLAGS += -X 'module/path/in/gomod/main.Expires=true' | |
GOLDFLAGS += -X 'main.Expires=true' | |
GOFLAGS = -ldflags "$(GOLDFLAGS)" | |
run: build | |
./mybinary | |
build: | |
go build -o mybinary $(GOFLAGS) . | |
release: | |
env GOOS=linux GOARCH=amd64 go build $(GOFLAGS) . | |
env GOOS=windows GOARCH=amd64 go build $(GOFLAGS) . | |
go install $(GOFLAGS) . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment