forked from massdriver-cloud/mass
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
89 lines (72 loc) · 2.06 KB
/
Makefile
File metadata and controls
89 lines (72 loc) · 2.06 KB
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
INSTALL_PATH ?= ~/bin
GIT_SHA := $(shell git log -1 --pretty=format:"%H")
LD_FLAGS := "-X github.com/massdriver-cloud/mass/pkg/version.version=dev -X github.com/massdriver-cloud/mass/pkg/version.gitSHA=local-dev-${GIT_SHA}"
MASSDRIVER_PATH?=../massdriver
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
MKFILE_DIR := $(dir $(MKFILE_PATH))
API_DIR := pkg/api
SCHEMA_URL ?= https://api.massdriver.cloud/graphql/schema.graphql
.DEFAULT_GOAL := install
all.macos: clean generate install.macos
all.linux: clean generate install.linux
.PHONY: check
check: clean generate test ## Run tests and linter locally
golangci-lint run
.PHONY: clean
clean:
rm -rf ${API_DIR}/schema.graphql
rm -rf ${API_DIR}/zz_generated.go
rm -f ./mass
.PHONY: docs
docs: build
./mass docs
.PHONY: generate
generate:
curl -s ${SCHEMA_URL} -o ${API_DIR}/schema.graphql
cd ${API_DIR} && go generate
.PHONY:
swagger-gen:
swag fmt -g cmd/server.go
swag init -g cmd/server.go --pd --ot go,yaml
.PHONY: test
test:
go test ./... -cover
bin:
mkdir bin
.PHONY: lint
lint:
golangci-lint run
.PHONY: build
build:
@if [ "$$(uname -s)" = "Darwin" ]; then \
$(MAKE) build.macos; \
elif [ "$$(uname -s)" = "Linux" ]; then \
$(MAKE) build.linux; \
else \
echo "Error: Unsupported operating system. Please use 'make build.macos' or 'make build.linux' directly."; \
exit 1; \
fi
.PHONY: build.macos
build.macos: bin
GOOS=darwin GOARCH=arm64 go build -o bin/mass-darwin-arm64 -ldflags=${LD_FLAGS}
.PHONY: build.linux
build.linux: bin
GOOS=linux GOARCH=amd64 go build -o bin/mass-linux-amd64 -ldflags=${LD_FLAGS}
.PHONY: install.macos
install.macos: build.macos
rm -f ${INSTALL_PATH}/mass
cp bin/mass-darwin-arm64 ${INSTALL_PATH}/mass
.PHONY: install.linux
install.linux: build.linux
cp -f bin/mass-linux-amd64 ${INSTALL_PATH}/mass
.PHONY: install
install: ## Install mass CLI (auto-detects macOS or Linux)
@OS="$$(uname -s)"; \
if [ "$$OS" = "Darwin" ]; then \
$(MAKE) install.macos; \
elif [ "$$OS" = "Linux" ]; then \
$(MAKE) install.linux; \
else \
echo "Unsupported OS: $$OS"; \
exit 1; \
fi