Skip to content
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

Add GitHub Actions workflow for publishing to PyPI #196

Merged
merged 13 commits into from
Jul 28, 2020
Merged

Conversation

leouieda
Copy link
Member

Use a separate workflow that doesn't run on pull requests. Builds the
archives/wheels and pushes to test PyPI on pushes to the master branch
and to PyPI proper on releases.

Reminders:

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst and the base __init__.py file for the package.
  • Write detailed docstrings for all functions/classes/methods. It often helps to design better code if you write the docstrings first.
  • If adding new functionality, add an example to the docstring, gallery, and/or tutorials.
  • Add your full name, affiliation, and ORCID (optional) to the AUTHORS.md file (if you haven't already) in case you'd like to be listed as an author on the Zenodo archive of the next release.

@leouieda leouieda changed the title WIP Add GitHub Actions workflow for publishing to PyPI Add GitHub Actions workflow for publishing to PyPI Jul 27, 2020
@leouieda leouieda requested review from dopplershift and hugovk July 27, 2020 17:00
@leouieda
Copy link
Member Author

leouieda commented Jul 27, 2020

@hugovk @dopplershift I implemented a workflow similar to what Hugo suggested in #195.

I set it up as a separate workflow since it's only really critical when we make a release and it would be hard to have a broken release if the master branch is passing all tests (unless the PyPI upload itself is broken, which would be caught by the test pypi upload). Does this seem sensible? I struggled with this decision quite a bit.

The test releases seem to be working: https://test.pypi.org/project/pooch/#history

I enabled the deploy on this branch to test PyPI for now but will remove it before merging.

run: twine check dist/*

- name: Publish to Test PyPI
if: success()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if: success() is the default.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏽 I thought so but just wanted to be safe

- name: Publish to PyPI
# Only publish to PyPI when a release triggers the build
if: success() && github.event_name == 'release'
uses: pypa/gh-action-pypi-publish@bce3b74dbf8cc32833ffba9d15f83425c1a736e0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that's paranoid...and not a bad idea.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆 yeah that blog post linked in that comment made my skin crawl

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which blog post?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leouieda
Copy link
Member Author

leouieda commented Jul 27, 2020

TODO:

  • Remove this branch from the deploy script
  • Remove PyPI deploy from TravisCI config

name: PyPI
runs-on: ubuntu-latest
# Only publish from the origin repository, not forks
if: github.repository == 'fatiando/pooch'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, you could rely on the fact that secrets.PYPI_TOKEN is only available on the original repo. If someone else put their own token as a secret on their fork, it would only work if it had permission on pypi.org. Just thinking out loud...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but that would mean that the workflow runs and raises an error for most contributors when they update their forks. I get really bothered by those red crosses...

@dopplershift
Copy link
Contributor

In general this makes sense, but it's also the kind of things I never get right the first time. So hopefully the pushes to test.pypi.org work...

@leouieda leouieda changed the title Add GitHub Actions workflow for publishing to PyPI WIP Add GitHub Actions workflow for publishing to PyPI Jul 27, 2020
@leouieda
Copy link
Member Author

🤞🏽 but it seems to work for test.pypi.org so far. I guess we might have to merge this and see. But if it works on test.pypi it should work on pypi, right? Why would something like this ever break unexpectedly?

ls -lh dist/

- name: Check the archives
run: twine check dist/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right. But then again, they also that we should be running this. Might just leave it since it takes a few seconds only.

@hugovk
Copy link
Member

hugovk commented Jul 27, 2020

I set it up as a separate workflow since it's only really critical when we make a release and it would be hard to have a broken release if the master branch is passing all tests (unless the PyPI upload itself is broken, which would be caught by the test pypi upload). Does this seem sensible? I struggled with this decision quite a bit.

Yep, sounds sensible.

I have separate workflows for lint, test, and deploy. It also means if, say, there's some temporary network error which stops deploy, you can restart just the deploy workflow.

@leouieda
Copy link
Member Author

@hugovk thanks for the comments!

I have separate workflows for lint, test, and deploy.

Thanks for sharing that link to your tinytext project! It really cleared up some things for me.

It also means if, say, there's some temporary network error which stops deploy, you can restart just the deploy workflow.

That's what I figured. Plus, I'm super paranoid with the CI on master so the release should be safe (famous last words).

@leouieda leouieda changed the title WIP Add GitHub Actions workflow for publishing to PyPI Add GitHub Actions workflow for publishing to PyPI Jul 28, 2020
@leouieda
Copy link
Member Author

Alright fingers crossed that this actually works 🤞🏽

@leouieda leouieda merged commit 2d27854 into master Jul 28, 2020
@leouieda leouieda deleted the deploy-pypi branch July 28, 2020 13:35
@leouieda
Copy link
Member Author

It works! https://test.pypi.org/project/pooch/#history

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants