-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
84 lines (64 loc) · 2.59 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
#!/usr/bin/make -f
# Go version and build settings
GO_VERSION := 1.23
GO_SYSTEM_VERSION := $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1-2)
REQUIRE_GO_VERSION := $(GO_VERSION)
# Project version
WEAVE_VERSION := $(shell git describe --tags)
# Build directory
BUILDDIR ?= $(CURDIR)/build
# Build targets
BUILD_TARGETS := build install test
release_version=$(filter-out $@,$(MAKECMDGOALS))
# Version check
check_version:
@if [ $(shell echo "$(GO_SYSTEM_VERSION) < $(REQUIRE_GO_VERSION)" | bc -l) -eq 1 ]; then \
echo "ERROR: Go version $(REQUIRE_GO_VERSION) is required for Weave."; \
exit 1; \
fi
# Build settings
LDFLAGS := -X github.com/initia-labs/weave/cmd.Version=$(WEAVE_VERSION)
dev: check_version
go install -ldflags "$(LDFLAGS) -X github.com/initia-labs/weave/analytics.AmplitudeKey=aba1be3e2335dd5b8b060e977d93410b" .
# Build targets
build: check_version $(BUILDDIR)
go build -mod=readonly -ldflags "$(LDFLAGS)" -o $(BUILDDIR)/weave .
install: check_version
go install -ldflags "$(LDFLAGS)" .
.PHONY: lint lint-fix
# Run golangci-lint to check code quality
lint: check_version
@command -v golangci-lint >/dev/null 2>&1 || { echo "golangci-lint is required but not installed. Install it by following instructions at https://golangci-lint.run/welcome/install/"; exit 1; }
golangci-lint run --out-format=tab --timeout=15m
# Run golangci-lint and automatically fix issues where possible (use with caution)
lint-fix: check_version
@echo "Warning: This will automatically modify your files to fix linting issues"
@read -p "Are you sure you want to continue? [y/N] " -n 1 -r; echo; if [[ ! $$REPLY =~ ^[Yy]$$ ]]; then exit 1; fi
@command -v golangci-lint >/dev/null 2>&1 || { echo "golangci-lint is required but not installed. Install it by following instructions at https://golangci-lint.run/welcome/install/"; exit 1; }
golangci-lint run --fix --out-format=tab --timeout=15m
test: check_version
go clean -testcache
go test -v ./...
integration-test: check_version
go clean -testcache
go test -v ./... -tags=integration
test-all: test integration-test
precommit: lint test-all
# Release process
release:
@if [ -z "$(release_version)" ]; then \
echo "ERROR: You must provide a release version. Example: make release v0.0.15"; \
exit 1; \
fi
git tag -a $(release_version) -m "$(release_version)"
git push origin $(release_version)
@echo "Paste the release notes below (end with Ctrl+D):"
@notes=$$(cat); \
gh release create $(release_version) --title "$(release_version)" --notes "$$notes"
# Development purpose
local: build
clear
./build/weave opinit init
# Catch-all target
%:
@: