From f00c35969f25284bac575098a547436e1bc76acb Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 29 Sep 2025 10:13:33 +0000 Subject: [PATCH] feat: Add GitHub Action to publish to PyPI This commit introduces a new GitHub Actions workflow to automate the publishing of the package to the Python Package Index (PyPI). The workflow is defined in `.github/workflows/publish-to-pypi.yml` and is triggered on every push to a tag matching the 'v*' pattern. Key features of the workflow: - It builds the source distribution (sdist) and binary wheels for multiple Python versions (3.9, 3.10, 3.11, 3.12). - The build process is split into separate jobs for sdist and wheels to improve efficiency. - Artifacts are used to pass the built distributions to the publish job. - The `pypa/gh-action-pypi-publish` action is used to upload the packages to PyPI, authenticating with the `PYPI_API_TOKEN` secret. --- .github/workflows/publish-to-pypi.yml | 84 +++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 .github/workflows/publish-to-pypi.yml diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml new file mode 100644 index 0000000..3becd84 --- /dev/null +++ b/.github/workflows/publish-to-pypi.yml @@ -0,0 +1,84 @@ +name: Publish Python package to PyPI + +on: + push: + tags: + - 'v*' + +jobs: + build_sdist: + name: Build source distribution + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.9" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + + - name: Build sdist + run: python -m build --sdist + + - name: Upload sdist artifact + uses: actions/upload-artifact@v3 + with: + name: sdist-artifact + path: dist/ + + build_wheels: + name: Build wheels on ${{ matrix.os }} for Python ${{ matrix.python-version }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + python-version: ["3.9", "3.10", "3.11", "3.12"] + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + + - name: Build wheels + run: python -m build --wheel + + - name: Upload wheel artifact + uses: actions/upload-artifact@v3 + with: + name: wheel-artifact-${{ matrix.os }}-${{ matrix.python-version }} + path: dist/ + + publish: + name: Publish package to PyPI + needs: [build_sdist, build_wheels] + runs-on: ubuntu-latest + steps: + - name: Download all build artifacts + uses: actions/download-artifact@v3 + with: + path: artifacts + + - name: Combine artifacts and list + run: | + mkdir dist + shopt -s globstar + mv artifacts/**/*.whl artifacts/**/*.tar.gz dist/ + ls -R dist + + - name: Publish package to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} \ No newline at end of file