-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
68 lines (57 loc) · 2.09 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
.PHONY: up clean sync generate test bump publish
SPEC_REMOTE = https://raw.githubusercontent.com/zamzar/zamzar-spec/main/openapi/spec.yaml
SPEC = spec.yaml
GENERATOR_CMD = docker compose exec codegen \
java -jar /opt/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar
GENERATE_ARGS = generate -i $(SPEC) -g python -c openapi-generator-config.yaml
EXEC_CMD = docker compose exec python
# Set sed -i command based on the detected OS
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
# for macOS
SED_INPLACE := sed -i ''
else
# for Linux
SED_INPLACE := sed -i
endif
# Note that the OpenAPI generator currently produces code that can fail the assignment mypy check in some cases;
# so we add inline comments to ignore these errors
SUPPRESS_MYPY_CMD = $(SED_INPLACE) -E 's/(for _item in self\.[^:]+:)/\1 \# type: ignore[assignment]/g' zamzar_sdk/models/*.py
up:
@docker compose up -d
clean:
@while read -r generated; do rm -f "$$generated" || true; done < .openapi-generator/FILES
@rm -rf dist
sync:
@curl -sSL $(SPEC_REMOTE) > $(SPEC)
generate: up
@$(eval CURRENT_VERSION=$(shell $(EXEC_CMD) python setup.py --version))
@$(GENERATOR_CMD) $(GENERATE_ARGS) --additional-properties=packageVersion=$(CURRENT_VERSION)
@$(SUPPRESS_MYPY_CMD)
test: sync generate
@$(EXEC_CMD) mypy
@$(EXEC_CMD) pytest -rP
build: up
@$(EXEC_CMD) python -m build
bump: sync up
ifndef VERSION
$(error VERSION is not set)
endif
@$(eval CURRENT_VERSION=$(shell $(EXEC_CMD) python setup.py --version))
@$(EXEC_CMD) sed -i "s/$(CURRENT_VERSION)/$(VERSION)/g" README.md
@$(EXEC_CMD) sed -i "s/$(CURRENT_VERSION)/$(VERSION)/g" setup.py
@$(EXEC_CMD) sed -i "s/$(CURRENT_VERSION)/$(VERSION)/g" zamzar_sdk/__init__.py
@$(GENERATOR_CMD) $(GENERATE_ARGS) --additional-properties=packageVersion=$(VERSION)
@$(SUPPRESS_MYPY_CMD)
publish: build
ifndef TWINE_USERNAME
$(error TWINE_USERNAME is not set)
endif
ifndef TWINE_PASSWORD
$(error TWINE_PASSWORD is not set)
endif
@docker compose exec \
-e TWINE_USERNAME=$(TWINE_USERNAME) \
-e TWINE_PASSWORD=$(TWINE_PASSWORD) \
python \
twine upload dist/*