From c5539e2ae7d99d8ef93fd4a13fe160f70e78cb98 Mon Sep 17 00:00:00 2001 From: Aaron Miller Date: Fri, 3 Jan 2025 10:23:34 -0800 Subject: [PATCH] Publish automatically to PyPI Use the pypa-blessed github action to publish built wheels automatically to PyPI: https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ Just following the instructions there, with modifications to handle our three different packages. This setup is much nicer in combination with automatic versioning; on each push to main we publish a dev release to TestPYPI, and when a tag is pushed (which will tell setuptools_scm that the symforce version should be that tag), wheels are published to PyPI. Topic: sf-auto-publish Relative: sf-auto-version --- .github/workflows/build_wheels.yml | 58 ++++++++++++++++++++++++++++++ docs/development.rst | 10 +++--- 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 0d07c638..9b6c7642 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -115,3 +115,61 @@ jobs: with: name: symforce-wheels delete-merged: true + + publish-to-pypi: + name: Publish Python 🐍 distribution 📦 to PyPI + strategy: + matrix: + package: [symforce, symforce_sym, skymarshal] + if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes + needs: + - merge-wheel-artifacts + runs-on: ubuntu-latest + + environment: + name: pypi + url: https://pypi.org/p/${{ matrix.package }} + + permissions: + id-token: write + + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: symforce-wheels + path: wheels-download/ + - run: mkdir dist && cp wheels-download/${{ matrix.package }}-*.whl dist/ + - name: Publish distribution 📦 to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + verbose: true + + publish-to-testpypi: + name: Publish Python 🐍 distribution 📦 to TestPyPI + strategy: + matrix: + package: [symforce, symforce_sym, skymarshal] + needs: + - merge-wheel-artifacts + runs-on: ubuntu-latest + + environment: + name: testpypi + url: https://test.pypi.org/p/${{ matrix.package }} + + permissions: + id-token: write + + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: symforce-wheels + path: wheels-download/ + - run: mkdir dist && cp wheels-download/${{ matrix.package }}-*.whl dist/ + - name: Publish distribution 📦 to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + verbose: true \ No newline at end of file diff --git a/docs/development.rst b/docs/development.rst index 777c3473..697b1ce1 100644 --- a/docs/development.rst +++ b/docs/development.rst @@ -99,6 +99,10 @@ To set the symbolic API, you can either use :func:`symforce.set_symbolic_api()` Building wheels ************************************************* +Wheels are built automatically for pushes to the main branch, by the ``build_wheels`` GitHub +Actions workflow. Previous runs of this workflow will have the built wheels available as an +artifact. The workflow can also be run manually on a branch. + You should be able to build Python wheels of symforce the standard ways. We recommend using ``build``, i.e. running ``python3 -m build --wheel`` from the ``symforce`` directory. By default, this will build a wheel that includes local dependencies on the ``skymarshal`` and ``symforce-sym`` @@ -107,12 +111,6 @@ typically want to set the environment variable ``SYMFORCE_REWRITE_LOCAL_DEPENDEN release version when building, and also run ``python3 -m build --wheel third_party/skymarshal`` and ``python3 -m build --wheel gen/python`` to build wheels for those packages separately. -For SymForce releases, all of this is handled by the ``build_wheels`` GitHub Actions workflow. This -workflow is currently run manually on a commit, and produces a ``symforce-wheels.zip`` artifact with -wheels (and sdists) for distribution (e.g. on PyPI). It doesn't upload them to PyPI - to do that -(after verifying that the built wheels work as expected) you should download and unzip the archive, -and upload to PyPI with ``python -m twine upload [--repository testpypi] --verbose *``. - ************************************************* Adding new types *************************************************