-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
133 lines (109 loc) · 4.63 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
123
124
125
126
127
128
129
130
131
132
133
SHELL := /usr/bin/env bash -Eeu -o pipefail
REPO_ROOT := $(shell git rev-parse --show-toplevel)
MAKEFILE_DIR := $(shell { cd "$(subst /,,$(dir $(lastword ${MAKEFILE_LIST})))" && pwd; } || pwd)
DOTLOCAL_DIR := ${MAKEFILE_DIR}/.local
DOTLOCAL_BIN_DIR := ${DOTLOCAL_DIR}/bin
PACKAGE_NAME := github.com/hakadoriya/z.go
export PATH := ${DOTLOCAL_BIN_DIR}:${REPO_ROOT}/.bin:${PATH}
.DEFAULT_GOAL := help
.PHONY: help
help: ## Display this help documents
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' ${MAKEFILE_LIST} | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-40s\033[0m %s\n", $$1, $$2}'
.PHONY: setup
setup: ## Setup tools for development
# == SETUP =====================================================
# versenv
make versenv
# --------------------------------------------------------------
.PHONY: versenv
versenv:
# direnv
direnv allow .
# golangci-lint
golangci-lint --version
.PHONY: clean
clean: ## Clean up cache, etc
# reset tmp
rm -rf ${MAKEFILE_DIR}/.tmp
mkdir -p ${MAKEFILE_DIR}/.tmp
# go build cache
go env GOCACHE
go clean -x -cache -testcache -modcache -fuzzcache
# golangci-lint cache
golangci-lint cache status
golangci-lint cache clean
.PHONY: lint
lint: ## Run secretlint, go mod tidy, golangci-lint
# typo
typos
# Update README.md
update-readme
# gitleaks ref. https://github.com/gitleaks/gitleaks
gitleaks detect --source . -v
# tidy
go-mod-all tidy
# golangci-lint
# ref. https://golangci-lint.run/usage/linters/
golangci-lint run -c "${REPO_ROOT}/.golangci.yml" --fix --sort-results --verbose --timeout=5m
# diff
git diff --exit-code
.PHONY: test
test: ## Run go test and display coverage
@[ -x "${DOTLOCAL_BIN_DIR}/godotnev" ] || GOBIN="${DOTLOCAL_BIN_DIR}" go install github.com/joho/godotenv/cmd/godotenv@latest
# Unit testing
godotenv -f .test.env go test -v -race -p=4 -parallel=8 -timeout=300s -cover -coverprofile=./coverage.txt.tmp ./... ; grep -v -e "/buildinfoz/" -e "/buildz/" -e "/example/" -e "/testingz/" -e ".deprecated.go" -e ".generated.go" -e ".gen.go" ./coverage.txt.tmp > ./coverage.txt
go tool cover -func=./coverage.txt
.PHONY: bench
bench: ## Run benchmarks
cd integrationtest && go test -run "^NoSuchTestForBenchmark" -benchmem -bench . ${PACKAGE_NAME}/integrationtest/database/sql -v -trimpath -race -p=4 -parallel=8 -timeout=30s
.PHONY: ci
ci: lint test ## CI command set
.PHONY: up
up: ## Run docker compose up --wait -d
# Run in background (If failed to start, output logs and exit abnormally)
#if ! docker compose up --wait -d; then docker compose logs; exit 1; fi
.PHONY: ps
ps: ## Run docker compose ps
#docker compose ps
.PHONY: down
down: ## Run docker compose down
#docker compose down
.PHONY: reset
reset: ## Run docker compose down and Remove volumes
#docker compose down --volumes
.PHONY: rmi
rmi: ## Run docker compose down and Remove all images, orphans
#docker compose down --rmi all --remove-orphans
.PHONY: restart
restart: ## Restart docker compose
#-make down
#make up
.PHONY: logs
logs: ## Tail docker compose logs
#@printf '[\033[36mNOTICE\033[0m] %s\n' "If want to go back prompt, enter Ctrl+C"
#docker compose logs -f
.PHONY: update-readme
update-readme: ## Update README.md
# Generate README.md
update-readme
.PHONY: release
release: ## git tag per go modules for release
${REPO_ROOT}/.bin/git-tag-go-mod
.PHONY: act-check
act-check:
@if ! command -v act >/dev/null 2>&1; then \
printf "\033[31;1m%s\033[0m\n" "act is not installed: brew install act" 1>&2; \
exit 1; \
fi
.PHONY: act-go-mod-tidy
act-go-mod-tidy: act-check ## Run go-mod-tidy workflow in act
# NOTE: ACTIONS_CACHE_URL should indicate NOT SUCH URL to avoid cache action waiting timeout (otherwise you waste so much time)
act pull_request --container-architecture linux/amd64 -P ubuntu-latest=catthehacker/ubuntu:act-latest -W .github/workflows/go-mod-tidy.yml --env ACTIONS_CACHE_URL=http://127.0.0.404:404/
.PHONY: act-go-lint
act-go-lint: act-check ## Run go-lint workflow in act
# NOTE: ACTIONS_CACHE_URL should indicate NOT SUCH URL to avoid cache action waiting timeout (otherwise you waste so much time)
act pull_request --container-architecture linux/amd64 -P ubuntu-latest=catthehacker/ubuntu:act-latest -W .github/workflows/go-lint.yml --env ACTIONS_CACHE_URL=http://127.0.0.404:404/
.PHONY: act-go-test
act-go-test: act-check ## Run go-test workflow in act
# NOTE: ACTIONS_CACHE_URL should indicate NOT SUCH URL to avoid cache action waiting timeout (otherwise you waste so much time)
act pull_request --container-architecture linux/amd64 -P ubuntu-latest=catthehacker/ubuntu:act-latest -W .github/workflows/go-test.yml --env ACTIONS_CACHE_URL=http://127.0.0.404:404/