Skip to content

Commit

Permalink
Better release action (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
audy authored Feb 20, 2025
1 parent e2919fd commit 7b1ad2d
Showing 1 changed file with 114 additions and 89 deletions.
203 changes: 114 additions & 89 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,108 +1,133 @@
---
name: Build Wheels on Release
# This file is autogenerated by maturin v1.8.2
# To update, run
#
# maturin generate-ci github
#
name: build wheels

on:
push:
branches:
- main
- master
tags:
- "*"
pull_request:
workflow_dispatch:
release:
types: [published]

jobs:
build-wheels:
runs-on: ${{ matrix.runner }}
linux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
include:
# macos - ARM
- os: macos-latest
architecture: arm64
runner: macos-14 # m1
python-version: "3.12"
- os: macos-latest
architecture: arm64
runner: macos-14 # m1
python-version: "3.11"
# macos - x86
- os: macos-latest
architecture: x64
runner: macos-13 # x86
python-version: "3.12"
- os: macos-latest
architecture: x64
runner: macos-13 # x86
python-version: "3.11"
# ubuntu - x86
- os: ubuntu-latest
architecture: x64
runner: ubuntu-latest
python-version: "3.11"
- os: ubuntu-latest
architecture: x64
runner: ubuntu-latest
python-version: "3.12"
fail-fast: false

platform:
- runner: ubuntu-22.04
target: x86_64
python-version:
- "3.11"
- "3.12"
steps:
- name: Checkout
uses: actions/checkout@master

- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
profile: minimal
toolchain: stable
override: true

# Setup Python for the selected version
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
target: ${{ matrix.platform.target }}
args: --release --out dist --interpreter python-${{ matrix.python-version }}
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.architecture }}
name: wheels-linux-${{ matrix.platform.target }}-${{ matrix.python-version }}
path: dist

# Install Rust toolchain
- uses: actions-rs/toolchain@v1
macos:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: macos-13
target: x86_64
- runner: macos-14
target: aarch64
python-version:
- "3.11"
- "3.12"
steps:
- uses: actions/checkout@v4
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
profile: minimal
toolchain: stable
override: true
target: ${{ matrix.platform.target }}
args: --release --out dist --interpreter python-${{ matrix.python-version }}
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.platform.target }}-${{ matrix.python-version }}
path: dist

- name: Install maturin
run: |
python -m venv venv
. venv/bin/activate
pip install maturin
pip show maturin
sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: wheels-sdist
path: dist

- name: Add library to venv
run: |
. venv/bin/activate
maturin develop --features=python
upload-release:
name: Upload release artifacts to GitHub
needs: [linux, macos, sdist]
runs-on: ubuntu-latest
if: github.event.release.tag_name
steps:
- name: Download wheel artifacts
uses: actions/download-artifact@v4

- name: Build wheels
id: build_wheels
run: |
. venv/bin/activate
maturin build --features=python --release --strip --manylinux=off
- name: List downloaded wheels
run: ls -l wheels-*/*

- name: Upload wheel artifact
uses: actions/upload-artifact@v3
- name: Upload Wheels to Release
uses: svenstaro/upload-release-action@v2
with:
name: wheel-${{ matrix.os }}-py${{ matrix.python-version }}
path: target/wheels/*.whl
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: wheels-*/**
tag: ${{ github.event.release.tag_name }}
file_glob: true

upload-release:
needs: [build-wheels]
runs-on: ubuntu-latest
steps:
- name: Download wheel artifacts
uses: actions/download-artifact@v3
with:
path: ./wheels

- name: List downloaded wheels
run: ls -l wheels/*
release:
name: Release to PyPI
runs-on: ubuntu-latest
if: github.event.release.tag_name
needs: [linux, macos, sdist]
permissions:
# Use to sign the release artifacts
id-token: write
# Used to upload release artifacts
contents: write
# Used to generate artifact attestation
attestations: write
steps:
- uses: actions/download-artifact@v4
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-path: "wheels-*/**"

- name: Upload Wheels to Release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: wheels/**/*.whl
tag: ${{ github.event.release.tag_name }}
file_glob: true
- name: Publish to PyPI
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing wheels-*/**

0 comments on commit 7b1ad2d

Please sign in to comment.