generated from sodre/ght-pypackage
-
Notifications
You must be signed in to change notification settings - Fork 1
347 lines (326 loc) · 10.4 KB
/
pypa-conda.yml
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#
# This GitHub Workflow was installed from https://github.com/sodre/workflows
# Please see the original repo on instructions on how to keep this up-to-date
name: pypa-conda
on:
release:
types: [published]
pull_request:
jobs:
#
# Create the PyPA source distribution
# - It must be architecture independent.
# - It must adhere to black code-formatting rules.
# - It must pass flake8 source code analysis.
create-sdist:
name: pypa-sdist
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.6]
black-version: [19.10b]
flake8-version: [3.7.9]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1.1.1
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v1
id: cache
with:
path: ~/.cache/pip
key: ${{ matrix.os }}-py${{ matrix.python-version }}-pip-black${{matrix.black-version}}-flake8${{matrix.flake8-version }}
- name: Install Black and Flake8
run: pip install black flake8
- name: Enforce black formatting
run: black --check .
- name: Enforce Flake8
run: flake8
- name: Build source distribution
run: python setup.py sdist
- uses: actions/upload-artifact@v1.0.0
with:
name: pypa-sdist
path: dist
#
# Create the PyPA binary distribution wheel
# - It must start from the source distribution
# - It can be architecture dependent, or universal (assumed in this case)
create-bdist-wheel:
name: pypa-bdist-wheel
needs:
- create-sdist
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.7]
runs-on: ${{ matrix.os }}
steps:
- name: Download the source distribution
uses: actions/download-artifact@v1.0.0
with:
name: pypa-sdist
path: .
# TODO: This piece can be improved, e.g. ensuring we are deleting the correct file
- name: Unpack the source distribution
run: |
tar -xvf *.tar.gz --strip 1
rm -f *.tar.gz
# Create the bdist wheel file
- uses: actions/setup-python@v1.1.1
- uses: actions/cache@v1
id: cache
with:
path: .eggs
key: ${{ matrix.os }}-${{ matrix.python-version }}-eggs-${{ hashFiles('setup.py') }}
- run: python setup.py bdist_wheel
- uses: actions/upload-artifact@v1.0.0
with:
name: pypa-bdist-wheel
path: dist
#
# Create the test distribution
# - It must start from the source distribution
# - It is architecture independent
create-tdist:
name: custom-tdist
needs:
- create-sdist
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.7]
runs-on: ${{ matrix.os }}
steps:
- name: Download the source distribution
uses: actions/download-artifact@v1.0.0
with:
name: pypa-sdist
path: .
# TODO: This piece can be improved, e.g. ensuring we are deleting the correct file
- name: Unpack the source distribution
run: |
tar -xvf *.tar.gz --strip 1
rm -f *.tar.gz
# Create the test distribution
- name: Create test distribution
run: |
mkdir dist
mv .coveragerc .github/codecov.yml setup.cfg setup.py tests dist
- uses: actions/upload-artifact@v1.0.0
with:
name: custom-tdist
path: dist
#
# Ensure pypa distribution passes unit tests
# - These must run on every pull-request commit
# - They should run on as many architectures as we expect to support
serverless-tox:
name: pypa-detox
needs:
- create-tdist
- create-bdist-wheel
if: github.event_name == 'pull_request'
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
python-version: [3.8]
runs-on: ${{ matrix.os }}
steps:
- name: Download the binary distribution
uses: actions/download-artifact@v1.0.0
with:
name: pypa-bdist-wheel
path: dist
- name: Download the test distribution
uses: actions/download-artifact@v1.0.0
with:
name: custom-tdist
path: .
#
# Setup the test environment, python + .whl + .whl[test]
- uses: actions/setup-python@v1.1.1
with:
python-version: ${{ matrix.python-version }}
- name: Get pip cache
id: pip-cache
run: |
python -c "from pip._internal.locations import USER_CACHE_DIR; print('::set-output name=dir::' + USER_CACHE_DIR)"
- uses: actions/cache@v1
id: cache
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ matrix.os }}-py${{ matrix.python-version }}-pip-${{ hashFiles('setup.py') }}
- name: Install binary and test dependencies
shell: bash
run: |
find dist -type f -name '*.whl' -exec pip install {} +
find dist -type f -name '*.whl' -exec pip install {}[test] \;
rm -rf dist
#
# Runs the test with coverage
- name: Run pytest through coverage
run: coverage run -m pytest
- name: Create coverage.xml artifact
run: coverage xml
# TODO: export junit.xml and coverage.xml as artifacts
- uses: codecov/codecov-action@v1
with:
name: ${{ matrix.os }}-py${{ matrix.python-version }}
fail_ci_if_error: true
file: ./coverage.xml
yml: .github/codecov.yml
token: ${{ secrets.CODECOV_TOKEN }}
#
# Create Conda Distribution
# - Must start from source distribution
# - Outputs the non-indexed contents of conda-bld folder
create-conda-package:
name: conda-build
needs:
- create-sdist
strategy:
matrix:
arch: [noarch]
python-version: [3.7]
runs-on: ubuntu-latest
steps:
- name: Download Source Distribution
uses: actions/download-artifact@v1.0.0
with:
name: pypa-sdist
path: .
# TODO: This piece can be improved, e.g. ensuring we are deleting the same file
- name: Unpack Source Distribution
run: |
tar -xvf *.tar.gz --strip 1
rm *.tar.gz
- uses: goanpeca/setup-miniconda@v1
with:
activate-environment: ''
auto-activate-base: true
conda-build-version: 3.18
condarc-file: .github/condarc.yml
- run: conda install setuptools_scm conda-verify
- uses: actions/cache@v1
id: conda-pkgs-cache
with:
path: /usr/share/miniconda/pkgs
key: ${{ runner.os }}-conda-py${{ matrix.python-version }}-${{ hashFiles('setup.py') }}
# TODO: We have to create an Anaconda token file to download private packages
- name: Run conda build
run: |
mkdir conda-bld
conda build --output-folder conda-bld .
env:
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_API_TOKEN }}
- name: Create conda-bld/manifest
run: |
for subdir in $(jq -r .subdirs[] conda-bld/channeldata.json); do
for pkg in $(jq -r '.packages | to_entries[] | .key' conda-bld/$subdir/repodata.json); do
echo conda-bld/$subdir/$pkg
done
done > conda-bld/manifest
- name: Make conda-bld artifact
run: |
mkdir dist
echo conda-bld/manifest | cat - conda-bld/manifest | zip -@ dist/conda-bld-${{ matrix.arch }}.zip
- uses: actions/upload-artifact@v1.0.0
with:
name: conda-bld-${{ matrix.arch }}
path: dist
#
# Publish the PyPA distributions to Release
upload-to-github:
name: upload-to-github
if: github.event_name == 'release'
needs:
- create-sdist
- create-bdist-wheel
- create-conda-package
strategy:
matrix:
artifact-name:
- pypa-sdist
- pypa-bdist-wheel
- conda-bld-noarch
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v1.0.0
with:
name: ${{ matrix.artifact-name }}
path: dist
#
# Publish Release Asset (to GitHub)
- name: Upload assets to this release
uses: AButler/upload-release-assets@v2.0
with:
files: dist/*
repo-token: ${{ secrets.GITHUB_TOKEN }}
#
# Publish to PyPi if public repository
upload-to-pypi:
name: upload-to-pypi
if: github.event.repository.private == false && github.event_name == 'release'
runs-on: ubuntu-latest
needs:
- upload-to-github
steps:
- name: Download source distribution
uses: actions/download-artifact@v1.0.0
with:
name: pypa-sdist
path: dist
- name: Download binary distribution
uses: actions/download-artifact@v1.0.0
with:
name: pypa-bdist-wheel
path: dist
- uses: actions/setup-python@v1.1.1
- name: Upload release to pypi.org
if: github.event.repository.private == false
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
pip install twine
twine upload dist/*
#
# Publish to Anaconda Cloud
upload-to-anaconda:
name: upload-to-anaconda
if: github.event_name == 'release'
needs:
- upload-to-github
strategy:
matrix:
artifact-name:
- conda-bld-noarch
runs-on: ubuntu-latest
steps:
- name: Download ${{ matrix.artifact-name }} distribution
uses: actions/download-artifact@v1.0.0
with:
name: ${{ matrix.artifact-name }}
path: .
- name: Unpack ${{ matrix.artifact-name }}
run: unzip ${{ matrix.artifact-name }}.zip
# Publish to Anaconda Cloud / Public and Private repos
- uses: actions/cache@v1
id: conda-pkgs-cache
with:
path: /usr/share/miniconda/pkgs
key: ${{ runner.os }}-conda-ac1.7.2
- uses: goanpeca/setup-miniconda@v1
with:
activate-environment: ''
auto-activate-base: true
- run: conda install anaconda-client=1.7.2
- name: Upload to Anaconda Cloud
run: |
cat conda-bld/manifest \
| xargs conda server upload `if ${{ github.event.repository.private }}; then echo --private; fi`
env:
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_API_TOKEN }}