forked from alphagov/notifications-python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
132 lines (111 loc) · 4.19 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
.DEFAULT_GOAL := help
SHELL := /bin/bash
DOCKER_BUILDER_IMAGE_NAME = govuk/notify-python-client-runner
BUILD_TAG ?= notifications-python-client-manual
DOCKER_CONTAINER_PREFIX = ${USER}-${BUILD_TAG}
.PHONY: help
help:
@cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: venv
venv: venv/bin/activate ## Create virtualenv if it does not exist
venv/bin/activate:
test -d venv || virtualenv venv -p python3
.PHONY: dependencies
dependencies: venv ## Install build dependencies
pip install --upgrade .
.PHONY: build
build: dependencies ## Build project
.PHONY: test
test: venv ## Run tests
./scripts/run_tests.sh
.PHONY: integration-test
integration-test: venv ## Run integration tests
./scripts/run_integration_tests.sh
.PHONY: build-wheel
build-wheel: venv ## build distributable wheel
./venv/bin/pip install wheel
./venv/bin/python setup.py bdist_wheel
.PHONY: publish-to-pypi
publish-to-pypi: build-wheel ## upload distributable wheel to pypi
./venv/bin/pip install --upgrade twine
@./venv/bin/twine upload dist/*.whl \
--username="${PYPI_USERNAME}" \
--password="${PYPI_PASSWORD}" \
--skip-existing # if you haven't run `make clean` there may be old wheels - don't try and re-upload them
.PHONY: generate-env-file
generate-env-file: ## Generate the environment file for running the tests inside a Docker container
scripts/generate_docker_env.sh
.PHONY: prepare-docker-runner-image
prepare-docker-runner-image: ## Prepare the Docker builder image
make -C docker build
.PHONY: build-with-docker
build-with-docker: prepare-docker-runner-image ## Build inside a Docker container
docker run -i --rm \
--name "${DOCKER_CONTAINER_PREFIX}-build" \
-v "`pwd`:/var/project" \
-e http_proxy="${HTTP_PROXY}" \
-e HTTP_PROXY="${HTTP_PROXY}" \
-e https_proxy="${HTTPS_PROXY}" \
-e HTTPS_PROXY="${HTTPS_PROXY}" \
-e NO_PROXY="${NO_PROXY}" \
${DOCKER_BUILDER_IMAGE_NAME} \
make build
.PHONY: test-with-docker
test-with-docker: prepare-docker-runner-image generate-env-file ## Run tests inside a Docker container
docker run -i --rm \
--name "${DOCKER_CONTAINER_PREFIX}-test" \
-v "`pwd`:/var/project" \
-e http_proxy="${HTTP_PROXY}" \
-e HTTP_PROXY="${HTTP_PROXY}" \
-e https_proxy="${HTTPS_PROXY}" \
-e HTTPS_PROXY="${HTTPS_PROXY}" \
-e NO_PROXY="${NO_PROXY}" \
--env-file docker.env \
${DOCKER_BUILDER_IMAGE_NAME} \
make test
.PHONY: integration-test-with-docker
integration-test-with-docker: prepare-docker-runner-image generate-env-file ## Run integration tests inside a Docker container
docker run -i --rm \
--name "${DOCKER_CONTAINER_PREFIX}-integration-test" \
-v "`pwd`:/var/project" \
-e http_proxy="${HTTP_PROXY}" \
-e HTTP_PROXY="${HTTP_PROXY}" \
-e https_proxy="${HTTPS_PROXY}" \
-e HTTPS_PROXY="${HTTPS_PROXY}" \
-e NO_PROXY="${NO_PROXY}" \
--env-file docker.env \
${DOCKER_BUILDER_IMAGE_NAME} \
make integration-test
.PHONY: publish-to-pypi-with-docker
publish-to-pypi-with-docker: prepare-docker-runner-image generate-env-file ## publish wheel to pypi inside a docker container
@docker run -i --rm \
--name "${DOCKER_CONTAINER_PREFIX}-publish-to-pypi" \
-v "`pwd`:/var/project" \
-e http_proxy="${HTTP_PROXY}" \
-e HTTP_PROXY="${HTTP_PROXY}" \
-e https_proxy="${HTTPS_PROXY}" \
-e HTTPS_PROXY="${HTTPS_PROXY}" \
-e NO_PROXY="${NO_PROXY}" \
-e PYPI_USERNAME="${PYPI_USERNAME}" \
-e PYPI_PASSWORD="${PYPI_PASSWORD}" \
--env-file docker.env \
${DOCKER_BUILDER_IMAGE_NAME} \
make publish-to-pypi
.PHONY: clean-docker-containers
clean-docker-containers: ## Clean up any remaining docker containers
docker rm -f $(shell docker ps -q -f "name=${DOCKER_CONTAINER_PREFIX}") 2> /dev/null || true
clean:
rm -rf .cache venv dist .eggs build .tox
.PHONY: tox-with-docker
tox-with-docker: prepare-docker-runner-image generate-env-file
docker run -i --rm \
--name "${DOCKER_CONTAINER_PREFIX}-integration-test" \
-v "`pwd`:/var/project" \
-e http_proxy="${HTTP_PROXY}" \
-e HTTP_PROXY="${HTTP_PROXY}" \
-e https_proxy="${HTTPS_PROXY}" \
-e HTTPS_PROXY="${HTTPS_PROXY}" \
-e NO_PROXY="${NO_PROXY}" \
--env-file docker.env \
${DOCKER_BUILDER_IMAGE_NAME} \
tox