-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
77 lines (65 loc) · 2.55 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
.PHONY: dev test image doc
APP_NAME := urbs-setting
APP_PATH := github.com/teambition/urbs-setting
APP_VERSION := $(shell git describe --tags --always --match "v[0-9]*")
dev:
@CONFIG_FILE_PATH=${PWD}/config/default.yml APP_ENV=development go run main.go
test:
@CONFIG_FILE_PATH=${PWD}/config/test.yml APP_ENV=test go test ./...
doc:
# https://github.com/Mermade/widdershins
# Install: npm i -g widdershins
echo "# Content generated by 'make doc'. DO NOT EDIT.\n" > doc/openapi.yaml
cat doc/openapi_header.yaml >> doc/openapi.yaml
cat doc/paths_version.yaml >> doc/openapi.yaml
cat doc/paths_user.yaml >> doc/openapi.yaml
cat doc/paths_group.yaml >> doc/openapi.yaml
cat doc/paths_product.yaml >> doc/openapi.yaml
cat doc/paths_label.yaml >> doc/openapi.yaml
cat doc/paths_module.yaml >> doc/openapi.yaml
cat doc/paths_setting.yaml >> doc/openapi.yaml
widdershins --language_tabs 'shell:Shell' 'http:HTTP' --summary doc/openapi.yaml -o doc/openapi.md
BUILD_TIME := $(shell date -u +"%FT%TZ")
BUILD_COMMIT := $(shell git rev-parse HEAD)
.PHONY: build build-tool
build:
@mkdir -p ./dist
GO111MODULE=on go build -ldflags "-X ${APP_PATH}/src/api.AppName=${APP_NAME} \
-X ${APP_PATH}/src/api.AppVersion=${APP_VERSION} \
-X ${APP_PATH}/src/api.BuildTime=${BUILD_TIME} \
-X ${APP_PATH}/src/api.GitSHA1=${BUILD_COMMIT}" \
-o ./dist/urbs-setting main.go
build-linux:
@mkdir -p ./dist
GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X ${APP_PATH}/src/api.AppName=${APP_NAME} \
-X ${APP_PATH}/src/api.AppVersion=${APP_VERSION} \
-X ${APP_PATH}/src/api.BuildTime=${BUILD_TIME} \
-X ${APP_PATH}/src/api.GitSHA1=${BUILD_COMMIT}" \
-o ./dist/urbs-setting main.go
PKG_LIST := $(shell go list ./... | grep -v /vendor/)
GO_FILES := $(shell find . -name '*.go' | grep -v /vendor/)
.PHONY: lint
lint:
@hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u golang.org/x/lint/golint; \
fi
@golint -set_exit_status ${PKG_LIST}
.PHONY: fmt-check
fmt-check:
test -z "$(shell gofmt -d -e ${GO_FILES})"
.PHONY: misspell-check
misspell-check:
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/client9/misspell/cmd/misspell; \
fi
@misspell -error $(GO_FILES)
.PHONY: coverhtml
coverhtml:
@mkdir -p coverage
@CONFIG_FILE_PATH=${PWD}/config/test-local.yml go test -coverprofile=coverage/cover.out ./...
@go tool cover -html=coverage/cover.out -o coverage/coverage.html
@go tool cover -func=coverage/cover.out | tail -n 1
DOCKER_IMAGE_TAG := ${APP_NAME}:latest
.PHONY: image
image:
docker build --rm -t ${DOCKER_IMAGE_TAG} .