-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathMakefile
171 lines (134 loc) · 3.64 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
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
VERSION := $(shell python setup.py --version)
HOSTNAME := $(shell hostname)
S3_PREFIX := s3://rstudio-connect-downloads/connect/rsconnect-python
BDIST_WHEEL := dist/rsconnect_python-$(VERSION)-py2.py3-none-any.whl
RUNNER = docker run \
-it --rm \
-v $(PWD):/rsconnect \
-w /rsconnect \
rsconnect-python:$* \
bash -c
TEST_COMMAND ?= ./scripts/runtests
SHELL_COMMAND ?= bash
ifneq ($(GITHUB_RUN_ID),)
RUNNER = bash -c
endif
TEST_ENV =
ifneq ($(CONNECT_SERVER),)
TEST_ENV += CONNECT_SERVER=$(CONNECT_SERVER)
endif
ifneq ($(CONNECT_API_KEY),)
TEST_ENV += CONNECT_API_KEY=$(CONNECT_API_KEY)
endif
# NOTE: See the `dist` target for why this exists.
SOURCE_DATE_EPOCH := $(shell date +%s)
export SOURCE_DATE_EPOCH
.PHONY: all-tests
all-tests: all-images test-2.7 test-3.5 test-3.6 test-3.7 test-3.8
.PHONY: all-images
all-images: image-2.7 image-3.5 image-3.6 image-3.7 image-3.8
image-%:
docker build -t rsconnect-python:$* --build-arg BASE_IMAGE=python:$*-slim .
shell-%:
$(RUNNER) '$(SHELL_COMMAND)'
test-%:
PYTHON_VERSION=$* $(RUNNER) '$(TEST_ENV) $(TEST_COMMAND)'
mock-test-%: clean-stores
@$(MAKE) -C mock_connect image up
@sleep 1
CONNECT_SERVER=http://$(HOSTNAME):3939 CONNECT_API_KEY=0123456789abcdef0123456789abcdef $(MAKE) test-$*
@$(MAKE) -C mock_connect down
fmt-%:
$(RUNNER) 'black .'
.PHONY: fmt-2.7
fmt-2.7: .fmt-unsupported
.PHONY: fmt-3.5
fmt-3.5: .fmt-unsupported
.PHONY: .fmt-unsupported
.fmt-unsupported:
@echo ERROR: This python version cannot run the fmting tools
@exit 1
.PHONY: deps-prerelease
deps-prerelease:
pip install --pre -r requirements.txt
deps-%:
$(RUNNER) 'pip install --pre -r requirements.txt'
lint-%:
$(RUNNER) 'black --check --diff rsconnect/'
$(RUNNER) 'flake8 rsconnect/'
$(RUNNER) 'mypy -p rsconnect'
.PHONY: lint-2.7
lint-2.7: .lint-unsupported
.PHONY: lint-3.5
lint-3.5: .lint-unsupported
.PHONY: .lint-unsupported
.lint-unsupported:
@echo ERROR: This python version cannot run the linting tools
@exit 1
.PHONY: clean
clean:
$(RM) -r \
./.coverage \
./.mypy_cache \
./.pytest_cache \
./build \
./dist \
./htmlcov \
./rsconnect_python.egg-info
.PHONY: clean-stores
clean-stores:
@find . -name "rsconnect-python" | xargs rm -rf
.PHONY: shell
shell: RUNNER = bash -c
shell: shell-3.8
.PHONY: test
test: RUNNER = bash -c
test: test-3.8
.PHONY: lint
lint: RUNNER = bash -c
lint: lint-3.8
.PHONY: deps
deps: RUNNER = bash -c
deps: deps-3.8
.PHONY: fmt
fmt: RUNNER = bash -c
fmt: fmt-3.8
.PHONY: docs
docs:
$(MAKE) -C docs VERSION=$(VERSION)
.PHONY: version
version:
@echo $(VERSION)
# NOTE: Wheels won't get built if _any_ file it tries to touch has a timestamp
# before 1980 (system files) so the $(SOURCE_DATE_EPOCH) current timestamp is
# exported as a point of reference instead.
.PHONY: dist
dist:
python setup.py bdist_wheel
twine check $(BDIST_WHEEL)
rm -vf dist/*.egg
@echo "::set-output name=whl::$(BDIST_WHEEL)"
@echo "::set-output name=whl_basename::$(notdir $(BDIST_WHEEL))"
.PHONY: sync-to-s3
sync-to-s3:
aws s3 cp --acl bucket-owner-full-control \
$(BDIST_WHEEL) \
$(S3_PREFIX)/$(VERSION)/$(notdir $(BDIST_WHEEL))
.PHONY: sync-latest-to-s3
sync-latest-to-s3:
aws s3 cp --acl bucket-owner-full-control \
--cache-control max-age=0 \
$(BDIST_WHEEL) \
$(S3_PREFIX)/latest/rsconnect_python-latest-py2.py3-none-any.whl
.PHONY: sync-latest-docs-to-s3
sync-latest-docs-to-s3:
aws s3 sync --acl bucket-owner-full-control \
--cache-control max-age=0 \
docs/site/ \
$(S3_PREFIX)/latest/docs/
.PHONY: promote-docs-in-s3
promote-docs-in-s3:
aws s3 sync --delete --acl bucket-owner-full-control \
--cache-control max-age=300 \
docs/site/ \
s3://docs.rstudio.com/rsconnect-python/