Skip to content
Open
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
90 changes: 90 additions & 0 deletions .github/workflows/publish-to-test-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Publish Python 🐍 distribution 📦 to PyPI

on: push

jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10.12"
- name: Install specific setuptools and pip
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor suggestion (feel free to ignore): Caching would greatly help with build times here. See: https://github.com/buildingamind/NewbornEmbodiedTuringTest/blob/bf29953ab909ae216eb67a06fb9dbda281b9def1/.github/workflows/docs.yml#L27C6-L42C47

Copy link
Collaborator

Choose a reason for hiding this comment

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

For bonus points, building this once and then using it for both docs.yml and publish-to-test.yml would be nice and efficient.

run: |
python -m pip install setuptools==65.5.0 pip==21
- name: Install pypa/build
run: |
python3 -m pip install build --user
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does this change from python to python3? Seems inconsistent

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree, let's make it python3

- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
Copy link
Collaborator

Choose a reason for hiding this comment

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

So this is triggered by pushing a new tag? Does this mean we still need to push a new tag?
Should this not be triggered by a push to main instead? And then we can grab the version from src/nett/_version.py.

This is how I would imagine it:

  1. Check if this is a PR to main AND that the version found in src/nett/_version.py is not an existing release (denoted as v{version num}): If both are true, run the build to confirm it is buildable.
  2. If this is being pushed to main (from merging the PR): Start the publication process, resulting in it being tagged and published to pypi.

The particular if statement solution for seeing if it is being pushed to main or is just a PR for main can be found in the docs workflow, see https://github.com/buildingamind/NewbornEmbodiedTuringTest/blob/bf29953ab909ae216eb67a06fb9dbda281b9def1/.github/workflows/docs.yml#L3C1-L11C12

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To be honest I don't have an opinion, I'm fine if we do this either way, but if what you have is already how docs work, it would make all the sense to have consistency between the two workflows.

needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/nett-benchmarkse
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo:

Suggested change
url: https://pypi.org/p/nett-benchmarkse
url: https://pypi.org/p/nett-benchmarks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, thanks

permissions:
id-token: write

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
needs:
- publish-to-pypi
runs-on: ubuntu-latest

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/gh-action-sigstore-python@v2.1.1
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'