Skip to content

Commit

Permalink
update ci to build sdist and to build wheels on multiple platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghan234 committed Dec 4, 2024
1 parent b693716 commit de3d5f1
Showing 1 changed file with 49 additions and 20 deletions.
69 changes: 49 additions & 20 deletions .github/workflows/python-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,65 +11,94 @@ 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:
release-build:
build_sdist:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check out repo
uses: actions/checkout@v4

- uses: actions/setup-python@v5
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Build release distributions
- name: Build source distribution
run: |
# NOTE: put your own distribution build steps here.
python -m pip install build cibuildwheel
cibuildwheel --output-dir dist/
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/cibuildwheel@v2.16.5
env:
CIBW_BUILD: cp${{ matrix.python-version }}

- name: Upload distributions
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: release-dists
path: dist/
name: dist-${{ matrix.os }}-${{ matrix.python-version }}
path: ./wheelhouse/*.whl

pypi-publish:
runs-on: ubuntu-latest
needs:
- release-build
- 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: pypi
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: https://pypi.org/project/mattersim/${{ 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: release-dists
path: dist/
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: ${{ secrets.PYPI_TOKEN }}
repository-url: https://upload.pypi.org/legacy/
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/' }}

0 comments on commit de3d5f1

Please sign in to comment.