-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
104 lines (83 loc) · 3.29 KB
/
Makefile
File metadata and controls
104 lines (83 loc) · 3.29 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
## Include per-checkout configuration
#
# local.mk is a way to override settings on a per-checkout basis. It is in the
# .gitignore and shouldn't be committed to git.
-include local.mk
# Project-specific overrides can go here. Make sure to use ?= for assignment,
# though; otherwise you may overwrite a value from local.mk. Using ?= in a
# Makefile means that the variable should only be set if it is not already set.
#
######################################################
### BEGIN PROJECT-SPECIFIC CONFIGURATION OVERRIDES ###
######################################################
# Define GOCI_LINT_V for golangci-lint. The install.sh script handles OS/ARCH.
GOCI_LINT_V?=v2.9.0
# Define GOTESTSUM_V for gotestsum. The install.sh script handles OS/ARCH.
GOTESTSUM_V?=1.13.0
####################################################
### END PROJECT-SPECIFIC CONFIGURATION OVERRIDES ###
####################################################
# Variables
ARCH?=$(shell go env GOARCH)
GO_BIN?=$(shell pwd)/.bin
OS?=$(shell go env GOOS)
# Update PATH for make targets
SHELL:=env PATH=$(GO_BIN):$(PATH) $(SHELL)
.PHONY: all
all: install-tools lint-go ## Install tools and run linters
.PHONY: install-tools
install-tools: install-oapi-codegen install-tsp ## Install golangci-lint and other tools for local development
mkdir -p ${GO_BIN}
ifndef CI
@echo "Installing golangci-lint ${GOCI_LINT_V} to ${GO_BIN}..."
curl -sSfL 'https://raw.githubusercontent.com/golangci/golangci-lint/${GOCI_LINT_V}/install.sh' | sh -s -- -b ${GO_BIN} ${GOCI_LINT_V}
@echo "golangci-lint installed."
@echo "Installing gotestsum ${GOTESTSUM_V} to ${GO_BIN}..."
curl -sSfL 'https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_V}/gotestsum_${GOTESTSUM_V}_${OS}_${ARCH}.tar.gz' | tar -xz -C ${GO_BIN} gotestsum
@echo "gotestsum installed."
else
@echo "CI environment detected, skipping local installation of golangci-lint."
endif
.PHONY: install-oapi-codegen
install-oapi-codegen: .bin/go/oapi-codegen
.bin/go/oapi-codegen:
GOBIN=$(shell pwd)/.bin/go go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@v2.3.0
.PHONY: install-tsp
install-tsp:
npm install -D @typespec/compiler @typespec/openapi3
.PHONY: lint
lint: lint-go ## Run all linters (currently only golangci-lint)
.PHONY: lint-go
lint-go: ## Run golangci linters
ifdef CI
mkdir -p test/results
golangci-lint run --output.junit-xml.path=test/results/lint-tests.xml ./...
else
golangci-lint run -v ./...
endif
.PHONY: test
test:
mkdir -p test/results
gotestsum --junitfile test/results/unit-tests.xml -- -race -v ./...
.PHONY: format
format: format-tsp format-go
.PHONY: format-tsp
format-tsp:
./node_modules/.bin/tsp format 'internal/definitions/**/*.tsp'
.PHONY: format-go
format-go:
golangci-lint run --fix -v ./...
.PHONY: generate
generate: tsp-compile oapi-generate
.PHONY: tsp-compile oapi-generate
tsp-compile:
./node_modules/.bin/tsp compile internal/legacy/definitions/main.tsp
.PHONY: oapi-generate
oapi-generate:
PATH=$(shell pwd)/.bin/go:$(PATH) go generate ./internal/...
.PHONY: clean
clean: ## Clean up the .bin directory
@echo "Cleaning up .bin directory..."
rm -rf $(GO_BIN)
help: ## Show this help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'