-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
90 lines (71 loc) · 2.65 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
# Configuration
ALL_FILES := $(sort $(shell find -type f -not -wholename "./.*" -not -name Makefile -not -wholename "*/__pycache__/*"))
ALL_DOCKER_FILES := $(shell ls dockerfiles)
SERVICE := $(notdir $(CURDIR))
SERVICE_LC := $(shell echo $(SERVICE) | tr '[[:upper:]]' '[[:lower:]]')
SERVICE_ID_FULL := $(shell sha256sum $(ALL_FILES) | sha256sum | cut -d' ' -f1)
SERVICE_ID_SHORT := $(shell echo $(SERVICE_ID_FULL) | head -c 6)
# Docker Tags
DOCKER_TEST_TAG = $(SERVICE_LC)-$(SERVICE_ID_SHORT).test
# Preparation of dependencies
CACHEBASE ?= ~/.cache/$(SERVICE).make-cache
CACHEDIR = $(CACHEBASE)/$(SERVICE_ID_FULL)
# run-arch-tests, run-python3.8-tests, ...
DOCKER_TESTS := $(addsuffix -tests, $(addprefix run-,$(ALL_DOCKER_FILES)))
.SECONDARY: # Do not remove intermediate files. We need them for caching!
.PHONY: all
all: check-format check-linters run-tests
.PHONY: apply-format
apply-format: $(CACHEDIR)/apply-format
.PHONY: check-format
check-format: | $(CACHEDIR)/check-format
.PHONY: check-linters
check-linters: | $(CACHEDIR)/check-linters
.PHONY: run-tests
run-tests: run-docker-tests | run-undockered-tests
.PHONY: run-docker-tests
run-docker-tests: | $(DOCKER_TESTS)
.PHONY: run-undockered-tests
run-undockered-tests: | $(CACHEDIR)/run-undockered-tests
.PHONY: get-service-id
get-service-id:
@echo $(SERVICE_ID_FULL)
run-%-tests: | $(CACHEDIR)/run-%-tests
# This is a pseudo phony target. Unfortunately, Make does not support
# phony pattern rules.
@touch $@
$(CACHEDIR):
mkdir -p $@
$(CACHEDIR)/run-undockered-tests: | $(CACHEDIR)
poetry run pytest -n $$(nproc)
touch $@
$(CACHEDIR)/run-%-tests: | $(CACHEDIR)/%-test-image
platform=$(subst -test-image,,$(notdir $|)) ; \
docker run --rm --privileged -v "$(CURDIR)/tests/:/project/tests" -t $(DOCKER_TEST_TAG).$$platform
touch $@
$(CACHEDIR)/%-test-image: | $(CACHEDIR)
platform=$(subst -test-image,,$(notdir $@)) ; \
DOCKER_BUILDKIT=1 docker build . -t $(DOCKER_TEST_TAG).$$platform -f dockerfiles/$$platform
touch $@
# STATIC ANALYSIS OF SOURCE CODE
$(CACHEDIR)/check-linters: | $(CACHEDIR)/check-ruff $(CACHEDIR)/check-mypy
touch $@
$(CACHEDIR)/check-ruff: | $(CACHEDIR)/check-format
poetry run ruff check .
touch $@
$(CACHEDIR)/check-mypy: | $(CACHEDIR)
poetry run mypy .
touch $@
# CHECKING FORMAT AND REFORMATTING
$(CACHEDIR)/apply-format: $(ALL_FILES) | $(CACHEDIR)
poetry run ruff check --select I --fix .
poetry run black .
touch $@
$(CACHEDIR)/check-format: | $(CACHEDIR)/check-black $(CACHEDIR)/check-import-ordering
touch $@
$(CACHEDIR)/check-black: | $(CACHEDIR)
poetry run black --check .
touch $@
$(CACHEDIR)/check-import-ordering: | $(CACHEDIR)
poetry run ruff check --select I .
touch $@