-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMakefile
83 lines (62 loc) · 2.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
BIN?=permissions-api
# Container build settings
CONTAINER_BUILD_CMD?=docker build
# Container settings
CONTAINER_REPO?=ghcr.io/infratographer
PERMISSIONS_API_CONTAINER_IMAGE_NAME = $(CONTAINER_REPO)/permissions-api
CONTAINER_TAG?=latest
# NATS settings
NATS_CREDS?=/tmp/user.creds
# go files to be checked
GO_FILES=$(shell git ls-files '*.go')
## Targets
.PHONY: help
help: Makefile ## Print help
@grep -h "##" $(MAKEFILE_LIST) | grep -v grep | sed -e 's/:.*##/#/' | column -c 2 -t -s#
.PHONY: build
build: ## Builds permissions-api binary.
go build -o $(BIN) ./main.go
.PHONY: ci
ci: | golint test coverage ## Setup dev database and run tests.
.PHONY: test
test: ## Runs unit tests.
@echo Running unit tests...
@go test -v -timeout 120s -cover -short -tags testtools ./...
.PHONY: coverage
coverage: ## Generates a test coverage report.
@echo Generating coverage report...
@go test -timeout 120s -tags testtools ./... -coverprofile=coverage.out -covermode=atomic
@go tool cover -func=coverage.out
@go tool cover -html=coverage.out
lint: golint ## Runs all lint checks.
golint: | vendor ## Runs Go lint checks.
@echo Linting Go files...
@go tool golangci-lint run --timeout 5m
clean: ## Cleans generated files.
@echo Cleaning...
@rm -f coverage.out
@go clean -testcache
vendor: ## Downloads and tidies go modules.
@go mod download
@go mod tidy
.PHONY: gci-diff gci-write gci
gci-diff: $(GO_FILES) ## Outputs improper go import ordering.
@go tool gci diff -s 'standard,default,prefix(github.com/infratographer)' $^
gci-write: $(GO_FILES) ## Checks and updates all go files for proper import ordering.
@go tool gci write -s 'standard,default,prefix(github.com/infratographer)' $^
gci: | gci-diff gci-write ## Outputs and corrects all improper go import ordering.
.PHONY: nats-account
nats-account: ## Generates NATS user account credentials.
@sudo chown -Rh vscode:vscode $(ROOT_DIR)/.devcontainer/nsc
@echo "Dumping NATS user creds file"
@go tool nsc --data-dir=$(ROOT_DIR)/.devcontainer/nsc/nats/nsc/stores generate creds -a INFRADEV -n USER > $(NATS_CREDS)
image: ## Builds all docker images.
$(CONTAINER_BUILD_CMD) -f Dockerfile . -t $(PERMISSIONS_API_CONTAINER_IMAGE_NAME):$(CONTAINER_TAG)
.PHONY: dev-infra-up
dev-infra-up: ## Starts local services to simplify local development.
@echo Starting services
@pushd .devcontainer && docker compose up -d --wait && popd
.PHONY: dev-infra-down
dev-infra-down: ## Stops local services used for local development.
@echo Stopping services
@pushd .devcontainer && docker compose down && popd