enable build from tag

This commit is contained in:
Luke K 2020-07-08 12:22:27 +00:00
parent b7a738b8d5
commit cb0a74714c
No known key found for this signature in database
GPG Key ID: 4896F75BAF2E1966
4 changed files with 8 additions and 14 deletions

View File

@ -8,7 +8,6 @@ on:
jobs:
build:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

View File

@ -4,7 +4,6 @@ BIN := faas
CODE := $(shell find . -name '*.go')
DATE := $(shell date -u +"%Y%m%dT%H%M%SZ")
HASH := $(shell git rev-parse --short HEAD 2>/dev/null)
BRCH := $(shell git symbolic-ref --short -q HEAD | sed 's/\//-/g')
VTAG := $(shell git tag --points-at HEAD)
VERS := $(shell [ -z $(VTAG) ] && echo 'tip' || echo $(VTAG) )
@ -12,22 +11,20 @@ all: $(BIN)
build: all
$(BIN): $(CODE)
go build -ldflags "-X main.brch=$(BRCH) -X main.date=$(DATE) -X main.vers=$(VERS) -X main.hash=$(HASH)" ./cmd/$(BIN)
go build -ldflags "-X main.date=$(DATE) -X main.vers=$(VERS) -X main.hash=$(HASH)" ./cmd/$(BIN)
test:
go test -cover -coverprofile=coverage.out ./...
image: Dockerfile
docker build -t $(REPO):$(BRCH) \
-t $(REPO):$(VERS) \
docker build -t $(REPO):$(VERS) \
-t $(REPO):$(HASH) \
-t $(REPO):$(BRCH)-$(DATE)-$(VERS)-$(HASH) .
-t $(REPO):$(DATE)-$(VERS)-$(HASH) .
push: image
docker push $(REPO):$(BRCH)
docker push $(REPO):$(VERS)
docker push $(REPO):$(HASH)
docker push $(REPO):$(BRCH)-$(DATE)-$(VERS)-$(HASH)
docker push $(REPO):$(DATE)-$(VERS)-$(HASH)
clean:
-@rm -f $(BIN)

View File

@ -6,9 +6,9 @@ import (
// Statically-populated build metadata set
// by `make build`.
var brch, date, vers, hash string
var date, vers, hash string
func main() {
cmd.SetMeta(brch, date, vers, hash)
cmd.SetMeta(date, vers, hash)
cmd.Execute()
}

View File

@ -23,15 +23,13 @@ func version(cmd *cobra.Command, args []string) {
// Populated at build time by `make build`, plumbed through
// main using SetMeta()
var (
brch string // the branch built from
date string // datestamp
vers string // verstionof git commit or `tip`
hash string // git hash built from
)
// SetMeta from the build process, used for verbose version tagging.
func SetMeta(buildBranch, buildTimestamp, commitVersionTag, commitHash string) {
brch = buildBranch
func SetMeta(buildTimestamp, commitVersionTag, commitHash string) {
date = buildTimestamp
vers = commitVersionTag
hash = commitHash
@ -44,5 +42,5 @@ func verboseVersion() string {
if vers == "" { // not statically populatd
return "v0.0.0-source"
}
return fmt.Sprintf("%s-%s-%s-%s", brch, date, vers, hash)
return fmt.Sprintf("%s-%s-%s", date, vers, hash)
}