Skip to content

Commit

Permalink
ci: release automation (#356)
Browse files Browse the repository at this point in the history
- Configures `release-plz` for changelog generation and publishing the
rust crate.
- `tket2` currently has version `0.0.0`, so it won't get auto-published
(also, the secret tokens are not present yet).
- Configures `release-please` for changelog generation of the python
package.
- Adds a CI job for building and publishing python wheels.
  - Generated by `maturin generate-ci`
  
Items 1. and 2. are mostly copied from hugr.

The main difference comes from configuring the changelog format directly
in `release-plz.toml` instead of including a noisy `cliff.toml`, as
recommended by release-plz in its newer versions.

Closes #354. Closes #229.

---------

Co-authored-by: Alec Edgington <[email protected]>
  • Loading branch information
aborgna-q and cqc-alec authored May 23, 2024
1 parent a7f3909 commit 3c9a101
Show file tree
Hide file tree
Showing 8 changed files with 322 additions and 5 deletions.
142 changes: 142 additions & 0 deletions .github/workflows/python-wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# This file is based on the version
# autogenerated by maturin v1.5.1
#
# To recreate it, run:
#
# maturin generate-ci github > .github/workflows/python-wheels.yml
#
# And edit the `on:` action triggers and the filters in `jobs.release.if`.
name: CI

on:
push:
branches:
- main
release:
types:
- published
workflow_dispatch:

permissions:
contents: read

jobs:
linux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
- runner: ubuntu-latest
target: armv7
- runner: ubuntu-latest
target: s390x
- runner: ubuntu-latest
target: ppc64le
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.platform.target }}
path: dist

windows:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: windows-latest
target: x64
- runner: windows-latest
target: x86
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
architecture: ${{ matrix.platform.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-windows-${{ matrix.platform.target }}
path: dist

macos:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: macos-latest
target: x86_64
- runner: macos-14
target: aarch64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.platform.target }}
path: dist

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

release:
name: Release
runs-on: ubuntu-latest
if: |
${{ (github.event_name == 'release' && github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/tket2-py-v'))}} ||
${{ (github.event_name == 'workflow_dispatch' && github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/tket2-py-v'))}} ||
needs: [linux, windows, macos, sdist]
steps:
- uses: actions/download-artifact@v4
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_PUBLISH }}
with:
command: upload
args: --non-interactive --skip-existing wheels-*/*
23 changes: 23 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Automatic changelog and version bumping with release-please for python projects
name: Release-please 🐍

on:
workflow_dispatch: {}
push:
branches:
- main

permissions:
contents: write
pull-requests: write

jobs:
release-please:
name: Create release PR
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v4
with:
# Using a personal access token so releases created by this workflow can trigger the deployment workflow
token: ${{ secrets.RELEASE_PLEASE_PAT }}
config-file: release-please-config.json
28 changes: 28 additions & 0 deletions .github/workflows/release-plz.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Automatic changelog, version bumping, and semver-checks with release-plz for rust projects
name: Release-plz 🦀

permissions:
pull-requests: write
contents: write

on:
push:
branches:
- main

jobs:
release-plz:
name: Release-plz
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Run release-plz
uses: MarcoIeni/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Build artifacts
/target
tket2-py/target/
/dist

# Python caches
__pycache__
Expand Down
3 changes: 3 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"tket2-py": "0.0.0"
}
39 changes: 34 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@
name = "tket2-py"
version = "0.0.0-alpha.1"
description = "pytket extension for the tket 2 compiler"
classifiers = [] # TODO
authors = [] # TODO
maintainers = [] # TODO
classifiers = [
"Environment :: Console",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"License :: OSI Approved :: Apache Software License",
"Operating System :: MacOS :: MacOS X",
"Operating System :: POSIX :: Linux",
"Operating System :: Microsoft :: Windows",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering",
]
authors = ["TKET development team <[email protected]>"]
maintainers = ["TKET development team <[email protected]>"]
include = ["pyproject.toml"]
license = "Apache-2.0"
readme = "README.md"
Expand All @@ -31,10 +43,27 @@ build-backend = "maturin"

[project]
name = "tket2"
classifiers = [
"Environment :: Console",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"License :: OSI Approved :: Apache Software License",
"Operating System :: MacOS :: MacOS X",
"Operating System :: POSIX :: Linux",
"Operating System :: Microsoft :: Windows",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering",
]
authors = [
{ name = "TKET development team", email = "[email protected]" },
]
maintainers = [
{ name = "TKET development team", email = "[email protected]" },
]
version = "0.0.0-alpha.1"
description = "pytket extension for the tket 2 compiler"
authors = [] # TODO
classifiers = [] # TODO
requires-python = ">=3.10"
license = { file = "LICENCE" }

Expand Down
65 changes: 65 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
"include-component-in-tag": true,
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": true,
"initial-version": "0.0.0",
"packages": {
"tket2-py": {
"release-type": "python",
"component": "tket2-py",
"package-name": "tket2",
"include-component-in-tag": true,
"draft": false,
"prerelease": false,
"draft-pull-request": true
}
},
"changelog-sections": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "perf",
"section": "Performance Improvements"
},
{
"type": "revert",
"section": "Reverts"
},
{
"type": "docs",
"section": "Documentation"
},
{
"type": "style",
"section": "Styling",
"hidden": true
},
{
"type": "chore",
"section": "Miscellaneous Chores",
"hidden": true
},
{
"type": "refactor",
"section": "Code Refactoring",
"hidden": true
},
{
"type": "test",
"section": "Tests",
"hidden": true
},
{
"type": "ci",
"section": "Continuous Integration",
"hidden": true
}
]
}
26 changes: 26 additions & 0 deletions release-plz.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Automatic changelog generation for rust projects

[workspace]
# Open the release PR as a draft
pr_draft = true

# Enforce adding the project name in the git tag, to avoid collisions with python.
# (This would normally only be enabled once there are multiple packages in the workspace)
git_tag_name = "{{ package }}-v{{ version }}"
git_release_name = "{{ package }}: v{{ version }}"

[changelog]
sort_commits = "oldest"

commit_parsers = [
{ message = "^feat", group = "New Features" },
{ message = "^fix", group = "Bug Fixes" },
{ message = "^docs", group = "Documentation" },
{ message = "^style", group = "Styling" },
{ message = "^refactor", group = "Refactor" },
{ message = "^perf", group = "Performance" },
{ message = "^test", group = "Testing" },
{ message = "^chore", group = "Miscellaneous Tasks", skip = true },
{ message = "^revert", group = "Reverted changes", skip = true },
{ message = "^ci", group = "CI", skip = true },
]

0 comments on commit 3c9a101

Please sign in to comment.