-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMakefile
More file actions
170 lines (139 loc) · 8.29 KB
/
Copy pathMakefile
File metadata and controls
170 lines (139 loc) · 8.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
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
-include .env
export
LOCAL_BIN:=$(CURDIR)/bin
PATH:=$(LOCAL_BIN):$(PATH)
# HELP =================================================================================================================
# This will output the help for each task
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help
help: ## Display this help screen
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-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)
compose-up: ### Run docker compose
docker compose up --build -d postgres && docker compose logs -f
.PHONY: compose-up
compose-up-integration-test: ### Run docker compose with integration test
docker compose up --build --abort-on-container-exit --exit-code-from integration
.PHONY: compose-up-integration-test
compose-down: ### Down docker compose
docker compose down --remove-orphans
.PHONY: compose-down
run: ### run app
go mod tidy && go mod download && \
GIN_MODE=debug CGO_ENABLED=0 go run ./cmd/app
.PHONY: run
run-noui: ### run app without UI
go mod tidy && go mod download && \
GIN_MODE=debug CGO_ENABLED=0 go run -tags=noui ./cmd/app
.PHONY: run-noui
openapi: ### generate OpenAPI spec to doc/openapi.json
go run ./cmd/openapi-gen
.PHONY: openapi
build: ### build app
CGO_ENABLED=0 go build -o ./bin/console ./cmd/app
.PHONY: build
build-noui: ### build app without UI
CGO_ENABLED=0 go build -tags=noui -o ./bin/console-noui ./cmd/app
.PHONY: build-noui
# Linux builds use -buildmode=pie for ASLR. Windows PE and macOS Mach-O binaries
# are already position independent without the flag, so it is only applied to the
# Linux targets. A PIE ELF requires the glibc dynamic loader at runtime, so the
# scratch-based container image in Dockerfile is deliberately built without it.
build-all-platforms: ### cross-compile for all platforms (Linux, Windows, macOS)
@echo "Building for all platforms using cross-compilation (CGO_ENABLED=0)..."
@mkdir -p dist/linux dist/windows dist/darwin
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -buildmode=pie -ldflags "-s -w" -trimpath -o dist/linux/console_linux_x64 ./cmd/app
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags=noui -buildmode=pie -ldflags "-s -w" -trimpath -o dist/linux/console_linux_x64_headless ./cmd/app
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w" -trimpath -o dist/windows/console_windows_x64.exe ./cmd/app
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -tags=noui -ldflags "-s -w" -trimpath -o dist/windows/console_windows_x64_headless.exe ./cmd/app
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w" -trimpath -o dist/darwin/console_mac_arm64 ./cmd/app
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -tags=noui -ldflags "-s -w" -trimpath -o dist/darwin/console_mac_arm64_headless ./cmd/app
@echo "All platform binaries built successfully!"
.PHONY: build-all-platforms
docker-rm-volume: ### remove docker volume
docker volume rm go-clean-template_pg-data
.PHONY: docker-rm-volume
linter-golangci: ### check by golangci linter
golangci-lint run
.PHONY: linter-golangci
linter-hadolint: ### check by hadolint linter
git ls-files --exclude='Dockerfile*' --ignored | xargs hadolint
.PHONY: linter-hadolint
linter-dotenv: ### check by dotenv linter
dotenv-linter
.PHONY: linter-dotenv
test: ### run test
go test -v -cover -race ./...
.PHONY: test
FUZZ_ROOT ?= internal
FUZZTIME ?= 30s
fuzz-list: ### list all fuzz targets as '<package> <target>'
@set -eu; \
find $(FUZZ_ROOT) -name '*fuzz_test.go' -exec dirname {} \; | sort -u | while read -r dir; do \
pkg="./$$dir"; \
go test "$$pkg" -list '^Fuzz' 2>/dev/null | grep '^Fuzz' | while read -r target; do \
echo "$$pkg $$target"; \
done; \
done
.PHONY: fuzz-list
fuzz-one: ### run one fuzz target, e.g. make fuzz-one PKG=./internal/usecase/devices TARGET=FuzzParseInterval FUZZTIME=30s
@if [ -z "$(PKG)" ] || [ -z "$(TARGET)" ]; then \
echo "usage: make fuzz-one PKG=./path TARGET=FuzzTarget [FUZZTIME=30s]"; \
exit 1; \
fi
go test "$(PKG)" -run=^$$ -fuzz="^$(TARGET)$$" -fuzztime="$(FUZZTIME)"
.PHONY: fuzz-one
fuzz-smoke: ### run all fuzz targets once (quick CI smoke)
$(MAKE) fuzz-all FUZZTIME=1x
.PHONY: fuzz-smoke
fuzz-all: ### run all fuzz targets sequentially with FUZZTIME per target
@set -eu; \
find $(FUZZ_ROOT) -name '*fuzz_test.go' -exec dirname {} \; | sort -u | while read -r dir; do \
pkg="./$$dir"; \
targets=$$(go test "$$pkg" -list '^Fuzz' 2>/dev/null | grep '^Fuzz' || true); \
for target in $$targets; do \
echo "==> $$pkg $$target (FUZZTIME=$(FUZZTIME))"; \
go test "$$pkg" -run=^$$ -fuzz="^$${target}$$" -fuzztime="$(FUZZTIME)"; \
done; \
done
.PHONY: fuzz-all
integration-test: ### run integration-test
go clean -testcache && go test -v ./integration-test/...
.PHONY: integration-test
mock: ### run mockgen
mockgen -source ./internal/usecase/ciraconfigs/interfaces.go -package mocks -mock_names Repository=MockCIRAConfigsRepository,Feature=MockCIRAConfigsFeature > ./internal/mocks/ciraconfigs_mocks.go
mockgen -source ./internal/usecase/devices/interfaces.go -package mocks -mock_names Repository=MockDeviceManagementRepository,Feature=MockDeviceManagementFeature > ./internal/mocks/devicemanagement_mocks.go
mockgen -source ./internal/usecase/amtexplorer/interfaces.go -package mocks -mock_names Repository=MockAMTExplorerRepository,Feature=MockAMTExplorerFeature,WSMAN=MockAMTExplorerWSMAN > ./internal/mocks/amtexplorer_mocks.go
mockgen -source ./internal/usecase/devices/wsman/interfaces.go -package mocks > ./internal/mocks/wsman_mocks.go
mockgen -source ./internal/usecase/export/interface.go -package mocks > ./internal/mocks/export_mocks.go
mockgen -source ./internal/usecase/domains/interfaces.go -package mocks -mock_names Repository=MockDomainsRepository,Feature=MockDomainsFeature > ./internal/mocks/domains_mocks.go
mockgen -source ./internal/controller/ws/v1/interface.go -package mocks > ./internal/mocks/wsv1_mocks.go
mockgen -source ./pkg/logger/logger.go -package mocks -mock_names Interface=MockLogger > ./internal/mocks/logger_mocks.go
mockgen -source ./internal/usecase/ieee8021xconfigs/interfaces.go -package mocks -mock_names Repository=MockIEEE8021xConfigsRepository,Feature=MockIEEE8021xConfigsFeature > ./internal/mocks/ieee8021xconfigs_mocks.go
mockgen -source ./internal/usecase/profiles/interfaces.go -package mocks -mock_names Repository=MockProfilesRepository,Feature=MockProfilesFeature > ./internal/mocks/profiles_mocks.go
mockgen -source ./internal/usecase/wificonfigs/interfaces.go -package mocks -mock_names Repository=MockWiFiConfigsRepository,Feature=MockWiFiConfigsFeature > ./internal/mocks/wificonfigs_mocks.go
mockgen -source ./internal/usecase/profilewificonfigs/interfaces.go -package mocks -mock_names Repository=MockProfileWiFiConfigsRepository,Feature=MockProfileWiFiConfigsFeature > ./internal/mocks/profileswificonfigs_mocks.go
mockgen -source ./internal/app/interface.go -package mocks > ./internal/mocks/app_mocks.go
.PHONY: mock
migrate-create: ### create new migration
migrate create -ext sql -dir /internal/app/migrations 'migrate_name'
.PHONY: migrate-create
# Mirror pkg/db.MigrationDSN: default sslmode=disable only when DB_URL doesn't
# set one, using the right separator for a DSN that already carries query params.
ifeq (,$(DB_URL))
MIGRATE_DB_URL :=
else ifneq (,$(findstring sslmode=,$(DB_URL)))
MIGRATE_DB_URL := $(DB_URL)
else ifeq (,$(findstring ?,$(DB_URL)))
MIGRATE_DB_URL := $(DB_URL)?sslmode=disable
else
MIGRATE_DB_URL := $(DB_URL)&sslmode=disable
endif
migrate-up: ### migration up
migrate -path /internal/app/migrations -database '$(MIGRATE_DB_URL)' up
.PHONY: migrate-up
bin-deps:
GOBIN=$(LOCAL_BIN) go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
GOBIN=$(LOCAL_BIN) go install go.uber.org/mock/mockgen@latest
build-tray: ### build app with system tray support (requires CGO, native build only)
CGO_ENABLED=1 go build -tags=tray -o ./bin/console-tray ./cmd/app
.PHONY: build-tray