forked from python-gitlab/python-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
166 lines (142 loc) · 5.34 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
SHELL := /bin/bash
HEAD_SHA := $(shell git rev-parse --short HEAD)
BRANCH := $(shell git branch | grep \\* | cut -d ' ' -f2)
TEST_IMAGE_NAME := linpy-gitlab-test
# COLORS
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
TARGET_MAX_CHAR_NUM=40
## prints help dialog
help:
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
CODE_COVERAGE_MIN=30
## install dev & prod requirements
install-requirements:
pip install ".[dev]"
## executes bandit security chcker
bandit:
./run_bandit.sh
## executes flake8
flake8:
flake8 linpy_webhooks
venv:
test -d .venv || ( \
python3 -m venv .venv; \
source .venv/bin/activate; \
)
## builds linpy test image to execute tests in. image tag is the current head sha
build-test-image:
docker build \
--build-arg ARTIFACTORY_USER=${ARTIFACTORY_USER} \
--build-arg ARTIFACTORY_PASSWORD=${ARTIFACTORY_PASSWORD} \
. -t linearb/$(TEST_IMAGE_NAME):$(HEAD_SHA) -f ./test.Dockerfile
## list all linpy test images
list-test-images:
docker images | grep linpy-test
## deletes linpy test image with tag which equals current head sha
delete-test-image:
docker rmi linearb/$(TEST_IMAGE_NAME):$(HEAD_SHA)
## executes test in local env
test:
pytest -s --cov=linpy_webhooks --cov-report term --cov-fail-under=$(CODE_COVERAGE_MIN) tests
## executes tests inside test container
test-in-container: build-test-image
docker run \
-e CACHE_REDIS_HOST=localhost \
-e CACHE_REDIS_PORT=6379 \
-e CACHE_REDIS_DB=1 \
-e AWS_DEFAULT_REGION=us-west-2 \
-e AWS_S3_BUCKET=data-lake-env-x \
-e INFERENCE_ESTIMATED_REVIEW_URL='mock-url-for-inference-model.com' \
--network=host \
--name=linpy_webhooks_tests \
--rm \
linearb/$(TEST_IMAGE_NAME):$(HEAD_SHA) \
pytest -s -v --cov=linpy_webhooks --cov-report term --cov-fail-under=$(CODE_COVERAGE_MIN) tests
test-cov-in-container: build-test-image
docker run \
-e CACHE_REDIS_HOST=localhost \
-e CACHE_REDIS_PORT=6379 \
-e CACHE_REDIS_DB=1 \
-e AWS_DEFAULT_REGION=us-west-2 \
-e AWS_S3_BUCKET=data-lake-env-x \
--network=host \
--name=linpy_webhooks_tests \
--rm \
linearb/$(TEST_IMAGE_NAME):$(HEAD_SHA) \
pytest -rx --cov=linpy_webhooks --cov-report term --cov-fail-under=$(CODE_COVERAGE_MIN) tests
## deletes tests container
delete-tests-container:
docker rm linpy_webhooks_tests
## executes pipdeptree inside test container. see https://pypi.org/project/pipdeptree/
print-dependency-tree: build-test-image
docker run \
--name=linpy_webhooks_dependencies \
linearb/$(TEST_IMAGE_NAME):$(HEAD_SHA) \
/bin/bash -c "pip install pipdeptree; pipdeptree"
## delete linpy_webhooks_dependencies container
delete-dependencies-container:
docker rm linpy_webhooks_dependencies
## prints current package version
current-version:
@pip install bump2version
bump2version --allow-dirty --dry-run --list patch | grep current_version
## deploys dev (RC) version. required arg: ver=package version (pattern: {major}.{minor}.{patch}-{release}{build} .example: 0.20.14-rc1). commit and tag will not be created
deploy-rc-version:
@test $(ver)
@if [[ $(ver) =~ ^[0-9]+.[0-9]+.[0-9]+-rc[0-9]+$$ ]]; \
then echo '$(ver) is a valid rc pattern'; \
else echo '$(ver) is not a valid rc pattern. example: 0.20.14-rc1'; exit 1; \
fi
@pip install bump2version
@echo "*** bumping to version:$(ver) ***"
bumpversion build --allow-dirty --no-tag --no-commit --new-version $(ver)
@echo "*** deploying linpy-gitlab with version:$(ver) ***"
rm -Rf dist
pip install --upgrade build
python3 -m build
pip install --upgrade twine
twine upload -r local dist/* --config-file ~/.pypirc
@echo "*** revering changed files ***"
git checkout pyproject.toml .bumpversion.cfg
## bump package version. required arg: part. valid values: 'patch', 'minor', 'major'. pushes new commit and tag. see https://pypi.org/project/bumpversion/
bump-release-version:
@test $(part)
if [[ $(BRANCH) != "main" ]]; then echo 'not on develop branch!. aborting operation'; exit 1; fi
@pip install bump2version
git pull
bumpversion $(part) --tag-name '{new_version}'
git push && git push --tags
## deploys to artifactory.
deploy-release-version:
# deploys to artifactory. VERSION IS NOT BUMPED
# execute 'make bump-version' in order to bump version
# this will override existing tag package
@echo "*** deploying release version of linpy-gitlab ***"
rm -Rf dist
pip install --upgrade build
python3 -m build
pip install --upgrade twine
twine upload -r local dist/* --config-file ~/.pypirc
## bumps and deploys release package. required arg: part (see bump-release-version target)
bump-and-deploy-release-version: bump-release-version deploy-release-version
bump-and-deploy-release-package: bump-release-version deploy-release-version
## prints the last tag
get-last-tag:
git fetch --all --tags
git tag --sort=-v:refname | head -n 1