Publish to PyPI #1
Workflow file for this run
This file contains hidden or 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
name: Publish to PyPI | |
on: | |
release: | |
types: [published] | |
workflow_dispatch: | |
inputs: | |
test_pypi: | |
description: 'Publish to Test PyPI instead of PyPI' | |
required: false | |
default: false | |
type: boolean | |
jobs: | |
build-wheels: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
include: | |
# macOS wheels (universal for both Intel + Apple Silicon) | |
- os: macos-latest | |
python-version: "3.11" | |
platform: apple | |
wheel-tag: macosx_10_9_universal2 | |
- os: macos-latest | |
python-version: "3.12" | |
platform: apple | |
wheel-tag: macosx_10_9_universal2 | |
# Linux CUDA wheels | |
- os: ubuntu-latest | |
python-version: "3.11" | |
platform: cuda | |
wheel-tag: linux_x86_64 | |
- os: ubuntu-latest | |
python-version: "3.12" | |
platform: cuda | |
wheel-tag: linux_x86_64 | |
# Linux ROCm wheels | |
- os: ubuntu-latest | |
python-version: "3.11" | |
platform: rocm | |
wheel-tag: linux_x86_64 | |
- os: ubuntu-latest | |
python-version: "3.12" | |
platform: rocm | |
wheel-tag: linux_x86_64 | |
# Linux CPU wheels | |
- os: ubuntu-latest | |
python-version: "3.11" | |
platform: cpu | |
wheel-tag: linux_x86_64 | |
- os: ubuntu-latest | |
python-version: "3.12" | |
platform: cpu | |
wheel-tag: linux_x86_64 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install build dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install build wheel setuptools | |
- name: Build wheel | |
run: | | |
python -m build --wheel | |
env: | |
SIMPLETUNER_PLATFORM: ${{ matrix.platform }} | |
- name: Rename wheel with platform suffix | |
run: | | |
cd dist | |
for wheel in *.whl; do | |
# Extract base name without .whl | |
base=$(basename "$wheel" .whl) | |
# Add platform suffix before .whl | |
mv "$wheel" "${base}+${{ matrix.platform }}.whl" | |
done | |
shell: bash | |
- name: Upload wheel artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: wheels-${{ matrix.platform }}-py${{ matrix.python-version }} | |
path: dist/*.whl | |
build-sdist: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.11" | |
- name: Install build dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install build | |
- name: Build source distribution | |
run: python -m build --sdist | |
- name: Upload sdist artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: sdist | |
path: dist/*.tar.gz | |
publish: | |
needs: [build-wheels, build-sdist] | |
runs-on: ubuntu-latest | |
environment: release | |
permissions: | |
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing | |
steps: | |
- name: Download all artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
path: dist/ | |
merge-multiple: true | |
- name: List artifacts | |
run: ls -la dist/ | |
- name: Publish to Test PyPI | |
if: ${{ github.event.inputs.test_pypi == 'true' }} | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
repository-url: https://test.pypi.org/legacy/ | |
skip-existing: true | |
- name: Publish to PyPI | |
if: ${{ github.event.inputs.test_pypi != 'true' }} | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
skip-existing: true |