|
1 | | -SHELL := /bin/bash |
| 1 | +SHELL := /usr/bin/env bash |
2 | 2 |
|
| 3 | +## https://www.gnu.org/software/make/manual/html_node/Parallel-Disable.html |
3 | 4 | .NOTPARALLEL: |
4 | | -.SECONDEXPANSION: |
5 | | -## NOTINTERMEDIATE requires make >=4.4 |
6 | | -.NOTINTERMEDIATE: |
7 | | - |
8 | | -GO_EXEC ?= go |
9 | | -export GO_EXEC |
10 | | -DOCKER_EXEC ?= docker |
11 | | -export DOCKER_EXEC |
12 | | - |
13 | | -MODULE := $(shell cat go.mod | grep -e "^module" | sed "s/^module //") |
14 | | -VERSION ?= 0.0.0 |
15 | | -X_FLAGS = \ |
16 | | - -X '$(MODULE)/build.Version=$(VERSION)' \ |
17 | | - -X '$(MODULE)/build.Branch=$(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || true)' \ |
18 | | - -X '$(MODULE)/build.Commit=$(shell git rev-parse HEAD 2>/dev/null || true)' \ |
19 | | - -X '$(MODULE)/build.CommitShort=$(shell git rev-parse --short HEAD 2>/dev/null || true)' \ |
20 | | - -X '$(MODULE)/build.Tag=$(shell git describe --tags 2>/dev/null || true)' |
21 | | -IMAGE_NAME ?= goboilerplate |
22 | | -IMAGE_TAG ?= latest |
23 | | - |
24 | | -GO_PACKAGES = $(GO_EXEC) list -tags='$(TAGS)' -mod=vendor ./... |
25 | | -GO_FOLDERS = $(GO_EXEC) list -tags='$(TAGS)' -mod=vendor -f '{{ .Dir }}' ./... |
26 | | -GO_FILES = find . -type f -name '*.go' -not -path './vendor/*' |
27 | | - |
28 | | -export GO111MODULE := on |
29 | | -#export GOFLAGS := -mod=vendor |
30 | | -GOPATH := $(shell go env GOPATH) |
31 | | -GO_VER := $(shell go env GOVERSION) |
32 | | -BUILD_OUTPUT ?= $(CURDIR)/output |
33 | 5 |
|
| 6 | +include $(CURDIR)/scripts/go.mk |
| 7 | +include $(CURDIR)/scripts/docker.mk |
34 | 8 | include $(CURDIR)/scripts/tools.mk |
35 | 9 |
|
36 | 10 | .DEFAULT_GOAL=default |
37 | 11 | .PHONY: default |
38 | 12 | default: checks build |
39 | 13 |
|
40 | | -.PHONY: mod |
41 | | -mod: |
42 | | - $(GO_EXEC) mod tidy -go=1.23 |
43 | | - $(GO_EXEC) mod verify |
44 | | - |
45 | | -.PHONY: vendor |
46 | | -vendor: |
47 | | - $(GO_EXEC) mod vendor |
48 | | - |
49 | | -# https://go.dev/ref/mod#go-get |
50 | | -# -u flag tells go get to upgrade modules |
51 | | -# -t flag tells go get to consider modules needed to build tests of packages named on the command line. |
52 | | -# When -t and -u are used together, go get will update test dependencies as well. |
53 | | -.PHONY: go-deps-upgrade |
54 | | -go-deps-upgrade: |
55 | | - $(GO_EXEC) get -u -t ./... |
56 | | - $(GO_EXEC) mod tidy -go=1.23 |
57 | | - $(GO_EXEC) mod vendor |
58 | | - |
59 | | -# https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies |
60 | | -# https://pkg.go.dev/cmd/compile |
61 | | -# https://pkg.go.dev/cmd/link |
62 | | - |
63 | | -#BUILD_FLAGS := -mod=vendor -a -ldflags "-s -w $(X_FLAGS) -extldflags='-static'" -tags '$(TAGS)' |
64 | | -BUILD_FLAGS := -mod=vendor -a -ldflags '-s -w $(X_FLAGS)' -tags '$(TAGS)' |
65 | | -BUILD_FLAGS_DEBUG := -mod=vendor -ldflags '$(X_FLAGS)' -tags '$(TAGS)' |
66 | | - |
67 | | -.PHONY: build |
68 | | -build: $(shell ls -d cmd/* | sed -e 's/\//./') |
69 | | - |
70 | | -cmd.%: CMDNAME=$* |
71 | | -cmd.%: |
72 | | - $(GO_EXEC) env |
73 | | - @echo '' |
74 | | - CGO_ENABLED=0 $(GO_EXEC) build $(BUILD_FLAGS) -o $(BUILD_OUTPUT)/$(CMDNAME) ./cmd/$(CMDNAME) |
75 | | - |
76 | | -dbg.%: BUILD_FLAGS=$(BUILD_FLAGS_DEBUG) |
77 | | -dbg.%: cmd.% |
78 | | - @echo "debug binary done" |
79 | | - |
80 | | -.PHONY: clean |
81 | | -clean: |
82 | | - rm -rf $(BUILD_OUTPUT) |
83 | | - |
84 | 14 | # man git-clean |
85 | 15 | .PHONY: git-reset |
86 | 16 | git-reset: |
87 | 17 | git reset --hard |
88 | 18 | git clean -fd |
89 | 19 |
|
90 | | -## https://docs.docker.com/reference/cli/docker/buildx/build/ |
91 | | -## --output='type=docker' |
92 | | -## --output='type=image,push=true' |
93 | | -## --platform=linux/arm64 |
94 | | -## --platform=linux/amd64,linux/arm64,linux/arm/v7 |
95 | | -## --platform=local |
96 | | -## --progress='plain' |
97 | | -## make DOCKER_BUILD_PLATFORM=linux/arm64 image |
98 | | -DOCKER_BUILD_PLATFORM ?= local |
99 | | -DOCKER_BUILD_OUTPUT ?= type=docker |
100 | | -.PHONY: image |
101 | | -image: |
102 | | - $(DOCKER_EXEC) buildx build \ |
103 | | - --output='type=docker' \ |
104 | | - --file='$(CURDIR)/build/docker/Dockerfile' \ |
105 | | - --tag='$(IMAGE_NAME):$(IMAGE_TAG)' \ |
106 | | - --platform='$(DOCKER_BUILD_PLATFORM)' \ |
107 | | - --output='$(DOCKER_BUILD_OUTPUT)' \ |
108 | | - . |
109 | | - |
110 | | -DOCKER_COMPOSE_EXEC ?= $(DOCKER_EXEC) compose -f $(CURDIR)/deployments/local/docker-compose.yml |
111 | | - |
112 | | -.PHONY: compose-up |
113 | | -compose-up: |
114 | | - $(DOCKER_COMPOSE_EXEC) up --force-recreate --build |
115 | | - |
116 | | -.PHONY: compose-up-detach |
117 | | -compose-up-detach: |
118 | | - $(DOCKER_COMPOSE_EXEC) up --force-recreate --build --detach |
119 | | - |
120 | | -.PHONY: compose-down |
121 | | -compose-down: |
122 | | - $(DOCKER_COMPOSE_EXEC) down --volumes --rmi local --remove-orphans |
123 | | - |
124 | | -# If the first target is "compose-exec" |
125 | | -# remove the first argument 'compose-exec' and store the rest in DOCKER_COMPOSE_ARGS |
126 | | -# and ignore the subsequent arguments as make targets. |
127 | | -# (using spaces for indentation) |
128 | | -ifeq (compose-exec,$(firstword $(MAKECMDGOALS))) |
129 | | - DOCKER_COMPOSE_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) |
130 | | - $(eval $(DOCKER_COMPOSE_ARGS):;@:) |
131 | | -endif |
132 | | - |
133 | | -.PHONY: compose-exec |
134 | | -compose-exec: |
135 | | - $(DOCKER_COMPOSE_EXEC) exec $(DOCKER_COMPOSE_ARGS) |
136 | | - |
137 | 20 | .PHONY: env |
138 | 21 | env: |
139 | | - @echo "Module: $(MODULE)" |
| 22 | + @echo -e "\e[0;90m>>>\e[0m \e[0;94m Module \e[0m \e[0;90m<<<\e[0m" |
| 23 | + @echo "$(MODULE)" |
| 24 | + @echo "" |
| 25 | + |
| 26 | + @echo -e "\e[0;90m>>>\e[0m \e[0;94m Go env \e[0m \e[0;90m<<<\e[0m" |
140 | 27 | $(GO_EXEC) env |
141 | 28 | @echo "" |
142 | | - @echo ">>> Packages:" |
| 29 | + |
| 30 | + @echo -e "\e[0;90m>>>\e[0m \e[0;94m Packages \e[0m \e[0;90m<<<\e[0m" |
143 | 31 | $(GO_PACKAGES) |
144 | 32 | @echo "" |
145 | | - @echo ">>> Folders:" |
| 33 | + |
| 34 | + @echo -e "\e[0;90m>>>\e[0m \e[0;94m Folders \e[0m \e[0;90m<<<\e[0m" |
146 | 35 | $(GO_FOLDERS) |
147 | 36 | @echo "" |
148 | | - @echo ">>> Files:" |
| 37 | + |
| 38 | + @echo -e "\e[0;90m>>>\e[0m \e[0;94m Files \e[0m \e[0;90m<<<\e[0m" |
149 | 39 | $(GO_FILES) |
150 | 40 | @echo "" |
151 | | - @echo ">>> Tools:" |
| 41 | + |
| 42 | + @echo -e "\e[0;90m>>>\e[0m \e[0;94m Tools \e[0m \e[0;90m<<<\e[0m" |
152 | 43 | @echo '$(TOOLS_BIN)' |
153 | 44 | @echo "" |
154 | | - @echo ">>> Path:" |
| 45 | + |
| 46 | + @echo -e "\e[0;90m>>>\e[0m \e[0;94m Path \e[0m \e[0;90m<<<\e[0m" |
155 | 47 | @echo "$${PATH}" | tr ':' '\n' |
| 48 | + @echo "" |
156 | 49 |
|
157 | | -.PHONY: test |
158 | | -test: |
159 | | - CGO_ENABLED=1 $(GO_EXEC) test -timeout 60s -race -tags="$(TAGS)" -coverprofile cover.out -covermode atomic ./... |
160 | | - @$(GO_EXEC) tool cover -func cover.out |
161 | | - @rm cover.out |
| 50 | + @echo -e "\e[0;90m>>>\e[0m \e[0;94m Shell \e[0m \e[0;90m<<<\e[0m" |
| 51 | + @echo "SHELL=$${SHELL}" |
| 52 | + @echo "BASH=$${BASH}" |
| 53 | + @echo "BASH_VERSION=$${BASH_VERSION}" |
| 54 | + @echo "BASH_VERSINFO=$${BASH_VERSINFO}" |
| 55 | + @echo "" |
162 | 56 |
|
163 | 57 | .PHONY: checks |
164 | 58 | checks: vet staticcheck gofumpt goimports golangci-lint-github-actions |
165 | 59 |
|
166 | | -.PHONY: run |
167 | | -run: |
168 | | - $(GO_EXEC) run -mod=vendor ./cmd/goboilerplate |
169 | | - |
170 | 60 | .PHONY: ci-gen-n-format |
171 | 61 | ci-gen-n-format: goimports gofumpt |
172 | 62 | ./scripts/git-check-dirty |
173 | 63 |
|
174 | 64 | .PHONY: ci-mod |
175 | 65 | ci-mod: mod |
176 | 66 | ./scripts/git-check-dirty |
| 67 | + |
| 68 | +.PHONY: ci-sh |
| 69 | +ci-sh: shfmt shellcheck |
| 70 | + @./scripts/git-check-dirty |
0 commit comments