forked from OWASP/cornucopia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
97 lines (80 loc) · 2.73 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
DOCKER = docker run \
--interactive \
--rm \
--env "HOST_IP=$(HOST_IP)" \
--env "MYPYPATH=${PWD}/typings" \
--env "RETRY_DELAY=${RETRY_DELAY}" \
--env "UPDATE_GOLDEN_FILES=$(UPDATE_GOLDEN_FILES)" \
--volume "$(PWD):${PWD}" \
--volume "/var/run/docker.sock:/var/run/docker.sock" \
--workdir "${PWD}"
SHELL := /bin/bash
.SHELLFLAGS := -euo pipefail -O globstar -c
HOST_IP ?= $(shell ip addr show dev docker0 | grep -oP "(?<=inet )[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")
RETRY_DELAY = 0.01
PYTHON_TEST_PATTERN ?= "*_?test.py" # Default to all types of tests
PYTHON_COVERAGE_MIN = 85 # %
PYTHON_VERSION = $(shell head -1 .python-version)
.PHONY: shfmt shellcheck pipenv
shfmt shellcheck pipenv:
@docker build \
--tag $@ \
--build-arg PYTHON_VERSION=$(PYTHON_VERSION) \
--build-arg "user_id=$(shell id -u)" \
--build-arg "group_id=$(shell id -g)" \
--build-arg "home=${HOME}" \
--build-arg "workdir=${PWD}" \
--target $@ . \
>/dev/null
.PHONY: fmt
fmt: shfmt pipenv
@$(DOCKER) shfmt -l -w .
@$(DOCKER) pipenv run black --line-length=120 .
.PHONY: fmt-check
fmt-check: shfmt pipenv
@$(DOCKER) shfmt -d .
@$(DOCKER) pipenv run black --line-length=120 --check .
.PHONY: static-check
static-check: pipenv
@$(DOCKER) pipenv run flake8 --max-line-length=120 --max-complexity=10 --ignore=E203,W503 --exclude ./.venv/
@$(DOCKER) pipenv run mypy --namespace-packages --strict ./scripts/
.PHONY: coverage-check
coverage-check: python-coverage-only
.PHONY: test
test: python-unit-test python-integration-test
@$(MAKE) -C docker smoke-test
.PHONY: python-test
python-test: pipenv
@$(DOCKER) pipenv run coverage run \
--append \
--branch \
--omit "*_?test.py,*/.local/*" \
--module unittest \
discover \
--verbose \
--start-directory "tests/scripts" \
--pattern $(PYTHON_TEST_FILE)$(PYTHON_TEST_PATTERN)
.PHONY: python-unit-test
python-unit-test:
@$(MAKE) python-test PYTHON_TEST_PATTERN="*_utest.py" PYTHON_TEST_FILE=$(PYTHON_TEST_FILE)
.PHONY: python-integration-test
python-integration-test:
@$(MAKE) python-test PYTHON_TEST_PATTERN="*_itest.py" PYTHON_TEST_FILE=$(PYTHON_TEST_FILE)
.PHONY: python-coverage-only
python-coverage-only:
@$(DOCKER) pipenv run coverage xml
@$(DOCKER) pipenv run coverage report --fail-under $(PYTHON_COVERAGE_MIN)
.PHONY: python-coverage
python-coverage:
-@rm .coverage
@$(MAKE) python-unit-test
@$(MAKE) python-integration-test
@$(MAKE) python-coverage-only
.PHONY: python-test-update-golden-files
python-test-update-golden-files:
UPDATE_GOLDEN_FILES=true $(MAKE) python-unit-test PYTHON_TEST_FILE=$(PYTHON_TEST_FILE)
UPDATE_GOLDEN_FILES=true $(MAKE) python-integration-test PYTHON_TEST_FILE=$(PYTHON_TEST_FILE)
.PHONY: google-account
google-account:
.PHONY: ready
ready: fmt static-check python-coverage