-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
292 lines (214 loc) · 8.59 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
PYTHON ?= python3
PACKAGE?= deadlinks
PYLINT ?= pylint
PYTEST ?= $(PYTHON) -m pytest
MYPY ?= mypy
BUILD = build
DIST = dist
BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
COMMIT = $(shell git rev-list --abbrev-commit -1 HEAD)
TAGGED = $(shell git describe)
PROCS = $(shell nproc)
export PATH := $(PWD)/bin:$(PATH)
export SHELL := bash
# --- Deadlinks: restarted ---------------------------------------------------------------
help: dep-gawk
@ echo "=============================================================================="
@ echo " Makefile: github.com/butuzov/deadlinks - links checker "
@ echo "=============================================================================="
@ cat $(MAKEFILE_LIST) | \
grep -E '^# ~~~ .*? [~]+$$|^[a-zA-Z0-9_-]+:.*?## .*$$' | \
gawk '{if ( $$1=="#" ) { \
match($$0, /^# ~~~ (.+?) [~]+$$/, a);\
{print "\n", a[1], ""}\
} else { \
match($$0, /^([a-zA-Z/_-]+):.*?## (.*)$$/, a); \
{printf " - \033[32m%-20s\033[0m %s\n", a[1], a[2]} \
}}'
@echo ""
# ~~~ Install ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
deps: venv ## install requiements
$(PYTHON) -m pip install -q -r requirements.txt
dev-env: deps clean ## Install Development Version
pip uninstall deadlinks -y
pip install -e .
# ~~~ Tests and Continues Integration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# make tests -> run tests + click integration
# make all -> runs all tests
# make docker-tests -> runs docket tests
# make brew-tests -> runs installs bre and runs brew tests
# make integration -> runs click/docker/brew
.PHONY: tests
tests: deps venv ## Run package tests (w/o integration tests)
$(PYTEST) . -m "not (docker or brew)" -n$(PROCS) --cov=$(PACKAGE);
all: ## All Tests (with integration tests)
$(PYTEST) . --randomly-dont-reorganize -n$(PROCS) \
--maxfail=10 -s -vrax --cov=$(PACKAGE);
coverage: tests ## Coverage Report (same as `make tests`)
integration: ## Integration Tests
$(PYTEST) . -m "docker or brew or click" -n$(PROCS) --cov=$(PACKAGE);
# ~~~ Linting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pylint: ## Linter: pylint
$(PYTHON) -m pylint $(PACKAGE)
pylint-full: ## Linter: pylint (with details report)
$(PYTHON) -m pylint $(PACKAGE) -r y
mypy: ## Linter: mypy
$(PYTHON) -m mypy $(PACKAGE) --config .github/configs/mypy.ini
linters: pylint mypy ### All Important Linters (pylint/mypy)
codacy-install: ## Brew Install Codacy Linters (Docker required)
brew install codacy-analysis-cli
codacy-uninstall: ## Brew Install Codacy Linters (Docker required)
@docker images | grep [c]odacy | awk '{print $3}' | xargs -L1 docker rmi
brew uninstall codacy-analysis-cli
# https://bandit.readthedocs.io/en/latest/plugins/index.html
bandit: ## Codacy Linter: Bandit (python)
codacy-analysis-cli analyse --tool bandit
remark: ## Codacy Linter: Remark (markdown)
codacy-analysis-cli analyse --tool remark-int
# https://prospector.readthedocs.io/en/master/
prospector: ## Codacy Linter: Prospector (python)
codacy-analysis-cli analyse --tool prospector
# Codacy Code Analysis
# https://github.com/codacy/codacy-analysis-cli#install
# https://support.codacy.com/hc/en-us/articles/115002130625
codacity-config: ## Codacy: Check .codacy.yml
codacy-analysis-cli validate-configuration --directory `pwd`
codacy: bandit prospector docker remark ## Codacy: Linters (All)
hadolint-install: ## Docker: Install hadolint (Dockerfile)
@brew install hadolint
# https://github.com/hadolint/hadolint
hadolint-check: ## Docker: Run hadolint (Dockerfile)
hadolint --config .github/configs/hadolint.yaml Dockerfile
# ~~~ Documentation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.PHONY: docs
docs: ## Documentation Build Pipeline
$(MAKE) docs-build
$(MAKE) docs-browse
$(MAKE) docs-ci
docs-browse: ghp
ghp -root=build/html -port=5678 &
open http://localhost:5678
docs-build: venv ## Generate Documentation
@$(PYTHON) -m pip install Sphinx sphinx-rtd-theme -q;
@$(PYTHON) -m pip install recommonmark sphinx-markdown-tables -q;
sphinx-build docs build/html -qW --keep-going;
docs-ci: venv ## Documentation CI
deadlinks internal --root=build/html --no-progress --fiff
docs-stop: ## Documentation WebServer: Stop
@ps -a | grep '[g]hp -root=build/html -port=5678' --color=never \
| awk '{print $$1}' | xargs -L1 kill -9
# ~~~ Brew (Package Manager for macoS) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
brew-env:
@ $(PYTHON) -m venv .brew;
@ source .brew/bin/activate;
@ $(PYTHON) -m pip install --upgrade pip requests Jinja2 -q;\
brew-prod: brew-env ## Create & Install Formula (Production)
@brew uninstall deadlinks -f
@echo "Creating formula (prod)..."
@ $(PYTHON) make_brew_formula.py
$(MAKE) brew-audit
@echo "Formula ready to be published"
brew-dev: build-prod ## Create & Install Formula (Development)
@brew uninstall deadlinks -f
@echo "Creating formula (dev)..."
$(MAKE) brew-web-start
@ $(PYTHON) make_brew_formula.py --dev
@ $(MAKE) brew-audit
@ $(MAKE) brew-install
$(MAKE) brew-web-stop
brew-install: ## Local Formula Installation
@if [ -f "deadlinks.rb" ]; then\
sleep 5;\
brew install --include-test deadlinks.rb;\
else\
echo ">>>>>> deadlinks.rb not found";\
exit 1;\
fi
brew-audit: ## Formula: Audit
@if [ -f "deadlinks.rb" ]; then\
brew audit --new-formula deadlinks.rb;\
brew audit --strict deadlinks.rb;\
else\
echo ">>>>>> deadlinks.rb not found";\
exit 1;\
fi
brew-web-start: ghp # Start Server (Serves dev pacakge)
@ghp -port=8878 2>&1 1>/dev/null &
brew-web-stop: # Stop Server (Serves dev pacakge)
@ps -a | grep '[g]hp -port=8878' --color=never \
| awk '{print $$1}' | xargs -L1 kill -9
brew-tests: venv brew-dev clean dev-env
$(PYTEST) . -m "brew" -n$(PROCS) --cov=$(PACKAGE);
# ~~~ Deployments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
build-prod: venv clean ## Build disto (source & wheel) - Production
@ $(PYTHON) setup.py sdist bdist_wheel > /dev/null 2>&1
build-dev: venv clean ## Build disto (source & wheel) - Development
@ \
DEADLINKS_BRANCH=$(BRANCH) \
DEADLINKS_COMMIT=$(COMMIT) \
DEADLINKS_TAGGED=$(TAGGED) \
$(PYTHON) setup.py sdist bdist_wheel > /dev/null 2>&1
clean: ## Cleanup Build artifacts
@echo "Cleanup Temporary Files"
@rm -rf ${DIST}
@rm -rf ${BUILD}
@rm -f deadlinks/__develop__.py
deploy:
@ $(PYTHON) -m pip install --upgrade wheel twine -q
deploy-test: deploy build-dev ## PyPi Deploy (test.pypi.org)
twine upload --repository-url https://test.pypi.org/legacy/ dist/*;\
deploy-prod: deploy build-prod ## PyPi Deploy (pypi.org)
twine upload --repository-url https://upload.pypi.org/legacy/ dist/*;\
pre-depeloy-check: venv clean deps ## Install Development Version
$(PYTHON) -m pip uninstall deadlinks -y
DEADLINKS_BRANCH=$(BRANCH) \
DEADLINKS_COMMIT=$(COMMIT) \
DEADLINKS_TAGGED=$(TAGGED) \
$(PYTHON) setup.py develop -q 2>&1 1> /dev/null
# ~~~ Docker ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
docker-clean: ## Clean untagged images
@docker ps -q -f "status=exited" | xargs -L1 docker rm
@docker images -q -f "dangling=true" | xargs -L1 docker rmi
@docker images | grep [b]utuzov/deadlinks | awk '{print $3}' | xargs -L1 docker rmi
docker-build: clean ## Build Image
@docker build . -t deadlinks:local --no-cache
docker-tests: venv ## Docker Integration Testing
$(PYTEST) . -m "docker" -n$(PROCS);
docker: ## Quick test
@docker run --rm -it --network=host deadlinks:local --version
# Helper Mehtods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dep-gawk:
@ if [ -z "$(shell command -v gawk)" ]; then \
if [ -x /usr/local/bin/brew ]; then $(MAKE) _brew_gawk_install; exit 0; fi; \
if [ -x /usr/bin/apt-get ]; then $(MAKE) _ubuntu_gawk_install; exit 0; fi; \
if [ -x /usr/bin/yum ]; then $(MAKE) _centos_gawk_install; exit 0; fi; \
if [ -x /sbin/apk ]; then $(MAKE) _alpine_gawk_install; exit 0; fi; \
echo "GNU Awk Required.";\
exit 1; \
fi
_brew_gawk_install:
@ echo "Instaling gawk using brew... "
@ brew install gawk --quiet
@ echo "done"
_ubuntu_gawk_install:
@ echo "Instaling gawk using apt-get... "
@ apt-get -q install gawk -y
@ echo "done"
_alpine_gawk_install:
@ echo "Instaling gawk using yum... "
@ apk add --update --no-cache gawk
@ echo "done"
_centos_gawk_install:
@ echo "Instaling gawk using yum... "
@ yum install -q -y gawk;
@ echo "done"
venv:
@ if [[ ! -z "${GITHUB_ENV}" ]]; then \
echo ">>>>> This is CI. Please Continue!";\
exit 0;\
elif [[ -z "${VIRTUAL_ENV}" ]]; then\
echo ">>>>> You need to run this test in virtual environment. Abort!";\
exit 1;\
else \
echo ">>>>> Oh Hi Mark";\
fi