forked from target/goalert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
250 lines (199 loc) · 10.7 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
.PHONY: stop start build-docker lint tools regendb resetdb
.PHONY: smoketest generate check all test test-long install install-race
.PHONY: cy-wide cy-mobile cy-wide-prod cy-mobile-prod cypress postgres
.PHONY: config.json.bak jest new-migration check-all cy-wide-prod-run cy-mobile-prod-run
.SUFFIXES:
GOFILES = $(shell find . -path ./web/src -prune -o -path ./vendor -prune -o -path ./.git -prune -o -type f -name "*.go" -print | grep -v web/inline_data_gen.go) go.sum
INLINER = devtools/inliner/*.go
CFGPARAMS = devtools/configparams/*.go
DB_URL = postgres://goalert@localhost:5432/goalert?sslmode=disable
LOG_DIR=
GOPATH=$(shell go env GOPATH)
BIN_DIR=bin
GIT_COMMIT=$(shell git rev-parse HEAD || echo '?')
GIT_TREE=$(shell git diff-index --quiet HEAD -- && echo clean || echo dirty)
GIT_VERSION=$(shell git describe --tags --dirty --match 'v*' || echo dev-$(shell date -u +"%Y%m%d%H%M%S"))
BUILD_DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
BUILD_FLAGS=
LD_FLAGS+=-X github.com/target/goalert/version.gitCommit=$(GIT_COMMIT)
LD_FLAGS+=-X github.com/target/goalert/version.gitVersion=$(GIT_VERSION)
LD_FLAGS+=-X github.com/target/goalert/version.gitTreeState=$(GIT_TREE)
LD_FLAGS+=-X github.com/target/goalert/version.buildDate=$(BUILD_DATE)
export CY_ACTION = open
export CY_BROWSER = chrome
export RUNJSON_PROD_FILE = devtools/runjson/localdev-cypress-prod.json
ifdef LOG_DIR
RUNJSON_ARGS += -logs=$(LOG_DIR)
endif
export CGO_ENABLED = 0
export PATH := $(PWD)/bin:$(PATH)
export GOOS = $(shell go env GOOS)
export GOALERT_DB_URL_NEXT = $(DB_URL_NEXT)
ifeq ($(shell test -d vendor && echo -n yes), yes)
export GOFLAGS=-mod=vendor
endif
ifdef BUNDLE
GOFILES += web/inline_data_gen.go
endif
all: test install
$(BIN_DIR)/runjson: go.sum devtools/runjson/*.go
go build $(BUILD_FLAGS) -o $@ ./devtools/$(@F)
$(BIN_DIR)/psql-lite: go.sum devtools/psql-lite/*.go
go build $(BUILD_FLAGS) -o $@ ./devtools/$(@F)
$(BIN_DIR)/waitfor: go.sum devtools/waitfor/*.go
go build $(BUILD_FLAGS) -o $@ ./devtools/$(@F)
$(BIN_DIR)/simpleproxy: go.sum devtools/simpleproxy/*.go
go build $(BUILD_FLAGS) -o $@ ./devtools/$(@F)
$(BIN_DIR)/resetdb: go.sum devtools/resetdb/*.go migrate/*.go
go build $(BUILD_FLAGS) -o $@ ./devtools/$(@F)
$(BIN_DIR)/mockslack: go.sum $(shell find ./devtools/mockslack -name '*.go')
go build $(BUILD_FLAGS) -o $@ ./devtools/mockslack/cmd/mockslack
$(BIN_DIR)/runjson.linux: go.sum devtools/runjson/*.go
GOOS=linux go build $(BUILD_FLAGS) -o $@ ./devtools/$(basename $(@F))
$(BIN_DIR)/psql-lite.linux: go.sum devtools/psql-lite/*.go
GOOS=linux go build $(BUILD_FLAGS) -o $@ ./devtools/$(basename $(@F))
$(BIN_DIR)/waitfor.linux: go.sum devtools/waitfor/*.go
GOOS=linux go build $(BUILD_FLAGS) -o $@ ./devtools/$(basename $(@F))
$(BIN_DIR)/simpleproxy.linux: go.sum devtools/simpleproxy/*.go
GOOS=linux go build $(BUILD_FLAGS) -o $@ ./devtools/$(basename $(@F))
$(BIN_DIR)/resetdb.linux: go.sum devtools/resetdb/*.go migrate/*.go
GOOS=linux go build $(BUILD_FLAGS) -o $@ ./devtools/$(basename $(@F))
$(BIN_DIR)/mockslack.linux: go.sum $(shell find ./devtools/mockslack -name '*.go')
GOOS=linux go build $(BUILD_FLAGS) -o $@ ./devtools/mockslack/cmd/mockslack
$(BIN_DIR)/goalert: go.sum $(GOFILES) graphql2/mapconfig.go
go build $(BUILD_FLAGS) -tags "$(BUILD_TAGS)" -ldflags "$(LD_FLAGS)" -o $@ ./cmd/goalert
$(BIN_DIR)/goalert.linux: $(BIN_DIR)/goalert web/inline_data_gen.go
GOOS=linux go build $(BUILD_FLAGS) -tags "$(BUILD_TAGS)" -ldflags "$(LD_FLAGS)" -o $@ ./cmd/goalert
$(BIN_DIR)/goalert.darwin: $(BIN_DIR)/goalert web/inline_data_gen.go
GOOS=darwin go build $(BUILD_FLAGS) -tags "$(BUILD_TAGS)" -ldflags "$(LD_FLAGS)" -o $@ ./cmd/goalert
$(BIN_DIR)/goalert-linux-amd64.tgz: $(BIN_DIR)/goalert.linux
rm -rf bin/goalert-linux
mkdir -p bin/goalert-linux/goalert/bin
cp $(BIN_DIR)/goalert.linux bin/goalert-linux/goalert/bin/goalert
tar czvf $@ -C bin/goalert-linux goalert
$(BIN_DIR)/goalert-darwin-amd64.tgz: $(BIN_DIR)/goalert.darwin
rm -rf bin/goalert-darwin
mkdir -p bin/goalert-darwin/goalert/bin
cp $(BIN_DIR)/goalert.darwin bin/goalert-darwin/goalert/bin/goalert
tar czvf $@ -C bin/goalert-darwin goalert
$(BIN_DIR)/integration/goalert/cypress.json: web/src/cypress.json
sed 's/\.ts/\.js/' web/src/cypress.json >bin/integration/goalert/cypress.json
$(BIN_DIR)/integration/goalert/cypress: web/src/node_modules web/src/webpack.cypress.js $(BIN_DIR)/integration/goalert/cypress.json $(shell find ./web/src/cypress)
rm -rf $@
(cd web/src && yarn webpack --config webpack.cypress.js --target node)
cp -r web/src/cypress/fixtures bin/integration/goalert/cypress/
touch $@
$(BIN_DIR)/integration/goalert/bin: $(BIN_DIR)/goalert.linux $(BIN_DIR)/mockslack.linux $(BIN_DIR)/simpleproxy.linux $(BIN_DIR)/waitfor.linux $(BIN_DIR)/runjson.linux $(BIN_DIR)/psql-lite.linux
rm -rf $@
mkdir -p bin/integration/goalert/bin
cp bin/*.linux bin/integration/goalert/bin/
for f in bin/integration/goalert/bin/*.linux; do mv $$f bin/integration/goalert/bin/$$(basename $$f .linux); done
touch $@
$(BIN_DIR)/integration/goalert/devtools: $(shell find ./devtools/ci)
rm -rf $@
mkdir -p bin/integration/goalert/devtools
cp -r devtools/ci bin/integration/goalert/devtools/
touch $@
$(BIN_DIR)/integration/goalert/.git: $(shell find ./.git)
rm -rf $@
mkdir -p bin/integration/goalert/.git
git rev-parse HEAD >bin/integration/goalert/COMMIT
test -d .git/resource && cp -r .git/resource bin/integration/goalert/.git/ || true
$(BIN_DIR)/integration: $(BIN_DIR)/integration/goalert/.git $(BIN_DIR)/integration/goalert/devtools $(BIN_DIR)/integration/goalert/cypress $(BIN_DIR)/integration/goalert/bin
touch $@
$(BIN_DIR)/integration.tgz: bin/integration
tar czvf bin/integration.tgz -C bin/integration goalert
install: $(GOFILES)
go install $(BUILD_FLAGS) -tags "$(BUILD_TAGS)" -ldflags "$(LD_FLAGS)" ./cmd/goalert
cypress: bin/runjson bin/waitfor bin/simpleproxy bin/mockslack bin/goalert bin/psql-lite web/src/node_modules
web/src/node_modules/.bin/cypress install
cy-wide: cypress web/src/build/vendorPackages.dll.js
CYPRESS_viewportWidth=1440 CYPRESS_viewportHeight=900 bin/runjson $(RUNJSON_ARGS) <devtools/runjson/localdev-cypress.json
cy-mobile: cypress web/src/build/vendorPackages.dll.js
CYPRESS_viewportWidth=375 CYPRESS_viewportHeight=667 bin/runjson $(RUNJSON_ARGS) <devtools/runjson/localdev-cypress.json
cy-wide-prod: web/inline_data_gen.go cypress
CYPRESS_viewportWidth=1440 CYPRESS_viewportHeight=900 CY_ACTION=$(CY_ACTION) bin/runjson $(RUNJSON_ARGS) <$(RUNJSON_PROD_FILE)
cy-mobile-prod: web/inline_data_gen.go cypress
CYPRESS_viewportWidth=375 CYPRESS_viewportHeight=667 CY_ACTION=$(CY_ACTION) bin/runjson $(RUNJSON_ARGS) <$(RUNJSON_PROD_FILE)
cy-wide-prod-run: web/inline_data_gen.go cypress
make cy-wide-prod CY_ACTION=run
cy-mobile-prod-run: web/inline_data_gen.go cypress
make cy-mobile-prod CY_ACTION=run
start: bin/waitfor web/src/node_modules web/src/build/vendorPackages.dll.js bin/runjson
# force rebuild to ensure build-flags are set
touch cmd/goalert/main.go
make bin/goalert BUILD_TAGS+=sql_highlight
bin/runjson <devtools/runjson/localdev.json
jest: web/src/node_modules
cd web/src && node_modules/.bin/jest $(JEST_ARGS)
test: web/src/node_modules jest
go test -short ./...
check: generate web/src/node_modules
# go run devtools/ordermigrations/main.go -check
go vet ./...
go run github.com/gordonklaus/ineffassign .
CGO_ENABLED=0 go run honnef.co/go/tools/cmd/staticcheck ./...
(cd web/src && yarn fmt)
./devtools/ci/tasks/scripts/codecheck.sh
check-all: check test smoketest cy-wide-prod-run cy-mobile-prod-run
migrate/inline_data_gen.go: migrate/migrations migrate/migrations/*.sql $(INLINER)
go generate ./migrate
graphql2/mapconfig.go: $(CFGPARAMS) config/config.go
(cd ./graphql2 && go run ../devtools/configparams/main.go -out mapconfig.go && goimports -w ./mapconfig.go) || go generate ./graphql2
graphql2/generated.go: graphql2/schema.graphql graphql2/gqlgen.yml
go generate ./graphql2
generate:
go generate ./...
smoketest: install bin/goalert
(cd smoketest && go test -parallel 10 -timeout 20m)
test-migrations: migrate/inline_data_gen.go bin/goalert
(cd smoketest && go test -run TestMigrations)
tools:
go get -u golang.org/x/tools/cmd/gorename
go get -u golang.org/x/tools/cmd/present
go get -u golang.org/x/tools/cmd/bundle
go get -u golang.org/x/tools/cmd/gomvpkg
go get -u github.com/golang/lint/golint
go get -u golang.org/x/tools/cmd/goimports
go get -u github.com/gordonklaus/ineffassign
go get -u honnef.co/go/tools/cmd/staticcheck
go get -u golang.org/x/tools/cmd/stringer
web/src/yarn.lock: web/src/package.json
(cd web/src && yarn --no-progress --silent && touch yarn.lock)
web/src/node_modules: web/src/node_modules/.bin/cypress
touch web/src/node_modules
web/src/node_modules/.bin/cypress: web/src/yarn.lock
(cd web/src && yarn --no-progress --silent --frozen-lockfile && touch node_modules/.bin/cypress)
web/src/build/index.html: web/src/webpack.prod.config.js web/src/yarn.lock $(shell find ./web/src/app -type f )
rm -rf web/src/build/static
(cd web/src && yarn --no-progress --silent --frozen-lockfile && node_modules/.bin/webpack --config webpack.prod.config.js)
web/inline_data_gen.go: web/src/build/index.html $(CFGPARAMS) $(INLINER)
go generate ./web
web/src/build/vendorPackages.dll.js: web/src/node_modules web/src/webpack.dll.config.js
(cd web/src && node_modules/.bin/webpack --config ./webpack.dll.config.js --progress)
config.json.bak: bin/goalert
bin/goalert get-config "--db-url=$(DB_URL)" 2>/dev/null >config.json.new || rm config.json.new
(test -s config.json.new && test "`cat config.json.new`" != "{}" && mv config.json.new config.json.bak || rm -f config.json.new)
postgres:
docker run -d \
--restart=always \
-e POSTGRES_USER=goalert \
--name goalert-postgres \
-p 5432:5432 \
postgres:11-alpine || docker start goalert-postgres
regendb: bin/resetdb bin/goalert migrate/inline_data_gen.go config.json.bak
./bin/resetdb -with-rand-data -admin-id=00000000-0000-0000-0000-000000000000
test -f config.json.bak && bin/goalert set-config --allow-empty-data-encryption-key "--db-url=$(DB_URL)" <config.json.bak || true
bin/goalert add-user --user-id=00000000-0000-0000-0000-000000000000 --user admin --pass admin123 "--db-url=$(DB_URL)"
resetdb: migrate/inline_data_gen.go config.json.bak
go run ./devtools/resetdb --no-migrate
clean:
git clean -xdf ./web ./bin ./vendor ./smoketest
build-docker: bin/goalert bin/mockslack
lint: $(GOFILES)
go run github.com/golang/lint/golint $(shell go list ./...)
new-migration:
@test "$(NAME)" != "" || (echo "NAME is required" && false)
@test ! -f migrate/migrations/*-$(NAME).sql || (echo "Migration already exists with the name $(NAME)." && false)
@echo "-- +migrate Up\n\n\n-- +migrate Down\n" >migrate/migrations/$(shell date +%Y%m%d%H%M%S)-$(NAME).sql
@echo "Created: migrate/migrations/$(shell date +%Y%m%d%H%M%S)-$(NAME).sql"