Skip to content

Commit 90fb4c7

Browse files
committed
CI: Condition upload attempt on presence of token
1 parent 2d4addc commit 90fb4c7

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

.github/workflows/pythonpackage.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,18 @@ jobs:
8080
with:
8181
name: distributions
8282
path: dist/
83-
- name: Upload to PyPI (on tags)
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
8489
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
8595
uses: pypa/gh-action-pypi-publish@master
8696
with:
8797
user: __token__

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

0 commit comments

Comments
 (0)