-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
323 lines (266 loc) · 13.3 KB
/
Makefile
File metadata and controls
323 lines (266 loc) · 13.3 KB
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
export
# ---------------- BEFORE RELEASE ----------------
# 1 - Update Version Number
# 2 - Update RELEASE.md
# 3 - make update_setup
# -------------- Release Process Steps --------------
# 1 - Get Credentials from devops-accounts repo
# 2 - Create Release Branch and push
# 3 - Create Release Tag and push
# 4 - GitHub Release
# 5 - PyPI Release
########################################################
# Variables
########################################################
# MUST BE THE SAME AS API in Mayor and Minor Version Number
# example: API 2.9.0 --> Client 2.9.X
ONDEWO_NLU_VERSION = 6.7.0
ONDEWO_NLU_API_GIT_BRANCH=tags/6.7.0
ONDEWO_PROTO_COMPILER_GIT_BRANCH=tags/5.9.0
PYPI_USERNAME?=ENTER_HERE_YOUR_PYPI_USERNAME
PYPI_PASSWORD?=ENTER_HERE_YOUR_PYPI_PASSWORD
# You need to setup an access token at https://github.com/settings/tokens - permissions are important
GITHUB_GH_TOKEN?=ENTER_YOUR_TOKEN_HERE
CURRENT_RELEASE_NOTES=`cat RELEASE.md \
| sed -n '/Release ONDEWO NLU Python Client ${ONDEWO_NLU_VERSION}/,/\*\*/p'`
GH_REPO="https://github.com/ondewo/ondewo-nlu-client-python"
DEVOPS_ACCOUNT_GIT="ondewo-devops-accounts"
DEVOPS_ACCOUNT_DIR="./${DEVOPS_ACCOUNT_GIT}"
ONDEWO_NLU_API_DIR=ondewo-nlu-api
ONDEWO_PROTO_COMPILER_DIR=ondewo-proto-compiler
ONDEWO_PROTOS_DIR=${ONDEWO_NLU_API_DIR}/ondewo/
GOOGLE_PROTOS_DIR=${ONDEWO_NLU_API_DIR}/google/
OUTPUT_DIR=.
IMAGE_UTILS_NAME=ondewo-nlu-client-utils-python:${ONDEWO_NLU_VERSION}
.DEFAULT_GOAL := help
########################################################
# ONDEWO Standard Make Targets
########################################################
setup_developer_environment_locally: install_precommit_hooks install_dependencies_locally
install_precommit_hooks: ## Installs pre-commit hooks and sets them up for the ondewo-csi-client repo
-pip install pre-commit
-conda -y install pre-commit
pre-commit install
pre-commit install --hook-type commit-msg
precommit_hooks_run_all_files: ## Runs all pre-commit hooks on all files and not just the changed ones
pre-commit run --all-file
install_dependencies_locally: ## Install dependencies locally
pip install -r requirements-dev.txt
pip install -r requirements.txt
flake8: ## Runs flake8
flake8 --config .flake8 .
mypy: ## Run mypy static code checking
@echo "---------------------------------------------"
@echo "START: Run mypy in pre-commit hook ..."
pre-commit run mypy --all-files
@echo "DONE: Run mypy in pre-commit hook."
@echo "---------------------------------------------"
@echo "START: Run mypy directly ..."
mypy --config-file=mypy.ini .
@echo "DONE: Run mypy directly"
@echo "---------------------------------------------"
help: ## Print usage info about help targets
# (first comment after target starting with double hashes ##)
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
makefile_chapters: ## Shows all sections of Makefile
@echo `cat Makefile| grep "########################################################" -A 1 | grep -v "########################################################"`
TEST: ## Prints some important variables
@echo "Release Notes: \n \n$(CURRENT_RELEASE_NOTES)"
@echo "GH Token: \t $(GITHUB_GH_TOKEN)"
@echo "NPM Name: \t $(NPM_USERNAME)"
@echo "NPM Password: \t $(NPM_PASSWORD)"
check_build: ## Checks if all built proto-code is there
@rm -rf build_check.txt
@for proto in `find ondewo-nlu-api/ondewo -iname "*.proto*"`; \
do \
echo $${proto} | cut -d "/" -f 4 | cut -d "." -f 1 >> build_check.txt; \
done
@echo "`sort build_check.txt | uniq`" > build_check.txt
@for file in `cat build_check.txt`;\
do \
find ondewo -iname "*pb*" | grep -q $${file}; \
if test $$? != 0; then echo "No Proto-Code for $${file}" & exit 1;fi \
done
@rm -rf build_check.txt
########################################################
# Repo Specific Make Targets
########################################################
# Build
update_setup: ## Update Version in setup.py
@sed -i "s/version='[0-9]*.[0-9]*.[0-9]*'/version='${ONDEWO_NLU_VERSION}'/g" setup.py
@sed -i "s/version=\"[0-9]*.[0-9]*.[0-9]*\"/version='${ONDEWO_NLU_VERSION}'/g" setup.py
build: clear_package_data init_submodules checkout_defined_submodule_versions build_compiler generate_ondewo_protos generate_services update_setup ## Build source code
push_to_pypi_via_docker: push_to_pypi_via_docker_image ## Release automation for building and pushing to pypi via a docker image
release_to_github_via_docker: build_utils_docker_image release_to_github_via_docker_image ## Release automation for building and releasing on GitHub via a docker image
clean_python_api: ## Clear generated python files
find ./ondewo -name \*pb2.py -type f -exec rm -f {} \;
find ./ondewo -name \*pb2_grpc.py -type f -exec rm -f {} \;
find ./ondewo -name \*.pyi -type f -exec rm -f {} \;
rm -rf google
build_compiler: ## Build proto compiler docker image
make -C ondewo-proto-compiler/python build
generate_services: ## Generate service wrapper files from proto definitions
python3 ondewo/nlu/scripts/generate_services.py \
${ONDEWO_NLU_API_DIR}/ondewo/nlu \
ondewo/nlu/services
-make precommit_hooks_run_all_files
make create_async_services
make precommit_hooks_run_all_files
generate_ondewo_protos: ## Generate python code from proto files
make -f ondewo-proto-compiler/python/Makefile run \
PROTO_DIR=${ONDEWO_PROTOS_DIR} \
EXTRA_PROTO_DIR=${GOOGLE_PROTOS_DIR} \
TARGET_DIR='ondewo' \
OUTPUT_DIR=${OUTPUT_DIR}
-make precommit_hooks_run_all_files
setup_conda_env: ## Checks for CONDA Environment
@echo "\n START SETTING UP CONDA ENV \n"
@conda env list | grep -q ondewo-nlu-client-python || ( echo "\n CONDA ENV FOR REPO DOESNT EXIST \n" \
&& make create_conda_env)
create_conda_env: ##Creates CONDA Environment
conda create -y --name ondewo-nlu-client-python python=3.9
/bin/bash -c 'source `conda info --base`/bin/activate ondewo-nlu-client-python; make setup_developer_environment_locally && echo "\n PRECOMMIT INSTALLED \n"'
create_async_services: ## Create async services for all synchronous services
@find ondewo -type d -name "services" ! -path "*/.*/*" | while read -r dir; do \
for file in "$$dir"/*.py; do \
filename=$$(basename -- "$$file"); \
case "$$filename" in \
"__init__.py"|async_*) continue ;; \
esac; \
cp "$$file" "$$dir/async_$$filename"; \
done; \
for file in "$$dir"/async_*.py; do \
sed -i -E \
-e '/def stub/b' -e 's/^([[:space:]]*)def /\1async def /g' \
-e 's/self\.stub/await self.stub/g' \
-e 's/ServicesInterface/AsyncServicesInterface/g' \
-e 's/services_interface/async_services_interface/g' \
"$$file"; \
sed -i -E \
-e 's/\bIterator\b/AsyncIterator/g' \
-e 's/(response: AsyncIterator\[[^]]+\] = )await (self\.stub)/\1\2/g' \
"$$file"; \
done; \
done
cp ondewo/nlu/client.py ondewo/nlu/async_client.py
sed -i -E \
-e 's/from ondewo\.nlu\.services\.([a-z_]+) import/from ondewo.nlu.services.async_\1 import/g' \
-e 's/from ondewo\.utils\.base_client import BaseClient/from ondewo.utils.async_base_client import AsyncBaseClient/g' \
-e 's/from ondewo\.nlu\.core\.services_container import ServicesContainer/from ondewo.nlu.core.async_services_container import AsyncServicesContainer/g' \
-e 's/\bServicesContainer\b/AsyncServicesContainer/g' \
-e 's/\bBaseClient\b/AsyncBaseClient/g' \
-e 's/class Client\b/class AsyncClient/g' \
ondewo/nlu/async_client.py
cp ondewo/nlu/core/services_container.py ondewo/nlu/core/async_services_container.py
sed -i -E \
-e 's/from ondewo\.nlu\.services\.([a-z_]+) import/from ondewo.nlu.services.async_\1 import/g' \
-e 's/class ServicesContainer\b/class AsyncServicesContainer/g' \
ondewo/nlu/core/async_services_container.py
-make precommit_hooks_run_all_files
########################################################
# Release
release: ## Automate the entire release process
@echo "Start Release"
make build
/bin/bash -c 'source `conda info --base`/bin/activate ondewo-nlu-client-python; make precommit_hooks_run_all_files || echo "PRECOMMIT FOUND SOMETHING"'
git status
make check_build
git add ondewo
git add Makefile
git add RELEASE.md
git add setup.py
git add ${ONDEWO_PROTO_COMPILER_DIR}
git add ${ONDEWO_NLU_API_DIR}
git status
-git commit -m "PREPARING FOR RELEASE ${ONDEWO_NLU_VERSION}"
git push
make create_release_branch
make create_release_tag
make release_to_github_via_docker
make push_to_pypi_via_docker
@echo "Release Finished"
create_release_branch: ## Create Release Branch and push it to origin
git checkout -b "release/${ONDEWO_NLU_VERSION}"
git push -u origin "release/${ONDEWO_NLU_VERSION}"
create_release_tag: ## Create Release Tag and push it to origin
git tag -a ${ONDEWO_NLU_VERSION} -m "release/${ONDEWO_NLU_VERSION}"
git push origin ${ONDEWO_NLU_VERSION}
login_to_gh: ## Login to Github CLI with Access Token
echo $(GITHUB_GH_TOKEN) | gh auth login -p ssh --with-token
build_gh_release: ## Generate Github Release with CLI
gh release create --repo $(GH_REPO) "$(ONDEWO_NLU_VERSION)" -n "$(CURRENT_RELEASE_NOTES)" -t "Release ${ONDEWO_NLU_VERSION}"
########################################################
# Submodules
install: init_submodules ## Installs all packages
pip install -e .
init_submodules: ## Initialize submodules
@echo "START initializing submodules ..."
git submodule update --init --recursive
@echo "DONE initializing submodules"
checkout_defined_submodule_versions: ## Update submodule versions
@echo "START checking out submodules ..."
git -C ${ONDEWO_NLU_API_DIR} fetch --all
git -C ${ONDEWO_NLU_API_DIR} checkout ${ONDEWO_NLU_API_GIT_BRANCH}
git -C ${ONDEWO_PROTO_COMPILER_DIR} fetch --all
git -C ${ONDEWO_PROTO_COMPILER_DIR} checkout ${ONDEWO_PROTO_COMPILER_GIT_BRANCH}
@echo "DONE checking out submodules"
########################################################
# PYPI
build_package: ## Builds PYPI Package
python setup.py sdist bdist_wheel
chmod a+rw dist -R
upload_package: ## Uploads PYPI Package
twine upload --verbose -r pypi dist/* -u${PYPI_USERNAME} -p${PYPI_PASSWORD}
clear_package_data: ## Clears PYPI Package
echo "Waiting 5s so directory for removal is not busy anymore"
sleep 5s
-rm -rf build dist ondewo_nlu_client.egg-info
build_utils_docker_image: ## Build utils docker image
docker build -f Dockerfile.utils -t ${IMAGE_UTILS_NAME} .
push_to_pypi_via_docker_image: ## Push source code to pypi via docker
[ -d $(OUTPUT_DIR) ] || mkdir -p $(OUTPUT_DIR)
docker run --rm \
-v ${shell pwd}/dist:/home/ondewo/dist \
-e PYPI_USERNAME=${PYPI_USERNAME} \
-e PYPI_PASSWORD=${PYPI_PASSWORD} \
${IMAGE_UTILS_NAME} make push_to_pypi
rm -rf dist
push_to_pypi: build_package upload_package clear_package_data ## Builds -> Uploads -> Clears PYPI Package
@echo 'YAY - Pushed to pypi : )'
show_pypi: build_package ## Shows PYPI Package with Dockerimage
tar xvfz dist/ondewo-nlu-client-${ONDEWO_NLU_VERSION}.tar.gz
tree ondewo-nlu-client-${ONDEWO_NLU_VERSION}
cat ondewo-nlu-client-${ONDEWO_NLU_VERSION}/ondewo_nlu_client.egg-info/requires.txt
show_pypi_via_docker_image: build_utils_docker_image ## Push source code to pypi via docker
[ -d $(OUTPUT_DIR) ] || mkdir -p $(OUTPUT_DIR)
docker run --rm \
-v ${shell pwd}/dist:/home/ondewo/dist \
-e PYPI_USERNAME=${PYPI_USERNAME} \
-e PYPI_PASSWORD=${PYPI_PASSWORD} \
${IMAGE_UTILS_NAME} make show_pypi
rm -rf dist
########################################################
# GITHUB
push_to_gh: login_to_gh build_gh_release ## Logs into GitHub CLI and Releases
@echo 'Released to Github'
release_to_github_via_docker_image: ## Release to Github via docker
docker run --rm \
-e GITHUB_GH_TOKEN=${GITHUB_GH_TOKEN} \
${IMAGE_UTILS_NAME} make push_to_gh
########################################################
# DEVOPS-ACCOUNTS
ondewo_release: spc clone_devops_accounts run_release_with_devops ## Release with credentials from devops-accounts repo
@rm -rf ${DEVOPS_ACCOUNT_GIT}
clone_devops_accounts: ## Clones devops-accounts repo
if [ -d $(DEVOPS_ACCOUNT_GIT) ]; then rm -Rf $(DEVOPS_ACCOUNT_GIT); fi
git clone git@bitbucket.org:ondewo/${DEVOPS_ACCOUNT_GIT}.git
run_release_with_devops: ## Gets Credentials from devops-repo and run release command with them
$(eval info:= $(shell cat ${DEVOPS_ACCOUNT_DIR}/account_github.env | grep GITHUB_GH & cat ${DEVOPS_ACCOUNT_DIR}/account_pypi.env | grep PYPI_USERNAME & cat ${DEVOPS_ACCOUNT_DIR}/account_pypi.env | grep PYPI_PASSWORD))
@(echo ${CONDA_PREFIX} | grep -q nlu-client-python || make setup_conda_env $(info)) && make release $(info)
spc: ## Checks if the Release Branch, Tag and Pypi version already exist
$(eval filtered_branches:= $(shell git branch --all | grep "release/${ONDEWO_NLU_VERSION}"))
$(eval filtered_tags:= $(shell git tag --list | grep "${ONDEWO_NLU_VERSION}"))
$(eval setuppy_version:= $(shell cat setup.py | grep "version"))
@if test "$(filtered_branches)" != ""; then echo "-- Test 1: Branch exists!!" & exit 1; else echo "-- Test 1: Branch is fine";fi
@if test "$(filtered_tags)" != ""; then echo "-- Test 2: Tag exists!!" & exit 1; else echo "-- Test 2: Tag is fine";fi
# @if test "$(setuppy_version)" != "version='${ONDEWO_NLU_VERSION}',"; then echo "-- Test 3: Setup.py not updated!!" & exit 1; else echo "-- Test 3: Setup.py is fine";fi