-
-
Save daog1/ed195b13c8f4ec57e608aa5a1207e7b9 to your computer and use it in GitHub Desktop.
compile git version inside go binary
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
mybinary |
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
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 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
VERSION := $(shell git rev-parse --short HEAD) | |
BUILDTIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ') | |
GOLDFLAGS += -X main.Version=$(VERSION) | |
GOLDFLAGS += -X main.Buildtime=$(BUILDTIME) | |
GOFLAGS = -ldflags "$(GOLDFLAGS)" | |
run: build | |
./mybinary | |
build: | |
go build -o mybinary $(GOFLAGS) . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment