Skip to content

build

build #1108

Workflow file for this run

name: build
on:
push:
tags:
- v*
branches:
- master
pull_request:
branches:
- master
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }}
cancel-in-progress: true
env:
STABLE_PYTHON_VERSION: "3.12"
HATCH_VERBOSE: 1
CIBW_BUILD_FRONTEND: build
jobs:
build-sdist:
name: Build source distribution
if: github.event_name == 'push' || ! github.event.pull_request.draft
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
with:
# Fetch all tags
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5
with:
python-version: ${{ env.STABLE_PYTHON_VERSION }}
cache: pip
- name: Install hatch
run: pip install --upgrade hatch
- name: Create source distribution
run: |
hatch build --target sdist
- name: Upload sdist
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4
with:
name: wheels-sdist
path: ./dist/*.tar.*
if-no-files-found: error
compression-level: 0
build-x86_64:
name: Build wheels on ${{ matrix.os }} (x86, 64-bit)
if: github.event_name == 'push' || ! github.event.pull_request.draft
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
archs: x86_64
- os: macos-latest
archs: x86_64
- os: windows-latest
archs: AMD64
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
with:
# Fetch all tags
fetch-depth: 0
- name: Cache pip packages
uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4
with:
path: ~/.cache/pip
key: ${{ github.workflow }}-pip-${{ runner.os }}-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ github.workflow }}-pip-${{ runner.os }}
${{ github.workflow }}-pip
${{ github.workflow }}
- name: Filter targets
id: cibw-filter
shell: bash
# Building all wheels on PRs is too slow, so we filter them to target
# the latest stable version of Python.
run: |
if [[ "${{ github.event_name}}" == "pull_request" ]] ; then
echo "build=cp${STABLE_PYTHON_VERSION/./}-*" >> "$GITHUB_OUTPUT"
else
echo "build=cp${STABLE_PYTHON_VERSION/./}-*" >> "$GITHUB_OUTPUT"
fi
- name: Create wheels
uses: pypa/cibuildwheel@ce3fb7832089eb3e723a0a99cab7f3eaccf074fd # v2.16.5
env:
CIBW_ARCHS: ${{ matrix.archs }}
CIBW_BUILD: ${{ steps.cibw-filter.outputs.build }}
- name: Upload wheels
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4
with:
name: wheels-${{ matrix.os }}-${{ matrix.archs }}
path: ./wheelhouse/*.whl
if-no-files-found: error
compression-level: 0
build-arm64:
name: Build wheels on ${{ matrix.os }} (arm64)
# As this requires emulation, it's not worth running on PRs
if: >-
github.event_name == 'push' &&
startsWith(github.event.ref, 'refs/tags')
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
archs: aarch64
- os: macos-latest
archs: arm64
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
with:
# Fetch all tags
fetch-depth: 0
# - name: Cache pip packages
# uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4
# with:
# path: ~/.cache/pip
# key: ${{ github.workflow }}-pip-${{ runner.os }}-${{ hashFiles('**/pyproject.toml') }}
# restore-keys: |
# ${{ github.workflow }}-pip-${{ runner.os }}
# ${{ github.workflow }}-pip
# ${{ github.workflow }}
# - name: Set up QEMU
# if: matrix.os == 'ubuntu-latest'
# uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3
# with:
# platforms: arm64
# - name: Create wheels
# uses: pypa/cibuildwheel@ce3fb7832089eb3e723a0a99cab7f3eaccf074fd # v2.16.5
# env:
# CIBW_ARCHS: ${{ matrix.archs }}
# - name: Upload wheels
# uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4
# with:
# name: wheels-${{ matrix.os }}-${{ matrix.archs }}
# path: ./wheelhouse/*.whl
# if-no-files-found: error
# compression-level: 0
check:
name: Check wheels
runs-on: ubuntu-latest
needs:
- build-x86_64
- build-arm64
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- name: Setup Python
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5
with:
python-version: ${{ env.STABLE_PYTHON_VERSION }}
cache: pip
- uses: actions/download-artifact@87c55149d96e628cc2ef7e6fc2aab372015aec85 # v4
with:
path: wheels
merge-multiple: true
- run: |
pipx run twine check --strict wheels/*
publish:
name: Publish wheels and sdist
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')
runs-on: ubuntu-latest
environment: pypi
needs:
- check
- build-sdist
permissions:
# Required for trusted publishing
id-token: write
contents: write
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
with:
fetch-depth: 0
- uses: actions/download-artifact@87c55149d96e628cc2ef7e6fc2aab372015aec85 # v4
with:
path: wheels
merge-multiple: true
- name: Setup Python
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5
with:
python-version: ${{ env.STABLE_PYTHON_VERSION }}
- name: Update changelog
id: changelog
run: |
pip install --upgrade commitizen
cz changelog \
--incremental \
--template .github/CHANGELOG.md.j2 \
--dry-run \
| tail -n+2 \
> ${{ runner.temp }}/changelog
echo -e "\n\n## Pull Requests\n\n" >> ${{ runner.temp }}/changelog
cz changelog \
--incremental \
--template .github/CHANGELOG.md.j2
- name: Generate release
id: release
uses: softprops/action-gh-release@v1
with:
files: wheels/*
body_path: ${{ runner.temp }}/changelog
draft: false
prerelease: false
generate_release_notes: true
# - name: Push build artifacts to PyPI
# uses: pypa/gh-action-pypi-publish@e53eb8b103ffcb59469888563dc324e3c8ba6f06 # v1.8.12
# with:
# skip-existing: true
# password: ${{ secrets.PYPI_TOKEN }}
# packages-dir: wheels
- name: Create PR for changelog update
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GH_TOKEN }}
commit-message: "chore: update changelog ${{ github.ref_name }}"
title: "chore: update changelog"
body: |
This PR updates the changelog for ${{ github.ref_name }}.
branch: chore/update-changelog
base: master