-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathMakefile
133 lines (108 loc) · 4.03 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
SHELL = /bin/sh
export BINARY := notable
export CGO_ENABLED := 0
export CHOWN_GID := $(shell id -g)
export CHOWN_UID := $(shell id -u)
export CWD := $(shell pwd)
export DOCKER_BUILD_TAG := github.com/jmcfarlane/notable.build
export DOCKER_PORT := 8080
export DOCKER_TAG := github.com/jmcfarlane/notable
export USER := $(shell whoami)
export PKGS := $(shell go list ./... | grep -v /templates)
# The tag is something like: v1.2.3
export TAG ?= $(shell head -n1 CHANGELOG.md | grep -E -o 'v[^ ]+')
# The tag is something like: 1.2.3
export VERSION ?= $(shell echo $(TAG) | cut -c2-)
export FLAGS := $(shell echo "\
-X main.buildBranch=$(shell git rev-parse --abbrev-ref HEAD) \
-X main.buildCompiler=$(shell go version | cut -f 3 -d' ') \
-X main.buildDate=$(shell date -u '+%Y-%m-%dT%H:%M:%SZ') \
-X main.buildHash=$(shell git rev-parse --short HEAD) \
-X main.buildUser=$(USER) \
-X main.buildVersion=$(VERSION)")
DOCKER_RUN = "docker run --rm -it -p $(DOCKER_PORT):$(DOCKER_PORT) $(DOCKER_TAG)"
# all: Produce a binary suitable for local testing only
all: clean
@echo ">> Building binary, this is not compiled with release flags!"
cd . && go build -o $(CWD)/$(BINARY)
# help: Print help information
help:
@echo ">> Help info for supported targets:"
@grep -E '^# [-a-z./]+:' Makefile | grep -v https:// | sed -e 's|#| make|g' | sort
# build: Produce artifacts via scripts/build.sh (meant for OCI builds)
build: clean tidy test vet
@echo ">> Building binary suitable for release"
CGO_ENABLED=$(CGO_ENABLED) ./scripts/build.sh
# docker-run: Run the most recent runable docker container in the foreground
docker-run:
@echo ">> Running the last runnable container"
@eval $(DOCKER_RUN)
# install: Install using/into the active $GOPATH
install: vet test
@echo ">> Installing into $(GOPATH)"
go install -ldflags "$(FLAGS)"
# uninstall: Uninstall everything from this project
uninstall:
@echo ">> Uninstalling from $(GOPATH)"
go clean -i -x $(PKGS)
# clean: Purge the target directory
clean:
@echo ">> Purging ./target $(BINARY)"
rm -rf ./target
rm -f $(BINARY)
# coverage: Display code coverage in html
coverage: test
@echo ">> Rendering code coverage"
go tool cover -html=coverage.txt
@echo echo "Success 👍"
# prepare-release: Prepare all assets for release
prepare-release: docker-runnable
@echo ">> Resulting docker containers"
docker images $(DOCKER_TAG)*
@echo ">> Resulting Github release artifacts"
ls -lsah target/*.zip
# publish-release: Publish a release
publish-release: prepare-release
@echo ">> Publishing release"
./scripts/release.sh
# docker-build: Perform a docker build
docker-build: clean target
@echo ">> Performing build inside docker"
docker build --no-cache --build-arg VERSION=$(VERSION) -t $(DOCKER_BUILD_TAG) -f Dockerfile.build .
# docker-build-export-target: Perform an OCI build (and export the target dir)
docker-build-export-target: docker-build
@echo ">> Copying target from docker to target"
docker run --privileged --rm -v $(CWD):/mount $(DOCKER_BUILD_TAG) /bin/bash -c \
"cp -r /go/src/github.com/jmcfarlane/notable/target /mount/"
# docker-runnable: Create a runnable docker container
docker-runnable: docker-build-export-target
@echo ">> Building a runnable docker container"
docker build --no-cache -t $(DOCKER_TAG) .
docker tag $(DOCKER_TAG):latest $(DOCKER_TAG):$(TAG)
# iterate: Build and run with a test db in the foreground
iterate: all
./notable -db /tmp/notable-test.db -daemon=false -browser=false
lorem-ipsum:
cd cmd/lorem-ipsum && go run main.go
# target: Create the target directory
target:
mkdir target
# test: Run go test
test:
@echo ">> Purging existing coverage.txt"
rm -f coverage.txt
@echo ">> Running tests"
go test -coverprofile=coverage.txt -covermode=atomic -v -timeout=90s
@echo echo "Success 👍"
@echo ">> Making sure test coverage.txt was written"
test -f coverage.txt
@echo echo "Success 👍"
# tidy: Tidy makes sure go.mod matches the source code in the module
tidy:
go mod tidy
# vet: Run go vet
vet:
@echo ">> Running go vet"
go vet $(PKGS)
@echo echo "Success 👍"
.PHONY: test