-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
112 lines (79 loc) · 2.48 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
PKG := synyx.de/tales
SERVER_CMD := tales-server
MIGRATE_CMD := tales-migrate
VERSION ?= $(shell git describe --tags --abbrev=0 2> /dev/null)
GIT_SHA := $(shell git rev-parse HEAD)
GIT_DIRTY := $(shell git status --porcelain | grep -v "??" 2> /dev/null)
GIT_TREE_STATE := $(if $(GIT_DIRTY),"dirty","clean")
LDFLAGS := -X $(PKG)/pkg/buildinfo.Version=$(VERSION) \
-X $(PKG)/pkg/buildinfo.GitSHA=$(GIT_SHA) \
-X $(PKG)/pkg/buildinfo.GitTreeState=$(GIT_TREE_STATE)
GOFLAGS := -ldflags "$(LDFLAGS)"
ifeq ($(GOOS), windows)
SUFFIX := .exe
endif
BINDIR=bin/
PKGDIR=pkg/
SERVER_BINARY=$(addsuffix ${SUFFIX},$(addprefix ${BINDIR},${SERVER_CMD}))
MIGRATE_BINARY=$(addsuffix ${SUFFIX},$(addprefix ${BINDIR},${MIGRATE_CMD}))
BINARIES=${SERVER_BINARY} ${MIGRATE_BINARY}
.PHONY: all go js \
build build-go build-js \
clean clean-go clean-js \
coverage coverage-go coverage-js \
lint lint-go lint-js \
test test-go test-js \
run dist docker
all: build
go: build-go
js: build-js
build: build-go build-js
build-go: ${BINARIES}
bin/%: cmd/**/*.go pkg/**/*.go
go build $(GOFLAGS) -o $@ $(PKG)/cmd/$(subst $(SUFFIX),,$(@:bin/%=%))
build-js:
npm run build
coverage: coverage-go coverage-js
coverage-go: coverage.html
coverage.html: coverage.out
go tool cover -html=coverage.out -o coverage.html
coverage.out: pkg/**/*_test.go
go test -coverprofile=coverage.out ./pkg/...
coverage-js: coverage/index.html
coverage/index.html:
npx jest --coverage --coverageReporters html
lint: lint-go lint-js
lint-go:
go vet ./...
which golint && golint -set_exit_status ./... || true
which golangci-lint && golangci-lint run || true
lint-js:
npm run lint
test: test-go test-js
test-go:
go test ./pkg/...
test-js:
npm run test
run:
${SERVER_BINARY} -resources pkg/web/public
dist: dist-go dist-js
dist-go: tales-server.zip
tales-server.zip: bin/* pkg/web/public/*
mkdir -p dist/tales-server
cp -r bin public dist/tales-server/
if which zip; then \
cd dist && zip -r tales-server.zip tales-server; \
else \
cd dist && 7z a tales-server.zip tales-server; \
fi
dist-js:
npm run dist
CONTAINER_BUILDER := $(shell which docker 2>/dev/null || which podman 2>/dev/null)
docker:
CGO_ENABLED=0 go build -ldflags "$(LDFLAGS) -extldflags=-static" -o bin/tales-server $(PKG)/cmd/tales-server
${CONTAINER_BUILDER} build -t tales .
clean: clean-go clean-js
clean-go:
rm -rf coverage.out coverage.html ${BINARIES}
clean-js:
rm -rf dist/main.{js,js.map} pkg/web/public/js/tales.{js,js.map} pkg/web/public/js/viewer.{js,js.map}