forked from Comcast/prombox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
139 lines (112 loc) · 3.53 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
134
135
136
137
138
139
# Copyright 2020 Comcast Cable Communications Management, LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
PREFIX ?= $(shell pwd)
LOCAL_OS ?= $(shell uname)
GO ?= go
GOFMT ?= $(GO)fmt
GOOPTS ?=
BINARY_CF_LINUX_AMD64=prombox-cflinuxfs3
BINARY_LOCAL_AMD64=prombox-${LOCAL_OS}
BUILD_TIME=`date +%FT%T%z`
BUILD_HOST=`hostname`
MAIN_VERSION=v0.0.1
GIT_COMMIT=`git rev-parse --short HEAD`
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`
VERSION=${MAIN_VERSION}.${GIT_COMMIT}
LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.BuildTime=${BUILD_TIME} -X main.BuildHost=${BUILD_HOST} -X main.GitHash=${GIT_COMMIT} -X main.GitBranch=${GIT_BRANCH} -s -w"
# Run prombox production binary artifact in local with config.local.prod.json
.PHONY: run
run:
./${BINARY_LOCAL_AMD64}
# Build prombox production binary artifacts including ui, api
.PHONY: build
build: clean build-ui build-assets build-api
.PHONY: build-dev
build-dev: clean build-ui-dev build-assets build-api
.PHONY: clean
clean:
rm -rf ui/dist
rm -rf ui/assets_vfsdata.go
rm -rf ui/node_modules
rm -rf ${BINARY_CF_LINUX_AMD64}
rm -rf ${BINARY_LOCAL_AMD64}
.PHONY: build-ui
build-ui: install-ui-pkgs
npm run --prefix ui build -- --modern > npm.log
cat npm.log
.PHONY: build-ui-dev
build-ui-dev: install-ui-pkgs
npm run --prefix ui build -- --mode development --modern > npm.log
cat npm.log
.PHONY: install-ui-pkgs
install-ui-pkgs:
npm install --prefix ui
.PHONY: build-assets
build-assets:
@echo ">> writing assets"
cd $(PREFIX)/ui && $(GO) generate -x -v $(GOOPTS)
.PHONY: check_assets
check_assets: build-assets
@echo ">> checking that assets are up-to-date"
@if ! (cd $(PREFIX)/ui && git diff --exit-code); then \
echo "Run 'make assets' and commit the changes to fix the error."; \
exit 1; \
fi
.PHONY: build-api
build-api:
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build ${LDFLAGS} -o ${BINARY_CF_LINUX_AMD64} .
env GOOS=darwin GOARCH=amd64 $(GO) build ${LDFLAGS} -o ${BINARY_LOCAL_AMD64} .
# Run/Serve API and UI in Development Mode
.PHONY: run-api-dev
run-api-dev:
$(GO) run main.go
.PHONY: run-ui-dev
run-ui-dev:
npm run --prefix ui serve
# Formatting/Linting
.PHONY: lint
lint: lint-ui fmt-api lint-api
.PHONY: lint-api
lint-api: vet-api
$(GO)lint -set_exit_status ./...
.PHONY: vet-api
# vet runs the Go source code static analysis tool `vet` to find any common errors.
vet-api:
@go vet 2>/dev/null ; if [ $$? -eq 3 ]; then \
$(GO) get golang.org/x/tools/cmd/vet; \
fi
@echo "go vet ./..."
@go vet ./... ; if [ $$? -eq 1 ]; then \
echo ""; \
echo "Vet found suspicious constructs. Please check the reported constructs"; \
echo "and fix them if necessary before submitting the code for review."; \
exit 1; \
fi
.PHONY: fmt-api
fmt-api:
$(GO) fmt ./...
.PHONY: lint-ui
lint-ui:
npm run --prefix ui lint
# Testing
.PHONY: test
test: test-ui test-api
.PHONY: test-ui
test-ui:
npm run --prefix ui test:unit
.PHONY: test-api
test-api:
$(GO) test ./... -coverprofile cp.out
.PHONY: coverage-report
coverage-report:
go tool cover -html=cp.out -o coverage.html