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")
4
3
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"))
7
8
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
12
15
13
16
.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
16
24
17
25
.PHONY : run
18
26
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 ./...
20
33
21
- # Compile bin and bundle static assets.
22
34
.PHONY : dist
23
- dist : build
24
- stuffbin -a stuff -in ${BIN} -out ${BIN} ${STATIC}
35
+ dist : $(STUFFBIN ) build pack-bin
25
36
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
27
38
# in the .goreleaser post-build hook.
28
39
.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}
31
42
32
43
# Use goreleaser to do a dry run producing local builds.
33
44
.PHONY : release-dry
@@ -38,5 +49,3 @@ release-dry:
38
49
.PHONY : release
39
50
release :
40
51
goreleaser --parallelism 1 --rm-dist --skip-validate
41
-
42
- .DEFAULT_GOAL := dist
0 commit comments