GitHub action for releasing the packages of a python uv workspace monorepo.
The action releases the components in dependency order. For each component it:
- Runs python-semantic-release to determine the release version, update the version metadata and changelog, and build the distributions. The release commit and tag are pushed.
- Publishes the distributions of the component to PyPI with
uv publish. - Raises the version requirements of the workspace packages depending on the
released component, runs
uv lock, and commits and pushes the changes (build(deps): require <component> >=<version> in dependents).
Components without releasable changes are skipped. Container image builds and other repository-specific steps should remain in the calling repository.
- Python Semantic Release is configured for each component in its
pyproject.toml. Itsbuild_commandmust place the distributions in thedistdirectory of the component, e.g.uv build --out-dir dist. - The raised requirements are committed as
build(deps). For the dependents to be released by them, configure the commit parser to treatbuildas a patch tag, e.g.patch_tags = ["fix", "perf", "build"]in[tool.semantic_release.commit_parser_options]. Use a monorepo-aware parser such asconventional-monorepoto release a component only for changes in its own directory. - A
uv.lockexists at the repository root. - Each component directory has a
pyproject.tomlwith a[project].name. - The workflow checks out the full Git history and has
contents: writeandid-token: writepermissions. The latter is required for PyPI trusted publishing; configure the GitHub repository as a PyPI publisher. - Release runs must not be concurrent, e.g. use a
concurrencygroup.
name: Release
on:
workflow_dispatch:
concurrency:
group: release
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- uses: nlsfi/python-monorepo-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}By default (components: auto) all components are released ordered so that
the dependencies of a component are released before it. The dependencies are
read from [project].dependencies, [project.optional-dependencies] and
[dependency-groups] of the components. A dependency cycle is an error.
To release only some components, or in a custom order, list them one per line:
- uses: nlsfi/python-monorepo-release-action@v1
with:
components: |
lib
db
github_token: ${{ secrets.GITHUB_TOKEN }}| Name | Required | Default | Description |
|---|---|---|---|
components |
no | auto |
Component directory names, one per line, or auto to order all by dependencies |
components_dir |
no | components |
Directory containing the component directories |
github_token |
yes | Token used to push release commits and tags | |
check_url |
no | https://pypi.org/simple/ |
PEP 691 index URL used to detect unpublished releases and skip uploaded files |
dry_run |
no | false |
Build and validate without committing, tagging, pushing, or publishing |
| Name | Description |
|---|---|
released |
"true" if any component was or would be released |
releases |
JSON object mapping released component names to their versions |
Every step is derived from the repository and index state, not only from what the current run released, so a run that failed halfway is completed by running it again. For each component the action also:
- publishes the latest release tag if its version is missing from
check_url. The distributions are built from the tag withuv build --out-dir dist; - raises the requirements of the dependents to the latest released version if their lower bound is below it. Without a new release, requirements that already have a lower bound at or above the latest release, or none at all, are never changed.
Already uploaded files are skipped with uv publish --check-url. A component
without releases is skipped, and a rerun with nothing to do changes nothing.
The index must support the PEP 700 versions field, as PyPI does.
With dry_run: true nothing is committed, tagged, pushed or published. The
version metadata is still updated in the temporary runner workspace and the
configured build command is run, followed by uv publish --dry-run. Dependent
requirements are updated and uv lock is run, but the changes are not
committed. The workspace is reset after each component, so a dry run should
only be run on a disposable checkout such as a CI runner.
When a component is released, requirements matching its normalized package name
in [project].dependencies and [project.optional-dependencies] are updated.
Extras and environment markers are preserved. The new lower bound is the
released version; the upper bound is the next major version, or the next minor
version for 0.x releases. All changed dependents and uv.lock are committed
together, so the dependents' own release configuration can detect the change.
The scripts in src/monorepo_release can also be used directly:
python -m monorepo_release.release <auto|components> [--components-dir <dir>] [--dry-run]
python -m monorepo_release.bump_dependents <component> <version> [--components-dir <dir>]bump_dependents updates the dependents and prints their directory names, one
per line.
uv sync
uv run prek install
uv run pytestThe tests include an end-to-end test (test/test_release_e2e.py) that releases
a fixture workspace with real git, uv and python-semantic-release against a
local bare repository, with only the PyPI upload mocked. It needs network access
to build the fixture packages. The CI action-dry-run job runs the action itself
with dry_run: true on the same fixture (test/fixture_workspace.py).