-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathMakefile
More file actions
176 lines (148 loc) · 6.84 KB
/
Copy pathMakefile
File metadata and controls
176 lines (148 loc) · 6.84 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
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
172
173
174
175
176
SHELL := /bin/sh
CARGO = cargo
# For unknown reasons, poetry on CI will sometimes "forget" what it's current path is, which
# can confuse relative path lookups.
# Let's be very explicit about it for now.
TESTS_DIR := $(shell pwd)/tests
TEST_RESULTS_DIR ?= workspace/test-results
# In order to be consumed by the ETE Test Metric Pipeline, files need to follow a strict naming convention:
# {job_number}__{utc_epoch_datetime}__{repository}__{workflow}__{test_suite}__results{-index}.xml
WORKFLOW := build-test-deploy
EPOCH_TIME := $(shell date +"%s")
TEST_FILE_PREFIX := $(if $(CIRCLECI),$(CIRCLE_BUILD_NUM)__$(EPOCH_TIME)__$(CIRCLE_PROJECT_REPONAME)__$(WORKFLOW)__)
UNIT_JUNIT_XML := $(TEST_RESULTS_DIR)/$(TEST_FILE_PREFIX)unit__results.xml
UNIT_COVERAGE_JSON := $(TEST_RESULTS_DIR)/$(TEST_FILE_PREFIX)unit__coverage.json
INTEGRATION_JUNIT_XML := $(TEST_RESULTS_DIR)/$(TEST_FILE_PREFIX)integration__results.xml
INTEGRATION_JUNIT_XML_LEGACY := $(TEST_RESULTS_DIR)/$(TEST_FILE_PREFIX)integration__legacy-results.xml
# NOTE: Do not be clever.
# The integration tests (and a few others) use pytest markers to control
# the tests that are being run. These markers are set and defined within
# the `./pyproject.toml`. That is the single source of truth.
PYTEST_ARGS := ${PYTEST_ARGS}
INTEGRATION_TEST_DIR := $(TESTS_DIR)/integration
INTEGRATION_TEST_FILE := $(INTEGRATION_TEST_DIR)/test_integration_all_rust.py
NOTIFICATION_TEST_DIR := $(TESTS_DIR)/notification
LOAD_TEST_DIR := $(TESTS_DIR)/load
POETRY := poetry --directory $(TESTS_DIR)
DOCKER_COMPOSE := docker compose
PYPROJECT_TOML := $(TESTS_DIR)/pyproject.toml
POETRY_LOCK := $(TESTS_DIR)/poetry.lock
FLAKE8_CONFIG := $(TESTS_DIR)/.flake8
LOCUST_HOST := "wss://autoconnect.stage.mozaws.net"
INSTALL_STAMP := .install.stamp
.PHONY: docker-dev-build
docker-dev-build:
echo $(CMAKE_POLICY_VERSION_MINIMUM)
docker build -f Dockerfile-dev -t autopush-dev .
.PHONY: docker-init
docker-init:
sudo apt update
sudo apt-get install build-essential libffi-dev libssl-dev pypy3-dev python3-virtualenv python3-poetry python-is-python3 git glibc-source cmake clang --assume-yes
cargo install cargo-audit
rustup update 1.96.0 ## RUST_VER
.PHONY: install
install: $(INSTALL_STAMP) ## Install dependencies with poetry
$(INSTALL_STAMP): $(PYPROJECT_TOML) $(POETRY_LOCK)
@if [ -z $(POETRY) ]; then echo "Poetry could not be found. See https://python-poetry.org/docs/"; exit 2; fi
$(POETRY) install
touch $(INSTALL_STAMP)
install_poetry:
curl -sSL https://install.python-poetry.org | python3 - --version 2.0.0
upgrade:
$(CARGO) install cargo-edit ||
echo "\n$(CARGO) install cargo-edit failed, continuing.."
$(CARGO) upgrade
$(CARGO) update
.ONESHELL:
unit-test: ## Run the Rust test suite (requires a running Bigtable emulator) and emit coverage
cargo llvm-cov --summary-only --json --output-path $(UNIT_COVERAGE_JSON) \
nextest --features=emulator --features=bigtable --jobs=2 --profile=ci; exit_code=$$?
mv target/nextest/ci/junit.xml $(UNIT_JUNIT_XML)
exit $$exit_code
build-integration-test:
$(DOCKER_COMPOSE) -f $(INTEGRATION_TEST_DIR)/docker-compose.yml build
.ONESHELL:
integration-test:
$(DOCKER_COMPOSE) -f $(INTEGRATION_TEST_DIR)/docker-compose.yml run -it --name integration-tests tests; exit_code=$$?
docker cp integration-tests:/code/integration__results.xml $(INTEGRATION_JUNIT_XML)
exit $$exit_code
integration-test-clean:
$(DOCKER_COMPOSE) -f $(INTEGRATION_TEST_DIR)/docker-compose.yml down
docker rm integration-tests
integration-test-legacy: ## pytest markers are stored in `tests/pytest.ini`
$(POETRY) -V
$(POETRY) install --without dev,load,notification --no-root
$(POETRY) run pytest $(INTEGRATION_TEST_FILE) \
--junit-xml=$(INTEGRATION_JUNIT_XML_LEGACY) \
-v $(PYTEST_ARGS)
integration-test-local: ## pytest markers are stored in `tests/pytest.ini`
$(POETRY) -V
$(POETRY) install --without dev,load,notification --no-root
$(POETRY) run pytest $(INTEGRATION_TEST_FILE) \
--junit-xml=$(INTEGRATION_JUNIT_XML) \
-v $(PYTEST_ARGS)
notification-test:
$(DOCKER_COMPOSE) -f $(NOTIFICATION_TEST_DIR)/docker-compose.yml build
$(DOCKER_COMPOSE) -f $(NOTIFICATION_TEST_DIR)/docker-compose.yml up -d server
$(DOCKER_COMPOSE) -f $(NOTIFICATION_TEST_DIR)/docker-compose.yml run -e NOTIFICATION_TEST_ENV=$(NOTIFICATION_TEST_ENV) --remove-orphans -it --name notification-tests tests
docker cp notification-tests:/code/notification-tests.xml $(NOTIFICATION_TEST_DIR)
notification-test-clean:
docker rm notification-tests
.PHONY: build-profile
build-profile: ## Run the profiler with the `profile` profile. See Cargo.toml for details.
# `prefix_build_flags.py` is a hack to work around the fact that we need to set some platform specific env vars for the build,
# but doing so in a Makefile is a nightmare. This way, we can just call this script with the same args we would
# normally call cargo with, and it will add the necessary env vars before running the command.
python3 scripts/prefix_build_flags.py RUSTFLAGS="-C force-frame-pointers=yes" cargo build --profile profile
.PHONY: format
format: $(INSTALL_STAMP) ## Sort imports and reformats code
$(POETRY) run isort $(TESTS_DIR)
$(POETRY) run black $(TESTS_DIR)
.PHONY: isort
isort: $(INSTALL_STAMP) ## Run isort
$(POETRY) run isort --check-only $(TESTS_DIR)
.PHONY: black
black: $(INSTALL_STAMP) ## Run black
$(POETRY) run black --quiet --diff --check $(TESTS_DIR)
.PHONY: flake8
flake8: $(INSTALL_STAMP) ## Run flake8
$(POETRY) run flake8 --config $(FLAKE8_CONFIG) $(TESTS_DIR)
.PHONY: bandit
bandit: $(INSTALL_STAMP) ## Run bandit
$(POETRY) run bandit --quiet -r -c $(PYPROJECT_TOML) $(TESTS_DIR)
.PHONY: mypy
mypy: $(INSTALL_STAMP) ## Run mypy
$(POETRY) run mypy --config-file=$(PYPROJECT_TOML) $(TESTS_DIR)
.PHONY: pydocstyle
pydocstyle: $(INSTALL_STAMP) ## Run pydocstyle
$(POETRY) run pydocstyle -es --count --config=$(PYPROJECT_TOML) $(TESTS_DIR)
lint:
$(POETRY) -V
$(POETRY) install
$(POETRY) run isort --sp $(PYPROJECT_TOML) -c $(TESTS_DIR)
$(POETRY) run black --quiet --diff --config $(PYPROJECT_TOML) --check $(TESTS_DIR)
$(POETRY) run flake8 --config $(FLAKE8_CONFIG) $(TESTS_DIR)
$(POETRY) run bandit --quiet -r -c $(PYPROJECT_TOML) $(TESTS_DIR)
$(POETRY) run pydocstyle --config=$(PYPROJECT_TOML) $(TESTS_DIR)
$(POETRY) run mypy $(TESTS_DIR) --config-file=$(PYPROJECT_TOML)
load:
LOCUST_HOST=$(LOCUST_HOST) \
$(DOCKER_COMPOSE) \
-f $(LOAD_TEST_DIR)/docker-compose.yml \
-p autopush-rs-load-tests \
up --scale locust_worker=1
load-clean:
$(DOCKER_COMPOSE) \
-f $(LOAD_TEST_DIR)/docker-compose.yml \
-p autopush-rs-load-tests \
down
docker rmi locust
.PHONY: doc-prev
doc-prev: ## Generate live preview of autopush docs via browser
mdbook clean docs/
mdbook build docs/
mdbook serve docs/ --open
.PHONY: gen-key
gen-key: ## Generate the CryptoKey values
$(POETRY) install --no-root
$(POETRY) run python3 $(CURDIR)/scripts/autokey.py