-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
95 lines (76 loc) · 2.39 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
RELEASE_VERSION :=$(shell cat .version)
YAML_FILES :=$(shell find . -type f -regex ".*y*ml" -print)
REG_URI :=us-docker.pkg.dev/cloudy-tools/builders
## Variable assertions
ifndef RELEASE_VERSION
$(error RELEASE_VERSION is not set)
endif
all: help
.PHONY: version
version: ## Prints the current version
@echo $(RELEASE_VERSION)
.PHONY: tidy
tidy: ## Updates the go modules and vendors all dependancies
go mod tidy
go mod vendor
.PHONY: upgrade
upgrade: ## Upgrades all dependancies
go get -d -u ./...
go mod tidy
go mod vendor
.PHONY: test
test: tidy ## Runs unit tests
mkdir -p tmp
go test -short -count=1 -race -covermode=atomic -coverprofile=cover.out ./...
.PHONY: cover
cover: test ## Runs unit tests and putputs coverage
go tool cover -func=cover.out
.PHONY: lint
lint: lint-go lint-yaml ## Lints the entire project
@echo "Completed Go and YAML lints"
.PHONY: lint
lint-go: ## Lints the entire project using go
golangci-lint run -c .golangci.yaml
.PHONY: lint-yaml
lint-yaml: ## Runs yamllint on all yaml files (brew install yamllint)
yamllint -c .yamllint $(YAML_FILES)
.PHONY: build
build: tidy ## Builds CLI binary
mkdir -p ./bin
CGO_ENABLED=0 go build -trimpath -ldflags="\
-w -s -X main.version=$(RELEASE_VERSION) \
-extldflags '-static'" \
-mod vendor -o bin/vimp main.go
.PHONY: image
image: ## Builds container image
KO_DOCKER_REPO=$(REG_URI)/vimp \
GOFLAGS="-ldflags=-X=main.version=$(RELEASE_VERSION)" \
COSIGN_EXPERIMENTAL="true" \
ko build main.go --image-refs .digest --bare --tags $(RELEASE_VERSION),latest
.PHONY: setup
setup: ## Creates the GCP resources
terraform -chdir=./setup init
terraform -chdir=./setup apply -auto-approve
.PHONY: apply
apply: ## Applies Terraform
terraform -chdir=./setup apply -auto-approve
.PHONY: services
services: ## Provisions all dependencies
tools/services
.PHONY: tag
tag: ## Creates release tag
git tag -s -m "release $(RELEASE_VERSION)" $(RELEASE_VERSION)
git push origin $(RELEASE_VERSION)
.PHONY: tagless
tagless: ## Delete the current release tag
git tag -d $(RELEASE_VERSION)
git push --delete origin $(RELEASE_VERSION)
.PHONY: clean
clean: ## Cleans bin and temp directories
go clean
rm -fr ./vendor
rm -fr ./bin
.PHONY: help
help: ## Display available commands
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk \
'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'