-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
170 lines (129 loc) · 5.34 KB
/
Makefile
File metadata and controls
170 lines (129 loc) · 5.34 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
## REFERENCES:
## (1) Passing environment variable with fallback value to Makefile:
## https://stackoverflow.com/a/70772707/6366150
## (2) Export environment variables inside "make environment"
## https://stackoverflow.com/a/49524393/6366150
## (3) Uppercase to lowercase and vice versa
## https://community.unix.com/t/uppercase-to-lowercase-and-vice-versa/285278/6
## (4) How do I trim leading and trailing whitespace from each line of some output?
## https://unix.stackexchange.com/a/279222/233927
############################################################################
## (1) ## Allowed values: info | warn | error | debug
LOG_LEVEL ?= info
## (3) (4)
LOG_LEVEL :=$(shell echo '${LOG_LEVEL}'| tr '[:lower:]' '[:upper:]'| tr -d '[:blank:]')
## (1) ## Allowed values: true | false
BRUTEFORCE ?= false
## (3) (4)
BRUTEFORCE :=$(shell echo '${BRUTEFORCE}'| tr '[:lower:]' '[:upper:]'| tr -d '[:blank:]')
# DOCKER
DOCKER_COMPOSE=docker compose
ifeq ($(BRUTEFORCE),1)
add_bruteforce=-tags bruteforce
endif
ifeq ($(BRUTEFORCE),TRUE)
add_bruteforce=-tags bruteforce
endif
# Package Manager
GO=go
GOTEST=$(GO) test -count=1 -v $(add_bruteforce)
GOCOVER=$(GO) tool cover
PKG_LIST=$(go list ./... | grep -v /vendor/ | tr '\n' ' '| xargs echo -n)
# DOCKER
BUILDKIT_PROGRESS=plain
CGO_ENABLED=0
# Modernize tool versioning
# Go 1.25 requires gopls v0.21.0+
# Go 1.24 and below should use gopls v0.20.0
GO_VERSION := $(shell go version | cut -d' ' -f3 | sed 's/go//')
MODERNIZE_VER := v0.20.0
# Check if Go version is 1.25 or higher
IS_GO_125 := $(shell echo "$(GO_VERSION)" | awk -F. '{if ($$1 > 1 || ($$1 == 1 && $$2 >= 25)) print 1; else print 0}')
ifeq ($(IS_GO_125),1)
MODERNIZE_VER := latest
endif
# Use GOTOOLCHAIN=auto to ensure the required toolchain is available if needed
MODERNIZE_CMD := GOTOOLCHAIN=auto $(GO) run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@$(MODERNIZE_VER)
.MAIN: test/coverage
.PHONY: all clean coverage dependencies help list test
.EXPORT_ALL_VARIABLES: # (2)
help: list
list:
@echo "Environment variables:"
@echo "LOG_LEVEL = info | warn | error | debug"
@echo "BRUTEFORCE = true | false"
@echo ""
@echo "Posible make commands:"
@LC_ALL=C $(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$'
env:
@echo "################################################################################"
@echo "## Environment: ################################################################"
@echo "################################################################################"
@printenv | grep -E "LOG_LEVEL|BRUTEFORCE"
@echo "################################################################################"
dependencies:
@echo "################################################################################"
@echo "## Dependencies: ###############################################################"
@echo "################################################################################"
$(GO) mod download -x
$(GO) mod verify
@echo "################################################################################"
lint/markdown:
markdownlint '**/*.md' --ignore node_modules && echo '✔ Your code looks good.'
lint/yaml:
yamllint --stric . && echo '✔ Your code looks good.'
lint: lint/markdown lint/yaml test/styling test/static
test/static: dependencies
$(GO) vet -v ./...
golangci-lint --verbose run ./...
test/styling: dependencies
gofmt -l . && echo '✔ Your code looks good.'
$(MODERNIZE_CMD) -test ./...
format:
$(MODERNIZE_CMD) -fix ./...
coverage.out: env dependencies
$(GOTEST) -v -covermode=atomic -coverprofile="coverage.out" ./exercises/...
test: env dependencies coverage.out
$(GOCOVER) -func=coverage.out
coverage: test
coverage/html: coverage.out
$(GOCOVER) -html=coverage.out -o ./coverage/coverage.html
open ./coverage/coverage.html
outdated:
$(GO) list -m -u all
update: dependencies outdated
$(GO) get -u all
$(GO) get -t -u ./...
$(GO) mod tidy
upgrade: update
clean:
$(GO) clean -testcache
rm -vfr ./coverage
mkdir -p ./coverage
touch ./coverage/.gitkeep
build: env dependencies
$(GO) build -v -o bin/ ./...
compose/build: env
${DOCKER_COMPOSE} --profile lint build
${DOCKER_COMPOSE} --profile testing build
${DOCKER_COMPOSE} --profile production build
compose/rebuild: env
${DOCKER_COMPOSE} --profile lint build --no-cache
${DOCKER_COMPOSE} --profile testing build --no-cache
${DOCKER_COMPOSE} --profile production build
compose/lint/markdown: compose/build
${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-go-lint make lint/markdown
compose/lint/yaml: compose/build
${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-go-lint make lint/yaml
compose/test/styling: compose/build
${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-go-lint make test/styling
compose/test/static: compose/build
${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-go-lint make test/static
compose/lint: compose/lint/markdown compose/lint/yaml compose/test/styling compose/test/static
compose/test: compose/build
${DOCKER_COMPOSE} --profile testing run --rm algorithm-exercises-go-test make test
compose/run: compose/build
${DOCKER_COMPOSE} --profile production run --rm algorithm-exercises-go
all: test coverage
run:
ls -alh