Publish Python packages #152
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
name: Publish Python packages | |
on: | |
push: | |
tags: | |
- v* | |
workflow_dispatch: | |
jobs: | |
check-version: | |
name: Check the tag corresponds to the crate version | |
runs-on: ubuntu-20.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Check Cargo.toml version vs Git tag | |
if: ${{ github.event_name == 'push' }} | |
working-directory: ./light-curve | |
run: | | |
cargo read-manifest | jq -r '.version' > /tmp/.crate_version | |
echo '${{ github.ref_name }}' | sed 's/^v//' > /tmp/.tag | |
diff /tmp/.crate_version /tmp/.tag | |
cibuildwheel: | |
name: Build ${{ matrix.platform }} ${{ matrix.arch }} ${{ matrix.abi3 && 'ABI3 ' || '' }}${{ matrix.interpreter }} | |
runs-on: ${{ matrix.os }} | |
needs: check-version | |
defaults: | |
run: | |
working-directory: ./light-curve | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-20.04, macos-12, windows-2019] | |
arch: [aarch64, ppc64le, x86_64, amd64] # amd64 is Windows-only | |
interpreter: [cp37, cp38, cp39, cp310, cp311, pp37, pp38, pp39] | |
platform: [manylinux, musllinux, macosx, win] | |
abi3: [false, true] | |
exclude: | |
# Build Linux on Linux | |
- os: macos-12 | |
platform: manylinux | |
- os: macos-12 | |
platform: musllinux | |
- os: windows-2019 | |
platform: manylinux | |
- os: windows-2019 | |
platform: musllinux | |
# Build macOS on macOS | |
- os: ubuntu-20.04 | |
platform: macosx | |
- os: windows-2019 | |
platform: macosx | |
# Build Windows on Windows | |
- os: ubuntu-20.04 | |
platform: win | |
- os: macos-12 | |
platform: win | |
# PyPy doesn't support musllinux | |
- interpreter: pp37 | |
platform: musllinux | |
- interpreter: pp38 | |
platform: musllinux | |
- interpreter: pp39 | |
platform: musllinux | |
# PyPy doesn't support PPC64le | |
- arch: ppc64le | |
interpreter: pp37 | |
- arch: ppc64le | |
interpreter: pp38 | |
- arch: ppc64le | |
interpreter: pp39 | |
# There is no Rust toolchain for PPC64le with MUSL | |
- arch: ppc64le | |
platform: musllinux | |
# x86_64 is the only supported architecture for macOS | |
- os: macos-12 | |
arch: aarch64 | |
- os: macos-12 | |
arch: ppc64le | |
# amd64 is Windows-only | |
- os: ubuntu-20.04 | |
arch: amd64 | |
- os: macos-12 | |
arch: amd64 | |
# We only support amd64 on Windows | |
- os: windows-2019 | |
arch: aarch64 | |
- os: windows-2019 | |
arch: ppc64le | |
- os: windows-2019 | |
arch: x86_64 | |
# We need a single interpreter for ABI, so we use py311 only | |
- abi3: true | |
interpreter: cp37 | |
- abi3: true | |
interpreter: cp38 | |
- abi3: true | |
interpreter: cp39 | |
- abi3: true | |
interpreter: cp310 | |
- abi3: true | |
interpreter: pp37 | |
- abi3: true | |
interpreter: pp38 | |
- abi3: true | |
interpreter: pp39 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up QEMU on Linux | |
if: ${{ matrix.os == 'ubuntu-20.04' }} | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: all | |
- name: Set up Rust toolchain on Windows | |
uses: dtolnay/rust-toolchain@master | |
if: ${{ matrix.os == 'windows-2019' }} | |
with: | |
toolchain: stable | |
targets: x86_64-pc-windows-msvc | |
# We only support AMD64 architecture for Windows, so we hard-code it here. | |
- name: Set CIBW envs on Windows | |
if: ${{ matrix.os == 'windows-2019' }} | |
run: | | |
"CIBW_BUILD=${{ matrix.interpreter }}-${{ matrix.platform }}_${{ matrix.arch }}" >> $env:GITHUB_ENV | |
"CIBW_ARCHS=AMD64" >> $env:GITHUB_ENV | |
- name: Set CIBW envs on Linux or macOS | |
if: ${{ matrix.os != 'windows-2019' }} | |
run: | | |
echo "CIBW_BUILD=${{ matrix.interpreter }}-${{ matrix.platform }}_${{ matrix.arch }}" >> $GITHUB_ENV | |
echo "CIBW_ARCHS=${{ matrix.arch }}" >> $GITHUB_ENV | |
- name: Patch pyproject.toml for ABI3 build | |
if: ${{ matrix.abi3 }} | |
run: | | |
python3 -m pip install tomlkit | |
python3 -c " | |
import tomlkit | |
def update_pyproject(data): | |
for key, value in data.items(): | |
if key == 'config-settings': | |
value['build-args'] += ',abi3' | |
continue | |
if isinstance(value, tomlkit.items.Table): | |
update_pyproject(value) | |
if isinstance(value, (tomlkit.items.Array, tomlkit.items.AoT)): | |
for item in value: | |
if isinstance(item, tomlkit.items.Table): | |
update_pyproject(item) | |
with open('pyproject.toml', 'r') as f: | |
pyproject = tomlkit.load(f) | |
print(pyproject) | |
update_pyproject(pyproject) | |
with open('pyproject.toml', 'w') as f: | |
tomlkit.dump(pyproject, f) | |
" | |
- name: Build wheels | |
uses: pypa/cibuildwheel@v2.16.5 | |
with: | |
package-dir: ./light-curve | |
env: | |
CIBW_BUILD_VERBOSITY: "3" | |
- name: Upload wheels as artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
path: ./wheelhouse/*.whl | |
if-no-files-found: error | |
name: artifact_${{ matrix.os }}-${{ matrix.arch }}-$${{ matrix.interpreter }}-${{ matrix.platform }}-${{ matrix.abi3 }} | |
sdist: | |
name: Build source distribution | |
runs-on: ubuntu-20.04 | |
defaults: | |
run: | |
working-directory: ./light-curve | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.x' | |
- name: Install maturin | |
run: pip install 'maturin>=1.0,<2.0' | |
- name: Build sdist | |
run: maturin sdist | |
- name: Upload sdist as an artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
path: ./light-curve/target/wheels/*.tar.gz | |
if-no-files-found: error | |
name: artifact_sdist | |
publish: | |
needs: [cibuildwheel, sdist] | |
name: Publish light-curve | |
runs-on: ubuntu-20.04 | |
steps: | |
- uses: actions/download-artifact@v4 | |
with: | |
pattern: artifact_* | |
merge-multiple: true | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.x' | |
- name: Install twine | |
run: pip install twine | |
- name: Publish light-curve | |
working-directory: artifact | |
run: twine upload *whl *tar.gz -u __token__ -p ${{ secrets.PYPI_TOKEN_LIGHT_CURVE }} --verbose | |
publish-light-curve-python: | |
needs: publish | |
name: Publish light-curve-python | |
runs-on: ubuntu-20.04 | |
defaults: | |
run: | |
working-directory: light-curve-python | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.x' | |
- name: Install deps | |
run: python3 -mpip install toml twine | |
- name: Publish light-curve-python | |
run: | | |
python3 setup.py sdist | |
twine check --strict dist/* | |
twine upload dist/* -u __token__ -p ${{ secrets.PYPI_TOKEN_LIGHT_CURVE_PYTHON }} --verbose |