-
Notifications
You must be signed in to change notification settings - Fork 652
Expand file tree
/
Copy pathMakefile
More file actions
168 lines (126 loc) · 4.83 KB
/
Makefile
File metadata and controls
168 lines (126 loc) · 4.83 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
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
.PHONY: all build deps image migrate test vet sec vulncheck format unused release
.PHONY: check-gosec check-govulncheck check-oapi-codegen check-staticcheck
CHECK_FILES ?= ./...
ifdef RELEASE_VERSION
VERSION=v$(RELEASE_VERSION)
else
VERSION=$(shell git describe --tags)
endif
ifneq ($(shell docker compose version 2>/dev/null),)
DOCKER_COMPOSE = docker compose
else
DOCKER_COMPOSE = docker-compose
endif
DEV_DOCKER_COMPOSE = docker-compose-dev.yml
BUILD_VERSION_PKG = github.com/supabase/auth/internal/utilities
BUILD_LD_FLAGS = -X $(BUILD_VERSION_PKG).Version=$(VERSION)
BUILD_CMD = go build \
-o $(1) \
-buildvcs=false \
-ldflags "$(BUILD_LD_FLAGS)$(2)"
RELEASE_TARGETS = x86 arm64 darwin-arm64 arm64-strip
RELEASE_ARCHIVES = \
auth-$(VERSION)-x86.tar.gz \
auth-$(VERSION)-arm64.tar.gz \
auth-$(VERSION)-darwin-arm64.tar.gz \
auth-$(VERSION)-arm64.tar.xz
help: ## Show this help.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
all: vet sec static build ## Run the tests and build the binary.
build: auth auth-arm64 auth-darwin-arm64 ## Build the binaries.
build-strip: auth-arm64-strip ## Build a stripped binary, for which the version file needs to be rewritten.
auth: deps
CGO_ENABLED=0 $(call BUILD_CMD,$(@),)
auth-x86: deps
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(call BUILD_CMD,$(@),)
auth-arm64: deps
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(call BUILD_CMD,$(@),)
auth-darwin-arm64: deps
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(call BUILD_CMD,$(@),)
auth-arm64-strip: deps
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(call BUILD_CMD,$(@), -s)
deps: ## Install dependencies.
@go mod download
@go mod verify
release-test: \
vet \
static \
sec \
vulncheck \
test
release: $(RELEASE_ARCHIVES)
auth-$(VERSION)-%.tar.gz: \
release-%/auth \
release-%/gotrue | migrations
tar -C $(<D) -czvf $(@) auth gotrue -C ../ migrations/
auth-$(VERSION)-arm64.tar.xz: \
release-arm64-strip/auth \
release-arm64-strip/gotrue | migrations
tar -C $(<D) -cf - auth gotrue -C ../ migrations/ \
| xz -T0 -9e -C crc64 > $(@)
release-%/auth: auth-%
mkdir -p $(@D)
cp -a $(<) $(@)
release-%/gotrue: release-%/auth
ln -sf $(<F) $(@)
migrate_dev: ## Run database migrations for development.
hack/migrate.sh postgres
migrate_test: ## Run database migrations for test.
hack/migrate.sh postgres
test: auth ## Run tests.
go test $(CHECK_FILES) -coverprofile=coverage.out -coverpkg ./... -p 1 -race -v -count=1
./hack/coverage.sh
vet: # Vet the code
go vet $(CHECK_FILES)
sec: check-gosec # Check for security vulnerabilities
gosec -quiet -exclude-generated -exclude=G117,G120,G704 $(CHECK_FILES)
gosec -quiet -tests -exclude-generated -exclude=G101,G104,G117,G120,G704 $(CHECK_FILES)
check-gosec:
@command -v gosec >/dev/null 2>&1 \
|| go install github.com/securego/gosec/v2/cmd/gosec@latest
vulncheck: check-govulncheck # Check for known vulnerabilities
govulncheck -format json $(CHECK_FILES) | go run ./hack/vulncheck-filter
check-govulncheck:
@command -v govulncheck >/dev/null 2>&1 \
|| go install golang.org/x/vuln/cmd/govulncheck@latest
unused: | check-staticcheck # Look for unused code
@echo "Unused code:"
staticcheck -checks U1000 $(CHECK_FILES)
@echo
@echo "Code used only in _test.go (do move it in those files):"
staticcheck -checks U1000 -tests=false $(CHECK_FILES)
static: | check-staticcheck
staticcheck ./...
check-staticcheck:
@command -v staticcheck >/dev/null 2>&1 \
|| go install honnef.co/go/tools/cmd/staticcheck@latest
generate: | check-oapi-codegen
go generate ./...
check-oapi-codegen:
@command -v oapi-codegen >/dev/null 2>&1 \
|| go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest
dev: ## Run the development containers
${DOCKER_COMPOSE} -f $(DEV_DOCKER_COMPOSE) up
down: ## Shutdown the development containers
# Start postgres first and apply migrations
${DOCKER_COMPOSE} -f $(DEV_DOCKER_COMPOSE) down
docker-test: ## Run the tests using the development containers
${DOCKER_COMPOSE} -f $(DEV_DOCKER_COMPOSE) up -d postgres
${DOCKER_COMPOSE} -f $(DEV_DOCKER_COMPOSE) run auth sh -c "make migrate_test"
${DOCKER_COMPOSE} -f $(DEV_DOCKER_COMPOSE) run auth sh -c "make test"
${DOCKER_COMPOSE} -f $(DEV_DOCKER_COMPOSE) down -v
docker-build: ## Force a full rebuild of the development containers
${DOCKER_COMPOSE} -f $(DEV_DOCKER_COMPOSE) build --no-cache
${DOCKER_COMPOSE} -f $(DEV_DOCKER_COMPOSE) up -d postgres
${DOCKER_COMPOSE} -f $(DEV_DOCKER_COMPOSE) run auth sh -c "make migrate_dev"
${DOCKER_COMPOSE} -f $(DEV_DOCKER_COMPOSE) down
docker-clean: ## Remove the development containers and volumes
${DOCKER_COMPOSE} -f $(DEV_DOCKER_COMPOSE) rm -fsv
format:
gofmt -s -w .
clean:
rm -rf \
$(addprefix release-,$(RELEASE_TARGETS)) \
$(addprefix auth-,$(RELEASE_TARGETS)) \
$(RELEASE_ARCHIVES) \
auth