Upload Python Package #7
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will upload a Python Package to PyPI when a release is created | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries | |
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
name: Upload Python Package | |
on: | |
release: | |
types: [published] | |
workflow_dispatch: | |
inputs: | |
target-repo: | |
description: 'Target repository (pypi or testpypi)' | |
required: true | |
default: 'testpypi' | |
permissions: | |
contents: read | |
jobs: | |
build_sdist: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repo | |
uses: actions/checkout@v4 | |
- name: Install Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.x" | |
- name: Build source distribution | |
run: | | |
pip install build | |
python -m build --sdist | |
- uses: actions/upload-artifact@v4 | |
with: | |
path: dist/*.tar.gz | |
build_wheels: | |
strategy: | |
matrix: | |
os: [ubuntu-latest, macos-14] | |
python-version: ["3.9", "3.10", "3.11", "3.12"] | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Build wheels | |
uses: pypa/[email protected] | |
env: | |
CIBW_BUILD: cp${{ matrix.python-version }} | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dist-${{ matrix.os }}-${{ matrix.python-version }} | |
path: ./wheelhouse/*.whl | |
pypi-publish: | |
runs-on: ubuntu-latest | |
needs: | |
- build_sdist | |
- build_wheels | |
permissions: | |
# IMPORTANT: this permission is mandatory for trusted publishing | |
id-token: write | |
# Dedicated environments with protections for publishing are strongly recommended. | |
# For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules | |
environment: | |
name: ${{ github.event.inputs.target-repo == 'pypi' && 'pypi' || 'testpypi' }} | |
# OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status: | |
# url: https://pypi.org/p/YOURPROJECT | |
# | |
# ALTERNATIVE: if your GitHub Release name is the PyPI project version string | |
# ALTERNATIVE: exactly, uncomment the following line instead: | |
# url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }} | |
url: ${{ github.event.inputs.target-repo == 'pypi' && 'https://pypi.org/project/mattersim/' || 'https://test.pypi.org/project/mattersim/' }}${{ github.event.release.name }} | |
steps: | |
- name: Retrieve release distributions | |
uses: actions/download-artifact@v4 | |
with: | |
name: dist-* | |
merge-multiple: true | |
path: dist | |
- name: Publish release distributions to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
verbose: true | |
skip-existing: true | |
packages-dir: dist/ | |
password: ${{ github.event.inputs.target-repo == 'pypi' && secrets.PYPI_TOKEN || secrets.TEST_PYPI_TOKEN }} | |
repository-url: ${{ github.event.inputs.target-repo == 'pypi' && 'https://upload.pypi.org/legacy/' || 'https://test.pypi.org/legacy/' }} |