-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
145 lines (127 loc) · 5.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
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
SHELL := /bin/bash
PYTHON = python3
PIP = $(PYTHON) -m pip
ifeq ($(OS),Windows_NT)
ACTIVATE_VENV = venv\Scripts\activate
else
ACTIVATE_VENV = source venv/bin/activate
endif
ifneq ("$(wildcard .env)","")
include .env
endif
.PHONY: analyze init pre-commit requirements lint clean test build force-release publish-test publish-prod help
# Default target executed when no arguments are given to make.
all: help
analyze:
cloc . --exclude-ext=svg,json,zip --vcs=git
# -------------------------------------------------------------------------
# Initialize. create virtual environment and install requirements
# -------------------------------------------------------------------------
init:
make clean && \
npm install && \
python3.11 -m venv venv && \
$(ACTIVATE_VENV) && \
pip install --upgrade pip && \
make requirements
# -------------------------------------------------------------------------
# Install and run pre-commit hooks
# -------------------------------------------------------------------------
pre-commit:
pre-commit install
pre-commit run --all-files
# -------------------------------------------------------------------------
# Install requirements: Python, npm and pre-commit
# -------------------------------------------------------------------------
requirements:
rm -rf .tox
$(PIP) install --upgrade pip wheel
$(PIP) install -r requirements/local.txt && \
npm install && \
make pre-commit
pre-commit autoupdate
# -------------------------------------------------------------------------
# Run black and pre-commit hooks.
# includes prettier, isort, flake8, pylint, etc.
# -------------------------------------------------------------------------
lint:
pre-commit run --all-files && \
black .
# -------------------------------------------------------------------------
# Destroy all build artifacts and Python temporary files
# -------------------------------------------------------------------------
clean:
rm -rf venv .pytest_cache __pycache__ .pytest_cache node_modules && \
rm -rf build dist secure_logger.egg-info
# -------------------------------------------------------------------------
# Run Python unit tests
# -------------------------------------------------------------------------
test:
python -m unittest discover -s secure_logger/tests/ && \
python -m setup_test
# -------------------------------------------------------------------------
# Build the project
# -------------------------------------------------------------------------
build:
@echo "-------------------------------------------------------------------------"
@echo " I. Unit tests"
@echo "-------------------------------------------------------------------------"
make test
@echo "-------------------------------------------------------------------------"
@echo " II. Check version"
@echo "-------------------------------------------------------------------------"
npx semantic-release --doctor --dry-run
@echo "-------------------------------------------------------------------------"
@echo " III. Initializing the project,"
@echo " Linting and running pre-commit hooks"
@echo "-------------------------------------------------------------------------"
make init
. venv/bin/activate
$(PIP) install --upgrade setuptools wheel twine
$(PIP) install --upgrade build
@echo "-------------------------------------------------------------------------"
@echo " IV. Building the project"
@echo "-------------------------------------------------------------------------"
$(PYTHON) -m build --sdist ./
$(PYTHON) -m build --wheel ./
@echo "-------------------------------------------------------------------------"
@echo " V. Verifying the build"
@echo "-------------------------------------------------------------------------"
twine check dist/*
# -------------------------------------------------------------------------
# Force a new semantic release to be created in GitHub
# -------------------------------------------------------------------------
force-release:
git commit -m "fix: force a new release" --allow-empty && git push
# -------------------------------------------------------------------------
# Publish to PyPi Test
# https://test.pypi.org/project/secure-logger/
# -------------------------------------------------------------------------
publish-test:
git rev-parse --abbrev-ref HEAD | grep '^main$$' || (echo 'Not on main branch, aborting' && exit 1)
make build
twine upload --verbose --skip-existing --repository testpypi dist/*
# -------------------------------------------------------------------------
# Publish to PyPi
# https://pypi.org/project/secure-logger/
# -------------------------------------------------------------------------
publish-prod:
git rev-parse --abbrev-ref HEAD | grep '^main$$' || (echo 'Not on main branch, aborting' && exit 1)
make build
twine upload --verbose --skip-existing dist/*
# -------------------------------------------------------------------------
# Generate help menu
# -------------------------------------------------------------------------
help:
@echo '===================================================================='
@echo 'init - build virtual environment and install requirements'
@echo 'analyze - runs cloc report'
@echo 'pre-commit - install and configure pre-commit hooks'
@echo 'requirements - install Python, npm and pre-commit requirements'
@echo 'lint - run black and pre-commit hooks'
@echo 'clean - destroy all build artifacts'
@echo 'test - run Python unit tests'
@echo 'build - build the project'
@echo 'force-release - force a new release to be created in GitHub'
@echo 'publish-test - test deployment to PyPi'
@echo 'publish-prod - production deployment to PyPi'