Skip to content

Commit 210bbf3

Browse files
authored
Merge pull request #16 from effigies/enh/pypi_deployment
ENH: Add PyPI deployment to GitHub action
2 parents 00d3a52 + 90fb4c7 commit 210bbf3

File tree

4 files changed

+70
-3
lines changed

4 files changed

+70
-3
lines changed

.github/workflows/pythonpackage.yml

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
# Packages that use it probably do not want to continue testing with editable installations,
77
# quadrupling their test load.
88

9+
# For deployment, it will be necessary to create a PyPI API token and store it as a secret
10+
# https://docs.github.com/en/actions/reference/encrypted-secrets
11+
912
name: Python package
1013

1114
# Set once
@@ -15,11 +18,12 @@ env:
1518
on:
1619
push:
1720
branches: [ main ]
21+
tags: [ '*' ]
1822
pull_request:
1923
branches: [ main ]
2024

2125
jobs:
22-
build:
26+
test:
2327
runs-on: ubuntu-latest
2428
strategy:
2529
matrix:
@@ -50,3 +54,45 @@ jobs:
5054
- name: Test with pytest
5155
run: |
5256
pytest -sv --doctest-modules pydra/tasks/$SUBPACKAGE
57+
58+
deploy:
59+
needs: test
60+
runs-on: ubuntu-latest
61+
strategy:
62+
matrix:
63+
python-version: [3.9]
64+
steps:
65+
- uses: actions/checkout@v2
66+
with:
67+
submodules: recursive
68+
fetch-depth: 0
69+
- name: Set up Python ${{ matrix.python-version }}
70+
uses: actions/setup-python@v2
71+
with:
72+
python-version: ${{ matrix.python-version }}
73+
- name: Install build tools
74+
run: python -m pip install --upgrade pip setuptools wheel twine
75+
- name: Build source and wheel distributions
76+
run: python setup.py sdist bdist_wheel
77+
- name: Check distributions
78+
run: twine check dist/*
79+
- uses: actions/upload-artifact@v2
80+
with:
81+
name: distributions
82+
path: dist/
83+
# Deploy on tags if PYPI_API_TOKEN is defined in the repository secrets.
84+
# Secrets are not accessible in the if: condition [0], so set an output variable [1]
85+
# [0] https://github.community/t/16928
86+
# [1] https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-output-parameter
87+
- name: Check for PyPI token on tag
88+
id: deployable
89+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
90+
env:
91+
PYPI_API_TOKEN: "${{ secrets.PYPI_API_TOKEN }}"
92+
run: if [ -n "$PYPI_API_TOKEN" ]; then echo ::set-output name=DEPLOY::true; fi
93+
- name: Upload to PyPI
94+
if: steps.deployable.outputs.DEPLOY
95+
uses: pypa/gh-action-pypi-publish@master
96+
with:
97+
user: __token__
98+
password: ${{ secrets.PYPI_API_TOKEN }}

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2020 Nipype developers
1+
Copyright 2021 Nipype developers
22

33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ python setup.py sdist bdist_wheel
3535
twine upload dist/*
3636
```
3737

38-
Note that we assume tags will be version numbers and not be prefixed with `v` or some other
38+
Note that uploading to PyPI is done via [Continuous integration](#continuous-integration)) when
39+
a tag is pushed to the repository, so only the first step needs to be donne manually.
40+
41+
Note also that we assume tags will be version numbers and not be prefixed with `v` or some other
3942
string. See Versioneer documentation for alternative configurations.
4043

4144
## Namespace packages
@@ -72,6 +75,10 @@ non-compliant package can potentially affect Pydra or other task packages.
7275
In addition to verifying installations do not break or conflict, pytest is run on the package,
7376
including all tests found in `test/` directories and [doctests].
7477

78+
Finally, packages are built and uploaded as artifacts for inspection. When a tag is pushed,
79+
the packages are uploaded to PyPI if a valid [API token](https://pypi.org/help/#apitoken) is placed
80+
in the [repository secrets](https://docs.github.com/en/actions/reference/encrypted-secrets).
81+
7582
[doctests]: https://docs.python.org/3/library/doctest.html
7683

7784
# Contributing to this template

setup.cfg

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ subpackage = TODO
55
author = TODO
66
author_email = TODO
77
description = TODO
8+
long_description = file:README.md
9+
long_description_content_type = text/markdown; variant=CommonMark
10+
license = Apache License, 2.0
11+
classifiers =
12+
Development Status :: 2 - Pre-Alpha
13+
Environment :: Console
14+
Intended Audience :: Science/Research
15+
License :: OSI Approved :: Apache Software License
16+
Operating System :: MacOS :: MacOS X
17+
Operating System :: POSIX :: Linux
18+
Programming Language :: Python :: 3.7
19+
Programming Language :: Python :: 3.8
20+
Programming Language :: Python :: 3.9
21+
Topic :: Scientific/Engineering
822

923
[options]
1024
python_requires = >=3.7

0 commit comments

Comments
 (0)