Skip to content

Using github actions to publish to PyPi #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/check-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Check if required secrets are set to publish to Pypi

on: push

jobs:
checksecret:
name: check if PYPI_TOKEN and TESTPYPI_TOKEN are set in github secrets
runs-on: ubuntu-latest
steps:
- name: Check PYPI_TOKEN
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
if ${{ env.PYPI_TOKEN == '' }} ; then
echo "PYPI_TOKEN secret is not set"
exit 1
fi
- name: Check TESTPYPI_TOKEN
env:
TESTPYPI_TOKEN: ${{ secrets.TESTPYPI_TOKEN }}
run: |
if ${{ env.TESTPYPI_TOKEN == '' }} ; then
echo "TESTPYPI_TOKEN secret is not set"
exit 1
fi


50 changes: 50 additions & 0 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Publish Pypi
on:
release:
types: [published]

jobs:
publish:
name: publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up Python 2.7
uses: actions/setup-python@v1
with:
python-version: 2.7

- name: Install twine
run: |
pip install twine

- name: Install wheel
run: |
pip install wheel

- name: Create a source distribution
run: |
python setup.py sdist

- name: Create a wheel
run: |
python setup.py bdist_wheel

- name: Create a .pypirc
run: |
echo -e "[pypi]" >> ~/.pypirc
echo -e "username = __token__" >> ~/.pypirc
echo -e "password = ${{ secrets.PYPI_TOKEN }}" >> ~/.pypirc
echo -e "[testpypi]" >> ~/.pypirc
echo -e "username = __token__" >> ~/.pypirc
echo -e "password = ${{ secrets.TESTPYPI_TOKEN }}" >> ~/.pypirc

- name: Publish to Test PyPI
if: github.event_name == 'release'
run: |
twine upload --skip-existing -r testpypi dist/*

- name: Publish to PyPI
if: github.event_name == 'release'
run: |
twine upload -r pypi dist/*