-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from mx-moth/release-automation
Add automatic PyPI publishing
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: Publish a new version to PyPI | ||
on: | ||
# This allows manually triggering a release | ||
workflow_dispatch: | ||
|
||
# This will automatically publish tagged commits matching a version number | ||
# | ||
# push: | ||
# tags: | ||
# - "[0-9]+.*" | ||
|
||
env: | ||
package-name: "nco" | ||
python-version: "3.11" | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ env.python-version }} | ||
cache: 'pip' | ||
|
||
- name: Build python package | ||
shell: bash -l {0} | ||
run: | | ||
pip install build | ||
python3 -m build | ||
- name: Store package artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: "Python package" | ||
path: "dist/" | ||
|
||
- name: Check tag matches version | ||
shell: bash -l {0} | ||
run: | | ||
if ! [[ "${{ github.ref }}" == refs/tags/* ]] ; then | ||
echo >&2 "Current ref is not a tag - not publishing to PyPI!" | ||
exit 1 | ||
fi | ||
VERSION="$( echo "${{ github.ref }}" | sed 's!refs/tags/!!' )" | ||
echo "Looking for packages with version $VERSION" | ||
ls -l dist/* | ||
packages=( | ||
"dist/${{ env.package-name }}-$VERSION.tar.gz" | ||
"dist/${{ env.package-name }}-$VERSION-*.whl" | ||
) | ||
for package in "${packages[@]}" ; do | ||
if ! test -e $package ; then | ||
echo >&2 "Could not find package file $package" | ||
exit 1 | ||
fi | ||
done | ||
- name: Publish Python package | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
password: ${{ secrets.PYPI_API_TOKEN }} |