-
Notifications
You must be signed in to change notification settings - Fork 0
512 lines (430 loc) · 18.4 KB
/
publish.yaml
File metadata and controls
512 lines (430 loc) · 18.4 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
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
# Based on https://github.com/prettier/prettier/blob/master/.github/workflows/dev-test.yml
name: Publish to PyPi
on:
workflow_dispatch:
inputs:
randomlyseed:
description: 'Pytest Randomly Seed'
required: false
default: ''
dry_run:
description: 'Do a dry run and do not publish'
required: false
default: '0'
push:
branches:
- main
jobs:
test:
strategy:
fail-fast: false
matrix:
os:
- "ubuntu-18.04"
- "ubuntu-20.04"
- "windows-2019"
- "macos-10.15"
# - "macos-11.0"
python-version:
- 3.7
- 3.8
- 3.9
include:
# only enable coverage on the fastest job
- os: "ubuntu-20.04"
python-version: "3.9"
IS_FASTEST_JOB: true
name: Test code before publishing in Python ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: |
python -c "import sys; print(sys.version)"
python -m venv venv
- name: Extract version number # Adapted from: https://stackoverflow.com/questions/58033366/how-to-get-current-branch-within-github-actions
shell: bash
run: echo '##[set-output name=package-version;]$(echo $(python .github/workflows/extract_package_info.py package_version))'
id: extract_version
- name: Display extracted version number
shell: bash
run: |
echo "Version: ${{ steps.extract_version.outputs.package-version }}"
- name: Confirming tag not already present on remote (if publishing)
if: github.event.inputs.dry_run != '1' && matrix.IS_FASTEST_JOB == true
run: if [$(git ls-remote --tags origin | grep v${{ steps.extract_version.outputs.package-version }}) = '']; then echo Tag does not exist on remote; else echo Tag already exists on remote && exit 1; fi
- name: Cache Pre-commit hooks
uses: actions/cache@v2.1.4
env:
cache-name: cache-pre-commit-hooks
if: matrix.IS_FASTEST_JOB == true
with:
path: ./.precommit_cache
key: ${{ matrix.os }}-${{ matrix.python-version }}-build-${{ env.cache-name }}-${{ hashFiles('**/.pre-commit-config.yaml') }}
restore-keys: |
${{ matrix.os }}-${{ matrix.python-version }}-build-${{ env.cache-name }}-
- name: Extract branch name # Adapted from: https://stackoverflow.com/questions/58033366/how-to-get-current-branch-within-github-actions
if: runner.os == 'Linux'
shell: bash
run: |
git branch -av
echo '##[set-output name=sha-of-main-branch;]$(echo $(git branch -av | grep remotes/origin/main | grep -oP "main\s+\K\w+"))'
echo '##[set-output name=sha-of-development-branch;]$(echo $(git branch -av | grep remotes/origin/development | grep -oP "development\s+\K\w+"))'
echo '##[set-output name=sha-of-current-branch;]$(echo $(git branch -av | grep "*" | grep -oP " \s+\K\w+"))'
id: extract_branch
- name: Display extracted branch information
if: runner.os == 'Linux'
run: |
echo "SHA of current branch: ${{ steps.extract_branch.outputs.sha-of-current-branch }}"
echo "SHA of main branch: ${{ steps.extract_branch.outputs.sha-of-main-branch }}"
echo "SHA of development branch: ${{ steps.extract_branch.outputs.sha-of-development-branch }}"
- name: Is this running on development branch?
if: runner.os == 'Linux'
run: if [ "${{ steps.extract_branch.outputs.sha-of-current-branch}}" = "${{ steps.extract_branch.outputs.sha-of-development-branch}}" ] ; then echo "Running on development branch."; else echo "Not running on development branch."; fi
- name: Is this running on main branch?
if: runner.os == 'Linux'
run: if [ "${{ steps.extract_branch.outputs.sha-of-current-branch}}" = "${{ steps.extract_branch.outputs.sha-of-main-branch}}" ] ; then echo "Running on main branch."; else echo "Not running on main branch."; fi
- name: Fail if attempting to publish from a branch other than main
if: runner.os == 'Linux' && github.event.inputs.dry_run != '1'
run: if [ "${{ steps.extract_branch.outputs.sha-of-current-branch}}" = "${{ steps.extract_branch.outputs.sha-of-main-branch}}" ] ; then echo "Running on main branch, can proceed to publish."; else exit 1; fi
- name: Activate virtual environment (Linux/MacOS)
if: runner.os == 'Linux' || runner.os == 'macOS'
run: . venv/bin/activate
- name: Activate virtual environment (Windows)
if: runner.os == 'Windows'
run: venv\Scripts\Activate.ps1
- name: Display Pip Version and confirm environment empty
run: |
pip -V
pip freeze
- name: Install Dev Dependencies
run: |
pip install -r requirements-dev.txt
pip install -r docs/requirements.txt
- name: Install Main Package
run: pip install -e .
- name: Log full installed packages
run: pip freeze
- name: Run pre-commit hooks
if: matrix.IS_FASTEST_JOB == true
run: |
pre-commit install
pre-commit run -a
- name: Run Tests with randomly generated seed
if: github.event.inputs.randomlyseed == ''
run: pytest -xsvv --cov-report=xml --full-ci --include-slow-tests -n auto
- name: Run Tests with supplied pytest-randomly seed
if: github.event.inputs.randomlyseed != ''
run: pytest -xsvv --cov-report=xml --full-ci --include-slow-tests -n auto --randomly-seed=${{ github.event.inputs.randomlyseed }}
- name: Confirm Sphinx Docs build correctly
# only check Sphinx docs build on the fastest job
if: matrix.IS_FASTEST_JOB == true
run: SPHINXOPTS="-W" make --directory=docs html # the -W flag treats warnings as errors to cause build failures
- name: Run prerelease to check packaging compatibilty
run: prerelease --no-input
- name: Build wheel for release
run: python setup.py bdist_wheel
# IMPORTANT! If a platform-specific wheel is generated, sometimes they may need to be renamed or there can be unexplained (Eli 2/25/21) issues getting the to install. See example: https://github.com/CuriBio/mantarray-waveform-analysis/blob/b4ef677f20c16e14156f941c6581b50802773010/.github/workflows/publish.yaml#L158
- name: Build sdist for release (Linux)
if: matrix.IS_FASTEST_JOB == true
run: python setup.py sdist
- name: Confirm no modifications to the repository files occurred when running the test suite
if: matrix.IS_FASTEST_JOB == true # only enable pre-commit on the fastest job
env:
PRE_COMMIT_HOME: ./.precommit_cache
run: pre-commit run git-dirty -a
- name: Upload build artifact
uses: actions/upload-artifact@v2
with:
name: dist--${{ matrix.os }}--${{ matrix.python-version }}
path: dist/*
publish_to_test_pypi:
needs: [test]
strategy:
fail-fast: false
matrix: # if publishing pure python code, then disable all except one os and python version combination. But if publishing code that uses Cython then likely all combinations will be needed
os:
- "ubuntu-20.04"
- "windows-2019"
- "macos-10.15"
# - "macos-11.0"
python-version:
- 3.7
- 3.8
- 3.9
name: Publish to Test PyPI for Python ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: |
python -c "import sys; print(sys.version)"
python -m venv venv
- name: Activate virtual environment (Linux/MacOS)
if: runner.os == 'Linux' || runner.os == 'macOS'
run: . venv/bin/activate
- name: Activate virtual environment (Windows)
if: runner.os == 'Windows'
run: venv\Scripts\Activate.ps1
- name: Display Pip Version and confirm environment empty
run: |
pip -V
pip freeze
- name: Install Dev Dependencies
run: pip install -r requirements-dev.txt
- name: Log full installed packages
run: pip freeze
- name: Download built dist folder from previous step
uses: actions/download-artifact@v2
with:
name: dist--${{ matrix.os }}--${{ matrix.python-version }}
path: dist
- name: Uploading to Test PyPI
if: github.event.inputs.dry_run != '1'
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: twine upload --repository testpypi dist/*
- name: Sleep for 360 seconds to allow Test PyPI Index to update before proceeding to the next step
if: github.event.inputs.dry_run != '1'
uses: juliangruber/sleep-action@v1
with:
time: 360s
install_from_test_pypi:
needs: [publish_to_test_pypi]
strategy:
fail-fast: false
matrix:
os:
- "ubuntu-18.04"
- "ubuntu-20.04"
- "windows-2019"
- "macos-10.15"
# - "macos-11.0"
python-version:
- 3.7
- 3.8
- 3.9
name: Install from Test PyPI and run tests on Python ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: |
python -c "import sys; print(sys.version)"
python -m venv venv
- name: Activate virtual environment (Linux/MacOS)
if: runner.os == 'Linux' || runner.os == 'macOS'
run: . venv/bin/activate
- name: Activate virtual environment (Windows)
if: runner.os == 'Windows'
run: venv\Scripts\Activate.ps1
- name: Display Pip Version and confirm environment empty
run: |
pip -V
pip freeze
- name: Download built dist folder from previous step
uses: actions/download-artifact@v2
with:
name: dist--${{ matrix.os }}--${{ matrix.python-version }}
path: dist
- name: Extract package info # Adapted from: https://stackoverflow.com/questions/58033366/how-to-get-current-branch-within-github-actions
shell: bash
run: |
echo '##[set-output name=package-name;]$(echo $(python .github/workflows/extract_package_info.py package_name))'
echo '##[set-output name=package-version;]$(echo $(python .github/workflows/extract_package_info.py package_version))'
id: extract_package_info
- name: Install Main Package From Test PyPI
if: github.event.inputs.dry_run != '1'
run: python .github/workflows/extract_package_info.py install_from_test_pypi
- name: Install Main Package From built wheel file as test since not publishing to PyPI
if: github.event.inputs.dry_run == '1'
run: python .github/workflows/extract_package_info.py install_from_dist
- name: Confirm no import errors when opening package
run: python -c "import ${{ steps.extract_package_info.outputs.package-name }}"
- name: Install Dev Dependencies
run: pip install -r requirements-dev.txt
- name: Log full installed packages
run: pip freeze
- name: Run Tests with randomly generated seed
if: github.event.inputs.randomlyseed == ''
run: pytest -xsvv --full-ci --include-slow-tests -n auto
- name: Run Tests with supplied pytest-randomly seed
if: github.event.inputs.randomlyseed != ''
run: pytest -xsvv --full-ci --include-slow-tests -n auto --randomly-seed=${{ github.event.inputs.randomlyseed }}
publish_to_pypi:
needs: [install_from_test_pypi]
strategy:
fail-fast: false
matrix: # if publishing pure python code, then disable all except one os and python version combination. But if publishing code that uses Cython then likely all combinations will be needed
os:
- "ubuntu-20.04"
- "windows-2019"
- "macos-10.15"
# - "macos-11.0"
python-version:
- 3.7
- 3.8
- 3.9
name: Publish to PyPI for Python ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: |
python -c "import sys; print(sys.version)"
python -m venv venv
- name: Activate virtual environment (Linux/MacOS)
if: runner.os == 'Linux' || runner.os == 'macOS'
run: . venv/bin/activate
- name: Activate virtual environment (Windows)
if: runner.os == 'Windows'
run: venv\Scripts\Activate.ps1
- name: Display Pip Version and confirm environment empty
run: |
pip -V
pip freeze
- name: Install Dev Dependencies
run: pip install -r requirements-dev.txt
- name: Log full installed packages
run: pip freeze
- name: Download built dist folder from previous step
uses: actions/download-artifact@v2
with:
name: dist--${{ matrix.os }}--${{ matrix.python-version }}
path: dist
- name: Uploading to PyPi
if: github.event.inputs.dry_run != '1'
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: twine upload dist/*
- name: Sleep for 360 seconds to allow PyPI Index to update before proceeding to the next step
if: github.event.inputs.dry_run != '1'
uses: juliangruber/sleep-action@v1
with:
time: 360s
install_from_pypi:
needs: [publish_to_pypi]
strategy:
fail-fast: false
matrix:
os:
- "ubuntu-18.04"
- "ubuntu-20.04"
- "windows-2019"
- "macos-10.15"
# - "macos-11.0"
python-version:
- 3.7
- 3.8
- 3.9
name: Test installation from PyPI for Python ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: |
python -c "import sys; print(sys.version)"
python -m venv venv
- name: Activate virtual environment (Linux/MacOS)
if: runner.os == 'Linux' || runner.os == 'macOS'
run: . venv/bin/activate
- name: Activate virtual environment (Windows)
if: runner.os == 'Windows'
run: venv\Scripts\Activate.ps1
- name: Display Pip Version and confirm environment empty
run: |
pip -V
pip freeze
- name: Download built dist folder from previous step
uses: actions/download-artifact@v2
with:
name: dist--${{ matrix.os }}--${{ matrix.python-version }}
path: dist
- name: Extract package info # Adapted from: https://stackoverflow.com/questions/58033366/how-to-get-current-branch-within-github-actions
shell: bash
run: |
echo '##[set-output name=package-name;]$(echo $(python .github/workflows/extract_package_info.py package_name))'
echo '##[set-output name=package-version;]$(echo $(python .github/workflows/extract_package_info.py package_version))'
id: extract_package_info
- name: Install Main Package From PyPI
if: github.event.inputs.dry_run != '1'
run: python .github/workflows/extract_package_info.py install_from_pypi
- name: Install Main Package From built wheel file as test since not publishing to PyPI
if: github.event.inputs.dry_run == '1'
run: python .github/workflows/extract_package_info.py install_from_dist
- name: Confirm no import errors when opening package
run: python -c "import ${{ steps.extract_package_info.outputs.package-name }}"
- name: Install Dev Dependencies
run: pip install -r requirements-dev.txt
- name: Log full installed packages
run: pip freeze
- name: Run Tests with randomly generated seed
if: github.event.inputs.randomlyseed == ''
run: pytest -xsvv --full-ci --include-slow-tests -n auto
- name: Run Tests with supplied pytest-randomly seed
if: github.event.inputs.randomlyseed != ''
run: pytest -xsvv --full-ci --include-slow-tests -n auto --randomly-seed=${{ github.event.inputs.randomlyseed }}
create_tag:
needs: [install_from_pypi]
strategy:
fail-fast: false
matrix:
os:
- "ubuntu-20.04"
name: Creating tag on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Extract version number # Adapted from: https://stackoverflow.com/questions/58033366/how-to-get-current-branch-within-github-actions
shell: bash
run: echo '##[set-output name=package-version;]$(echo $(grep -Po "(?<= version=\")[0-9.]+" setup.py))'
id: extract_version
- name: Tagging commit
run: |
echo "About to tag with: v${{ steps.extract_version.outputs.package-version }}"
git tag "v${{ steps.extract_version.outputs.package-version }}"
- name: Listing all local tags (including new tag)
run: git tag -l
- name: Pushing Tag
if: github.event.inputs.dry_run != '1'
run: git push --tags