Skip to content

Commit 43cbdf3

Browse files
committed
Refactor Makefile and goreleaser file.
1 parent 8dd369e commit 43cbdf3

File tree

4 files changed

+34
-23
lines changed

4 files changed

+34
-23
lines changed

.goreleaser.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ builds:
66
- binary: dictpress
77
main: ./cmd/dictpress
88
goos:
9+
- windows
910
- darwin
1011
- linux
1112
- freebsd
@@ -14,7 +15,7 @@ builds:
1415
goarch:
1516
- amd64
1617
ldflags:
17-
- -s -w -X "main.buildString={{ .Tag }} ({{ .ShortCommit }} {{ .Date }})"
18+
- -s -w -X "main.buildString={{ .Tag }} ({{ .ShortCommit }} {{ .Date }})" -X "main.versionString={{ .Tag }}"
1819

1920
hooks:
2021
# stuff executables with static assets.
@@ -25,3 +26,4 @@ archives:
2526
files:
2627
- README.md
2728
- LICENSE
29+
- site

Makefile

+29-20
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
1-
LAST_COMMIT := $(shell git rev-parse --short HEAD)
2-
VERSION := $(shell git describe --tags --abbrev=0)
3-
BUILDSTR := \#${LAST_COMMIT} $(shell date -u +"%Y-%m-%dT%H:%M:%S%z")
1+
# Try to get the commit hash from 1) git 2) the VERSION file 3) fallback.
2+
LAST_COMMIT := $(or $(shell git rev-parse --short HEAD 2> /dev/null),$(shell head -n 1 VERSION | grep -oP -m 1 "^[a-z0-9]+$$"),"UNKNOWN")
43

5-
STATIC := config.sample.toml schema.sql queries.sql admin
6-
BIN := dictpress
4+
# Try to get the semver from 1) git 2) the VERSION file 3) fallback.
5+
VERSION := $(or $(shell git describe --tags --abbrev=0 2> /dev/null),$(shell grep -oP "tag: \K(.*)(?=,)" VERSION),"v0.0.0")
6+
7+
BUILDSTR := ${VERSION} (\#${LAST_COMMIT} $(shell date -u +"%Y-%m-%dT%H:%M:%S%z"))
78

8-
# Install dependencies needed for building
9-
.PHONY: deps
10-
deps:
11-
go get -u github.com/knadh/stuffbin/...
9+
YARN ?= yarn
10+
GOPATH ?= $(HOME)/go
11+
STUFFBIN ?= $(GOPATH)/bin/stuffbin
12+
13+
BIN := dictpress
14+
STATIC := config.sample.toml schema.sql queries.sql admin
1215

1316
.PHONY: build
14-
build:
15-
go build -o ${BIN} -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}'" cmd/${BIN}/*.go
17+
build: $(BIN)
18+
19+
$(STUFFBIN):
20+
go install github.com/knadh/stuffbin/...
21+
22+
$(BIN): $(shell find . -type f -name "*.go")
23+
CGO_ENABLED=0 go build -o ${BIN} -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}'" cmd/${BIN}/*.go
1624

1725
.PHONY: run
1826
run:
19-
go run -ldflags="-s -w -X 'main.buildString=${BUILDSTR}'" cmd/${BIN}/*.go
27+
CGO_ENABLED=0 go run -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}'" cmd/${BIN}/*.go
28+
29+
# Run Go tests.
30+
.PHONY: test
31+
test:
32+
go test ./...
2033

21-
# Compile bin and bundle static assets.
2234
.PHONY: dist
23-
dist: build
24-
stuffbin -a stuff -in ${BIN} -out ${BIN} ${STATIC}
35+
dist: $(STUFFBIN) build pack-bin
2536

26-
# pack-releases runn stuffbin packing on the given binary. This is used
37+
# pack-releases runns stuffbin packing on the given binary. This is used
2738
# in the .goreleaser post-build hook.
2839
.PHONY: pack-bin
29-
pack-bin:
30-
stuffbin -a stuff -in ${BIN} -out ${BIN} ${STATIC}
40+
pack-bin: $(BIN) $(STUFFBIN)
41+
$(STUFFBIN) -a stuff -in ${BIN} -out ${BIN} ${STATIC}
3142

3243
# Use goreleaser to do a dry run producing local builds.
3344
.PHONY: release-dry
@@ -38,5 +49,3 @@ release-dry:
3849
.PHONY: release
3950
release:
4051
goreleaser --parallelism 1 --rm-dist --skip-validate
41-
42-
.DEFAULT_GOAL := dist

cmd/dictpress/install.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func installSchema(app *App, prompt bool) {
1010
if prompt {
1111
fmt.Println("")
1212
fmt.Println("** first time installation **")
13-
fmt.Printf("** IMPORTANT: This will wipe existing dictmaker tables and types in the DB '%s' **",
13+
fmt.Printf("** IMPORTANT: This will wipe existing tables and types in the DB '%s' **",
1414
ko.String("db.db"))
1515
fmt.Println("")
1616

cmd/dictpress/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func init() {
8282
}
8383

8484
if ok, _ := f.GetBool("version"); ok {
85-
fmt.Printf("%s (%s)\n", versionString, buildString)
85+
fmt.Println(buildString)
8686
os.Exit(0)
8787
}
8888

0 commit comments

Comments
 (0)