-
Notifications
You must be signed in to change notification settings - Fork 22
/
Makefile
142 lines (125 loc) · 3.89 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
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 # %
.PHONY: shfmt shellcheck pipenv
shfmt shellcheck pipenv:
@docker build \
--tag $@ \
--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 coverage-check
@$(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: release
release:
@rm -f .version.properties
git tag -d pre-release 2> /dev/null || echo ok
git checkout master
git fetch --all
git pull origin master
./version-up.sh --patch -r --prefix v --apply
@rm -f .version.properties
# To release a new version:
# git push origin --tag <name of tag>
.PHONY: release-patch
release-patch:
@rm -f .version.properties
git tag -d pre-release 2> /dev/null || echo ok
git checkout master
git fetch --all
git pull origin master
./version-up.sh --patch -r --prefix v --apply
@rm -f .version.properties
#
# To release a new version:
# git push origin --tag <name of tag>
.PHONY: release-minor
release-minor:
@rm -f .version.properties
git tag -d pre-release 2> /dev/null || echo ok
git checkout master
git fetch --all
git pull origin master
./version-up.sh --minor -r --prefix v --apply
@rm -f .version.properties
#
# To release a new version:
# git push origin --tag <name of tag>
.PHONY: release-major
release-major:
@rm -f .version.properties
git tag -d pre-release 2> /dev/null || echo ok
git checkout master
git fetch --all
git pull origin master
./version-up.sh --major -r --prefix v --apply
@rm -f .version.properties
#
# To release a new version:
# git push origin --tag <name of tag>
.PHONY: ready
ready: fmt static-check python-coverage