generated from devnw/oss-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
122 lines (95 loc) · 3.41 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
all: deps tidy fmt build test lint
op=op run --env-file="./.env" --
opact=op run --env-file="./.env.act" --
#-------------------------------------------------------------------------
# Variables
# ------------------------------------------------------------------------
SHELL := $(shell which bash)
fuzzsh=https://raw.githubusercontent.com/devnw/workflows/refs/heads/main/fuzz.sh
env=CGO_ENABLED=0
pyenv=.venv/bin
#-------------------------------------------------------------------------
# Targets
#-------------------------------------------------------------------------
deps:
python3 -m venv .venv
$(pyenv)/pip install --upgrade pre-commit
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install github.com/goreleaser/goreleaser@latest
ci-test-deps:
# install act
if [ ! -d .act ]; then make install-act; git clone git@github.com:nektos/act.git .act; fi
cd .act && git pull && sudo make install
test: lint
CGO_ENABLED=1 go test -cover -failfast -race ./...
fuzz:
curl -fsSL $(fuzzsh) | $(SHELL)
bench:
go test -bench=. -benchmem ./...
lint: tidy
golangci-lint run
$(pyenv)/pre-commit run --all-files
build: update upgrade tidy lint test
$(env) go build ./...
release: build-ci
goreleaser release --snapshot --clean
upgrade:
$(pyenv)/pre-commit autoupdate
go get -u ./...
update:
git submodule update --recursive
fmt:
gofmt -s -w .
tidy: fmt
go mod tidy
clean:
rm -rf dist
rm -rf coverage
rm -rf .act
rm -rf .venv
#-------------------------------------------------------------------------
# Git targets
#-------------------------------------------------------------------------
tag:
@latest_tag=$$(git describe --tags `git rev-list --tags --max-count=1`); \
current_major=$$(echo $$latest_tag | cut -d. -f1); \
current_minor=$$(echo $$latest_tag | cut -d. -f2); \
current_patch=$$(echo $$latest_tag | cut -d. -f3); \
next_minor=$$((current_minor + 1)); \
default_version="$$current_major.$$next_minor.$$current_patch"; \
read -p "Enter the version number [$$default_version]: " version; \
version=$${version:-$$default_version}; \
commits=$$(git log $$latest_tag..HEAD --pretty=format:"%h %s" | awk '{print "- " $$0}'); \
git tag -a $$version -m "Release $$version" -m "$$commits"; \
git push origin $$version
#-------------------------------------------------------------------------
# CI targets
#-------------------------------------------------------------------------
build-ci: deps
$(env) go build ./...
CGO_ENABLED=1 go test \
-cover \
-covermode=atomic \
-coverprofile=coverage.txt \
-failfast \
-race ./...
make fuzz FUZZ_TIME=10
bench-ci: build-ci
go test -bench=. ./... | tee output.txt
release-ci: build-ci
goreleaser release --clean
test-ci:
DOCKER_HOST=$(shell docker context inspect --format='{{json .Endpoints.docker.Host}}' $(shell docker context show)) \
$(opact) act \
-s GIT_CREDENTIALS \
-s GITHUB_TOKEN="$(shell gh auth token)" \
--var GO_VERSION \
--var ALERT_CC_USERS
#-------------------------------------------------------------------------
# Force targets
#-------------------------------------------------------------------------
FORCE:
#-------------------------------------------------------------------------
# Phony targets
#-------------------------------------------------------------------------
.PHONY: build test lint fuzz bench fmt tidy clean release update upgrade deps translate test-act ci-test-deps