-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
153 lines (115 loc) · 3.48 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Makefile - use `make` or `make help` to get a list of commands.
#
# Note - Comments inside this makefile should be made using a single
# hashtag `#`, lines with double hash-tags will be the messages that
# printed in the help command
# Name of the current directory
PROJECTNAME="go-wallhaven"
# List of all Go-files to be processed
GOFILES=$(wildcard *.go)
# Redirecting error output to a file, acts as logs that can
# be referenced if needed
STDERR=/tmp/$(PROJECTNAME)-stderr.txt
# Docker image variables
IMAGE := $(PROJECTNAME)
VERSION := latest
# Ensures firing a blank `make` command default to help
.DEFAULT_GOAL := help
# Make is verbose in Linux. Make it silent
MAKEFLAGS += --silent
.PHONY: help
## `help`: Generates this help dialog for the Makefile
help: Makefile
echo
echo " Commands available in \`"$(PROJECTNAME)"\`:"
echo
sed -n 's/^[ \t]*##//p' $< | column -t -s ':' | sed -e 's/^//'
echo
# Will install missing dependencies
.PHONY: install
## `install`: Fetch dependencies needed to run `go-wallhaven`
install:
echo " > Getting dependencies..."
go get -v $(get)
go mod tidy
.PHONY: codestyle
## :
## `codestyle`: Run code formatter(s)
codestyle:
golangci-lint run --fix
.PHONY: lint
## `lint`: Run linters and check code-style
lint:
golangci-lint run
# No `help` message for this command - designed to be consumed internally
.PHONY: --test-runner
--test-runner:
go test ./... -race -covermode=atomic -coverprofile=./coverage/coverage.txt
go tool cover -html=./coverage/coverage.txt -o ./coverage/coverage.html
.PHONY: test
## :
## `test`: Run all tests
test: export TEST_MODE=complete
test: --test-runner
.PHONY: fast-tests
## `fast-tests`: Selectively run fast tests
fast-tests: export TEST_MODE=fast
fast-tests: --test-runner
.PHONY: slow-tests
## `slow-tests`: Selectively run slow tests
slow-tests: export TEST_MODE=slow
slow-tests: --test-runner
.PHONY: test-suite
## `test-suite`: Check code style, run linters and ALL tests
test-suite: export TEST_MODE=complete
test-suite: lint test
.PHONY: run
## :
## `run`: Run `go-wallhaven` in production mode
run: export production_mode=production
run: export __BUILD_MODE__=production
run:
go run main.go $(q)
.PHONY: run-debug
## `run-debug`: Run `go-wallhaven` in debug mode
run-debug: export debug_mode=debug
run-debug: export __BUILD_MODE__=debug
run-debug:
go run main.go $(q)
.PHONY: docker-gen
## :
## `docker-gen`: Create a production docker image for `go-wallhaven`
docker-gen:
echo "Building docker image \`$(IMAGE):$(VERSION)\`..."
docker build --rm \
--build-arg final_image=scratch \
--build-arg build_mode=production \
-t $(IMAGE):$(VERSION) . \
-f ./docker/Dockerfile
.PHONY: docker-debug
## `docker-debug`: Create debug-friendly docker images for `go-wallhaven`
docker-debug:
echo "Building docker image \`$(IMAGE):$(VERSION)\`..."
docker build --rm=false \
--build-arg final_image=golang:1.18 \
--build-arg build_mode=debug \
-t $(IMAGE)-debug:$(VERSION) . \
-f ./docker/Dockerfile
.PHONY: clean-docker
## `clean-docker`: Delete an existing docker image
clean-docker:
echo "Removing docker $(IMAGE):$(VERSION)..."
docker rmi -f $(IMAGE):$(VERSION)
## :
## NOTE: All docker-related commands can use `IMAGE`
## : and `VERSION` variables to modify the docker
## : image being targeted
## :
## : Example;
## : make docker-gen IMAGE=new_project VERSION=3.15
## :
## : Likewise, both the `run` commands can pass runtime
## : arguments under the `q` arg
## :
## : Example;
## : `make run q="time --version"`