-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
139 lines (116 loc) · 4.42 KB
/
Copy pathMakefile
File metadata and controls
139 lines (116 loc) · 4.42 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
### Defensive settings for make:
# https://tech.davis-hansson.com/p/make/
SHELL:=bash
.ONESHELL:
.SHELLFLAGS:=-xeu -o pipefail -O inherit_errexit -c
.SILENT:
.DELETE_ON_ERROR:
MAKEFLAGS+=--warn-undefined-variables
MAKEFLAGS+=--no-builtin-rules
# We like colors
# From: https://coderwall.com/p/izxssa/colored-makefile-for-golang-projects
RED=`tput setaf 1`
GREEN=`tput setaf 2`
RESET=`tput sgr0`
YELLOW=`tput setaf 3`
# Python checks
UV?=uv
# installed?
ifeq (, $(shell which $(UV) ))
$(error "UV=$(UV) not found in $(PATH)")
endif
PROJECT_FOLDER=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
VENV_FOLDER=$(PROJECT_FOLDER)/.venv
BIN_FOLDER=$(VENV_FOLDER)/bin
IMAGE_NAME?=ghcr.io/simplesconsultoria/zodb-backup
IMAGE_TAG?=dev
# Build metadata baked into the image as OCI labels. VCS_REF and BUILD_DATE fall
# back to "unknown" rather than to a wrong value, e.g. in a repository with no
# commits yet or an export without git history.
VERSION=$(shell sed -n 's/^__version__ = "\(.*\)"/\1/p' src/zodb_backup/__init__.py)
VCS_REF=$(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
BUILD_DATE=$(shell date -u +%Y-%m-%dT%H:%M:%SZ)
all: build
# Add the following 'help' target to your Makefile
# And add help text after each target name starting with '\#\#'
.PHONY: help
help: ## This help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
$(VENV_FOLDER): ## Install dependencies
@echo "$(GREEN)==> Install environment$(RESET)"
@uv sync
.PHONY: install
install: $(VENV_FOLDER) ## Install the project
.PHONY: clean
clean: ## Clean environment
@echo "$(RED)==> Cleaning environment and build$(RESET)"
rm -rf $(VENV_FOLDER) .python-version .ruff_cache .pytest_cache .mypy_cache .coverage htmlcov dist build uv.lock
############################################
# QA
############################################
.PHONY: lint
lint: $(VENV_FOLDER) ## Check code base according to our standards
@echo "$(GREEN)==> Lint codebase$(RESET)"
@uvx ruff@latest check --config $(PROJECT_FOLDER)/pyproject.toml
@uvx ruff@latest format --check --config $(PROJECT_FOLDER)/pyproject.toml
@uvx pyroma@latest -d .
@uvx check-python-versions@latest .
@uv run mypy
.PHONY: format
format: $(VENV_FOLDER) ## Fix code base according to our standards
@echo "$(GREEN)==> Format codebase$(RESET)"
@uvx ruff@latest check --select I --fix --config $(PROJECT_FOLDER)/pyproject.toml
@uvx ruff@latest format --config $(PROJECT_FOLDER)/pyproject.toml
.PHONY: check
check: format lint ## Check and fix code base according to Plone standards
############################################
# Tests
############################################
.PHONY: test
test: $(VENV_FOLDER) ## Test the code with pytest
@echo "🚀 Testing code: Running pytest"
@uv run pytest -m "not integration"
.PHONY: test-integration
test-integration: $(VENV_FOLDER) docker-build ## Run the opt-in tests that need a docker compose stack
@echo "🚀 Testing code: Running integration tests"
@uv run pytest -m integration
.PHONY: test-coverage
test-coverage: $(VENV_FOLDER) ## Test the code with pytest and report coverage
@echo "🚀 Testing code: Running pytest"
@uv run pytest -m "not integration" --cov=zodb_backup --cov-report term-missing
############################################
# Container image
############################################
.PHONY: docker-build
docker-build: ## Build the container image
@echo "$(GREEN)==> Build container image $(IMAGE_NAME):$(IMAGE_TAG) ($(VERSION))$(RESET)"
@docker build \
--build-arg VERSION=$(VERSION) \
--build-arg VCS_REF=$(VCS_REF) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
-t $(IMAGE_NAME):$(IMAGE_TAG) .
.PHONY: stack-down
stack-down: ## Tear down the integration stack and its volumes
@echo "$(RED)==> Tearing down the test stack$(RESET)"
@docker compose -f docker-compose.test.yml down -v
############################################
# Release
############################################
.PHONY: build
build: $(VENV_FOLDER) ## Build the sdist and wheel
@echo "🚀 Build package"
@rm -Rf dist
@uv build
.PHONY: changelog
changelog: $(VENV_FOLDER) ## Display a draft of the changelog
@echo "🚀 Display the draft for the changelog"
@uv run towncrier --draft
.PHONY: release
release: $(VENV_FOLDER) ## Release the package to pypi.org
@echo "🚀 Release package"
@uv run prerelease
@uv run release
@rm -Rf dist
@uv build
@uv publish
@uv run postrelease