-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
Makefile
172 lines (132 loc) · 5.25 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
ifndef GOPATH
GOPATH := $(shell go env GOPATH)
endif
ifndef GOBIN # derive value from gopath (default to first entry, similar to 'go get')
GOBIN := $(shell go env GOPATH | sed 's/:.*//')/bin
endif
tools = $(addprefix $(GOBIN)/, golangci-lint goimports govulncheck protoc-gen-go protoc-gen-go-grpc gci)
deps = $(addprefix $(GOBIN)/, wire dbmate)
ifneq (,$(wildcard ./.local.env))
include ./.local.env
export
endif
.DEFAULT_GOAL := all
###############################################################################
#
# Initialization
#
###############################################################################
init: ## Install git hooks to perform pre-commit checks
git config core.hooksPath .githooks
git config commit.template .gitmessage
dep: $(deps) ## Install the deps required to generate code and build Harness
@echo "Installing dependencies"
@go mod download
tools: $(tools) ## Install tools required for the build
@echo "Installed tools"
###############################################################################
#
# Harness Build and testing rules
#
###############################################################################
build: generate ## Build the all-in-one Harness binary
@echo "Building Harness Server"
go build -o ./gitness ./cmd/gitness
test: generate ## Run the go tests
@echo "Running tests"
go test -v -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
###############################################################################
#
# Artifact Registry Build and testing rules
#
###############################################################################
run: ar-clean build
./gitness server .local.env || true
ar-conformance-test: ar-clean build
./gitness server .local.env > logfile.log 2>&1 & echo $$! > server.PID
@sleep 10
./registry/tests/conformance_test.sh localhost:3000
EXIT_CODE=$$?;
kill `cat server.PID`
@rm server.PID
@rm logfile.log
exit $$EXIT_CODE
ar-hot-conformance-test:
rm -rf distribution-spec || true
./registry/tests/conformance_test.sh localhost:3000 || true
ar-api-update:
@set -e; \
oapi-codegen --config ./registry/config/openapi/artifact-services.yaml ./registry/app/api/openapi/api.yaml; \
oapi-codegen --config ./registry/config/openapi/artifact-types.yaml ./registry/app/api/openapi/api.yaml;
ar-clean:
@rm artifact-registry 2> /dev/null || true
@docker stop ps_artifacthub 2> /dev/null || true
rm -rf distribution-spec
@kill -9 $$(lsof -t -i:3000) || true
@rm server.PID || true
@rm logfile.log || true
go clean
###############################################################################
#
# Code Formatting and linting
#
###############################################################################
format: tools # Format go code and error if any changes are made
@echo "Formating ..."
@goimports -w .
@gci write --skip-generated --custom-order -s standard -s "prefix(github.com/harness/gitness)" -s default -s blank -s dot .
@echo "Formatting complete"
sec:
@echo "Vulnerability detection $(1)"
@govulncheck ./...
lint: tools generate # lint the golang code
@echo "Linting $(1)"
@golangci-lint run --timeout=3m --verbose
###############################################################################
# Code Generation
#
# Some code generation can be slow, so we only run it if
# the source file has changed.
###############################################################################
generate: wire
@echo "Generated Code"
wire: cmd/gitness/wire_gen.go
force-wire: ## Force wire code generation
@sh ./scripts/wire/gitness.sh
cmd/gitness/wire_gen.go: cmd/gitness/wire.go
@sh ./scripts/wire/gitness.sh
###############################################################################
# Install Tools and deps
#
# These targets specify the full path to where the tool is installed
# If the tool already exists it wont be re-installed.
###############################################################################
update-tools: delete-tools $(tools) ## Update the tools by deleting and re-installing
delete-tools: ## Delete the tools
@rm $(tools) || true
# Install golangci-lint
$(GOBIN)/golangci-lint:
@echo "🔘 Installing golangci-lint... (`date '+%H:%M:%S'`)"
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.56.2
# Install goimports to format code
$(GOBIN)/goimports:
@echo "🔘 Installing goimports ... (`date '+%H:%M:%S'`)"
@go install golang.org/x/tools/cmd/goimports
# Install wire to generate dependency injection
$(GOBIN)/wire:
go install github.com/google/wire/cmd/wire@latest
# Install dbmate to perform db migrations
$(GOBIN)/dbmate:
go install github.com/amacneil/dbmate@v1.15.0
$(GOBIN)/govulncheck:
go install golang.org/x/vuln/cmd/govulncheck@v1.1.1
$(GOBIN)/protoc-gen-go:
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
$(GOBIN)/protoc-gen-go-grpc:
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
$(GOBIN)/gci:
go install github.com/daixiang0/gci@v0.13.1
help: ## show help message
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[$$()% 0-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
.PHONY: delete-tools update-tools help format lint