-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
171 lines (146 loc) · 6.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
default: help
POETRY_DEV=external/shell_scripts_lib/python/poetry_dev.sh
POETRY_PIP_RELEASER=external/shell_scripts_lib/python/poetry_pip_releaser.sh
PLUGINS_ROOT_FOLDER=plugins
# Generate SSH key for GitHub action of a repository with required access to another repository:
# 1. Go to user 'Settings' -> 'Developer Settings' -> 'Personal Access Token':
# - Select Token (Classic)
# - Generate new token on the classic mode with full 'repo' scope
# - Copy the GitHub PAT secret
# 2. Add the private key as a secret in the repository running the workflow:
# - Go to the repository’s settings page on GitHub.
# - Click on “Secrets and variables” in the left sidebar and then "Actions".
# - Click on “New repository secret”.
# - Enter a name for the secret, such as MY_REPO_ACCESS_TOKEN, and paste the contents of the private key file into the “Value” field.
# - Click on “Add secret”.
# 3. On the GitHub workflow use is as:
# - token: ${{ secrets.MY_REPO_ACCESS_TOKEN }}
.PHONY: prod-mode
prod-mode: ## Enable production mode for packaging and distribution
@poetry self add poetry-multiproject-plugin
@./scripts/switch_mode.py prod
@poetry lock
.PHONY: dev-mode
dev-mode: ## Enable local development
@pip3 install tomlkit --disable-pip-version-check --no-python-version-warning
@./scripts/switch_mode.py dev
@poetry lock
.PHONY: run
run: ## Run provisioner CLI from sources (Usage: make run 'config view')
@poetry run provisioner $(filter-out $@,$(MAKECMDGOALS))
.PHONY: deps-install
deps-install: ## Update and install pyproject.toml dependencies on all virtual environments
@poetry lock
@poetry install --with dev --sync -v
.PHONY: typecheck
typecheck: ## Check for Python static type errors
@poetry run mypy $(PWD)/*/**/*.py
.PHONY: fmtcheck
fmtcheck: ## Validate Python code format and sort imports
@poetry run black . --check
@poetry run ruff check . --show-fixes
.PHONY: fmt
fmt: ## Format Python code using Black style and sort imports
@poetry run black .
@poetry run ruff check . --show-fixes --fix
.PHONY: test
test: ## Run tests suite on runtime and all plugins
@poetry run coverage run -m pytest; \
if [ $$? -ne 0 ]; then \
exit 1; \
fi;
.PHONY: test-coverage-html
test-coverage-html: ## Run tests suite on runtime and all plugins
@poetry run coverage run -m pytest; \
if [ $$? -ne 0 ]; then \
exit 1; \
fi;
@echo "\n\n========= COVERAGE FULL REPORT ======================\n\n"
@poetry run coverage report
@poetry run coverage html
-@echo "\n====\n\nFull coverage report available on the following link:\n\n • $(PWD)/htmlcov/index.html\n"
# This is the command used by GitHub Actions to run the tests
# It must fail the GitHub action step if any of the tests fail
# This is the reason we're performing an exist code check since it
# is a makefile that runs other makefiles within a for loop
.PHONY: test-coverage-xml
test-coverage-xml: ## Run tests suite on runtime and all plugins
@poetry run coverage run -m pytest; \
if [ $$? -ne 0 ]; then \
exit 1; \
fi;
@echo "\n\n========= COVERAGE FULL REPORT ======================\n\n"
@poetry run coverage report
@poetry run coverage xml
-@echo "\n====\n\nFull coverage report available on the following link:\n\n • $(PWD)/coverage.xml\n"
.PHONY: pip-install-runtime
pip-install-runtime: ## [LOCAL] Install provisioner runtime to local pip
@echo "\n========= PROJECT: provisioner ==============\n"
@cd provisioner; poetry build-project -f sdist; cd ..
@pip3 install provisioner/dist/provisioner_*.tar.gz
# @cd provisioner; poetry build-project -f wheel; cd ..
# @pip3 install provisioner/dist/provisioner_*.whl
# @cd provisioner; poetry build-project -f sdist; cd ..
# @pip3 install provisioner/dist/provisioner_*.tar.gz
.PHONY: pip-install-plugin
pip-install-plugin: ## [LOCAL] Install any plugin to local pip (make pip-install-plugin example)
@if [ -z "$(word 2, $(MAKECMDGOALS))" ]; then \
echo "Error: plugin name is required. Usage: make pip-install-plugin <plugin_name>"; \
exit 1; \
fi
@PLUGIN=$(word 2, $(MAKECMDGOALS)); \
echo "\n========= PLUGIN: $$PLUGIN ==============\n"; \
cd ${PLUGINS_ROOT_FOLDER}/provisioner_$${PLUGIN}_plugin; poetry build-project -f sdist; cd ../..; \
pip3 install ${PLUGINS_ROOT_FOLDER}/provisioner_$${PLUGIN}_plugin/dist/provisioner_*.tar.gz;
# cd ${PLUGINS_ROOT_FOLDER}/provisioner_$${PLUGIN}_plugin; poetry build-project -f wheel; cd ../..; \
# pip3 install ${PLUGINS_ROOT_FOLDER}/provisioner_$${PLUGIN}_plugin/dist/provisioner_*.whl;
.PHONY: pip-uninstall-runtime
pip-uninstall-runtime: ## [LOCAL] Uninstall provisioner from local pip
@echo "\n========= PROJECT: provisioner ==============\n"
@cd provisioner; pip3 uninstall -y provisioner_shared provisioner_runtime; cd ..
.PHONY: pip-uninstall-plugin
pip-uninstall-plugin: ## [LOCAL] Uninstall any plugins source distributions from local pip (make pip-uninstall-plugin example)
@if [ -z "$(word 2, $(MAKECMDGOALS))" ]; then \
echo "Error: plugin name is required. Usage: make pip-uninstall-plugin <plugin_name>"; \
exit 1; \
fi
@PLUGIN=$(word 2, $(MAKECMDGOALS)); \
echo "\n========= PLUGIN: $$PLUGIN ==============\n"; \
pip3 uninstall -y provisioner_$${PLUGIN}_plugin;
.PHONY: clear-project
clear-project: ## Clear Poetry virtual environments and clear Python cache
@find . -type d -name "__pycache__" -exec rm -rf {} +
@poetry env remove --all
# http://localhost:9001/provisioner/
.PHONY: docs-site
docs-site: ## Run a local documentation site (required: npm, hugo)
@cd docs-site; npm run docs-serve; cd-
# http://192.168.x.xx:9001/
.PHONY: docs-site-lan
docs-site-lan: ## Run a local documentation site with LAN available (required: npm, hugo)
@cd docs-site; npm run docs-serve-lan; cd-
#
# To add a submodule for the first time to an existing repository:
#
# git submodule add git@github.com:ZachiNachshon/provisioner-plugins.git plugins
#
.PHONY: plugins-init
plugins-init: ## Initialize Provisioner Plugins git-submodule (only on fresh clone)
@cd plugins; \
git submodule init; \
git submodule update; \
.PHONY: plugins-status
plugins-status: ## Show plugins submodule status (commit-hash)
@git submodule status plugins
.PHONY: plugins-fetch
plugins-fetch: ## Prompt for Provisioner Plugins commit-hash to update the sub-module
@read -p "Enter Provisioner Plugins git repo commit hash (dont forget to git push afterwards): " arg; \
cd plugins; \
git fetch; \
git checkout $$arg; \
cd ..; \
git add plugins; \
git commit -m "Update Provisioner Plugins to $$arg"; \
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'