diff --git a/.changeset/README.md b/.changeset/README.md index 43c4e92a4..936a5d457 100644 --- a/.changeset/README.md +++ b/.changeset/README.md @@ -1,66 +1,26 @@ # Changesets -Add a changeset to any PR that should be released. Create a markdown file in -this directory (any name, e.g. `fix-token-parsing.md`): +Add a changeset to any PR that changes a published package. Create a markdown +file in this directory (any name, for example `fix-token-parsing.md`), or run +`verwalter changeset`: ```md --- "livekit-api": patch --- -Short description of the change, used in the release notes. +Short description of the change, for the user of the package. ``` -List one line per package the change should release: +- **Packages:** `livekit` (the code in `livekit-rtc/`), `livekit-api`, `livekit-protocol`. One line per package. +- **Levels:** `patch` for a fix, `minor` for an addition, `major` for a break. -- **Packages:** `livekit-rtc`, `livekit-api`, `livekit-protocol` -- **Types:** +Do not add the PR number: the release adds it. When several pending changesets +name the same package, the largest level wins. A change to `livekit-protocol` +also releases `livekit-api` as a patch, with no changeset for it. - | Type | Example | - |---|---| - | `patch` | 1.5.1 → 1.5.2 | - | `minor` | 1.5.1 → 1.6.0 | - | `major` | 1.5.1 → 2.0.0 | - | `patch-rc` | 1.5.1 → 1.5.2.rc1 | - | `minor-rc` | 1.5.1 → 1.6.0.rc1 | - | `major-rc` | 1.5.1 → 2.0.0.rc1 | - | `next-rc` | 1.6.0.rc1 → 1.6.0.rc2 | - | `promote` | 1.6.0.rc2 → 1.6.0 | +A PR that needs no release (docs, CI, tests) gets the `internal` label. -When several pending changesets touch the same package, the largest bump wins. -Mixing stable and rc types for one package, or combining `promote` with -anything else, is rejected. Only rc types are allowed on branches other than -`main`. - -While a package is at an rc (e.g. `1.6.0.rc1`), only `next-rc` and `promote` -are accepted for it, so fixes land in the next rc and the planned `1.6.0` still -ships. Any other type would skip it (`patch` would release `1.6.1`). To move -to a different version line, use the Manual Version Bump workflow below. - -## How releases happen - -1. Every PR is checked by the **Changeset** workflow; invalid changesets fail - the check. -2. On each push to `main`, **Package Release** applies all pending changesets - and opens (or updates) the `Release: ...` PR with the version bumps and - release notes, then deletes the changesets it used. Changesets used by an - rc release are kept instead (and recorded in `.changeset/pre.json`) until - that package's next stable release, normally `promote`, whose release notes - then list every change since the last stable version. -3. Merging that release PR tags each bumped package, publishes it to PyPI and - creates its GitHub Release. - -Changes that don't need a release (docs, CI, tests) don't need a changeset. - -## Manual version bump - -As a fallback, run the **Manual Version Bump** workflow with a package and -bump type. It opens a `release/-v` PR without reading any -changeset; merging it publishes the same way as a changeset release PR. -It doesn't touch `.changeset/`, so changesets kept from rc releases stay until -that package's next changeset stable release. - -The two flows don't know about each other: a manual bump doesn't close an open -`Release: ...` changeset PR for the same package (or the other way round), and -both change that package's version, so once one merges the other conflicts. -Close the stale one before merging. +Pre-releases (`1.6.0rc1`) are not a changeset level: run the Pre-release PR +workflow. For a major rc of `livekit-protocol`, also add a `patch` changeset for +`livekit-api`. See [RELEASING.md](../RELEASING.md). diff --git a/.github/changesets.py b/.github/changesets.py deleted file mode 100644 index a4722fdd4..000000000 --- a/.github/changesets.py +++ /dev/null @@ -1,294 +0,0 @@ -"""Consume pending .changeset/*.md files and bump package versions. - -A changeset looks like: - - --- - "livekit-rtc": patch - "livekit-api": minor-rc - --- - - Summary of the change. - -Supported bump types: patch, minor, major, patch-rc, minor-rc, major-rc, -next-rc, promote. When several changesets touch the same package, the -largest bump wins (an explicit X-rc wins over next-rc). Mixing stable and -rc bumps, or combining promote with anything else, is an error. While a -package is at an rc, only next-rc and promote are accepted for it. - -Changesets used by an rc release are kept and recorded in .changeset/pre.json -(package -> file names) instead of being deleted, so later runs skip them. The -package's next stable release (normally promote) lists them in its release -notes and deletes them. -""" - -from __future__ import annotations - -import json -import os -import pathlib -import re -import subprocess - -import click -from packaging.version import Version -from update_versions import PACKAGES, do_bump, do_prerelease, read_version - -CHANGESET_DIR = pathlib.Path(".changeset") -# Changesets already released in an rc, kept until the package's stable release -PRE_STATE = CHANGESET_DIR / "pre.json" - -# Names accepted in changeset frontmatter -> key in PACKAGES -PACKAGE_ALIASES = { - "livekit": "livekit", - "livekit-rtc": "livekit", - "livekit-api": "livekit-api", - "livekit-protocol": "livekit-protocol", -} - -STABLE = {"patch": 1, "minor": 2, "major": 3} -RC = {"patch-rc": 1, "minor-rc": 2, "major-rc": 3} -BUMP_TYPES = set(STABLE) | set(RC) | {"next-rc", "promote"} - - -def parse_changeset(path: pathlib.Path) -> tuple[dict[str, str], str]: - m = re.match(r"^---\s*\n(.*?)\n?---\s*\n?(.*)$", path.read_text(), re.DOTALL) - if not m: - raise click.ClickException(f"{path}: missing '---' frontmatter") - - bumps: dict[str, str] = {} - for line in m.group(1).splitlines(): - line = line.strip() - if not line or line.startswith("#"): - continue - lm = re.fullmatch(r'[\'"]?([\w.\-]+)[\'"]?\s*:\s*[\'"]?([\w\-]+)[\'"]?', line) - if not lm: - raise click.ClickException(f"{path}: cannot parse line {line!r}") - name, kind = lm.groups() - if name not in PACKAGE_ALIASES: - raise click.ClickException( - f"{path}: unknown package {name!r} (expected one of {sorted(PACKAGE_ALIASES)})" - ) - if kind not in BUMP_TYPES: - raise click.ClickException( - f"{path}: unknown bump type {kind!r} (expected one of {sorted(BUMP_TYPES)})" - ) - bumps[PACKAGE_ALIASES[name]] = kind - return bumps, m.group(2).strip() - - -def resolve(package: str, kinds: set[str]) -> str: - if "promote" in kinds: - if len(kinds) > 1: - raise click.ClickException( - f"{package}: 'promote' cannot be combined with {sorted(kinds - {'promote'})}" - ) - return "promote" - - stable = kinds & STABLE.keys() - if stable and kinds - stable: - raise click.ClickException(f"{package}: cannot mix stable and rc bumps ({sorted(kinds)})") - if stable: - return max(stable, key=STABLE.__getitem__) - - explicit_rc = kinds & RC.keys() - if explicit_rc: - return max(explicit_rc, key=RC.__getitem__) - return "next-rc" - - -def validate(package: str, kind: str) -> None: - cur = Version(read_version(pathlib.Path(PACKAGES[package]))) - if kind == "next-rc" and not (cur.pre and cur.pre[0] == "rc"): - raise click.ClickException(f"{package}: next-rc requires an rc version (got {cur})") - if kind == "promote" and not cur.is_prerelease: - raise click.ClickException(f"{package}: promote requires a pre-release (got {cur})") - # Any other bump would move past the rc's planned stable version, e.g. - # patch on 1.4.0.rc1 releases 1.4.1 and 1.4.0 never ships. - if cur.is_prerelease and kind not in ("next-rc", "promote"): - raise click.ClickException( - f"{package}: {kind} is not allowed while at pre-release {cur}; " - "use next-rc or promote (or the Manual Version Bump workflow)" - ) - - -def apply(package: str, kind: str) -> None: - if kind in STABLE: - do_bump(package, kind) - elif kind in RC: - do_bump(package, kind.removesuffix("-rc")) - do_prerelease(package, "rc") - elif kind == "next-rc": - do_prerelease(package, "rc") - elif kind == "promote": - do_bump(package, "release") - - -def changeset_origin(path: pathlib.Path, repo: str | None) -> str: - """Return " (#123 by @user)" for the PR that added this changeset, or "".""" - if not repo: - return "" - try: - sha = subprocess.run( - ["git", "log", "--diff-filter=A", "--format=%H", "-1", "--", str(path)], - capture_output=True, - text=True, - check=True, - ).stdout.strip() - if not sha: - return "" - pr = subprocess.run( - [ - "gh", - "api", - f"repos/{repo}/commits/{sha}/pulls", - "--jq", - '.[0] // empty | "\\(.number) \\(.user.login)"', - ], - capture_output=True, - text=True, - check=True, - ).stdout.split() - except (OSError, subprocess.CalledProcessError) as e: - click.echo(f"warning: cannot resolve PR for {path}: {e}", err=True) - return "" - if len(pr) == 2: - return f" (#{pr[0]} by @{pr[1]})" - return f" ({sha[:7]})" - - -def kept_entries(names: list[str], package: str, repo: str | None) -> list[str]: - """Release-note entries for this package from changesets kept since its rc releases.""" - entries = [] - for name in names: - path = CHANGESET_DIR / name - bumps, summary = parse_changeset(path) - if summary and package in bumps: - entries.append(f"`{bumps[package]}` {summary}{changeset_origin(path, repo)}") - return entries - - -@click.command() -@click.option( - "--rc-only", - is_flag=True, - default=False, - help="Reject stable bumps (used for non-main branches).", -) -@click.option( - "--notes", - type=click.Path(dir_okay=False, path_type=pathlib.Path), - default=None, - help="Write release notes (markdown) to this file.", -) -@click.option( - "--repo", - envvar="GITHUB_REPOSITORY", - default=None, - help="owner/name used to look up the PR and author of each changeset (needs gh).", -) -@click.option( - "--check", - is_flag=True, - default=False, - help="Only validate the pending changesets; don't change any file.", -) -def main(rc_only: bool, notes: pathlib.Path | None, repo: str | None, check: bool) -> None: - pre: dict[str, list[str]] = json.loads(PRE_STATE.read_text()) if PRE_STATE.exists() else {} - kept = {name for names in pre.values() for name in names} - # A kept changeset still owes its entry to the stable release notes. - missing = sorted(name for name in kept if not (CHANGESET_DIR / name).exists()) - if missing: - raise click.ClickException( - f"changesets kept from rc releases are missing: {missing} " - f"(restore them, or remove them from {PRE_STATE} on purpose)" - ) - # Parse them now too, so a broken kept changeset fails the PR check - # instead of the stable release. - for name in sorted(kept): - parse_changeset(CHANGESET_DIR / name) - files = sorted( - p - for p in CHANGESET_DIR.glob("*.md") - if p.name.lower() != "readme.md" and p.name not in kept - ) - - kinds: dict[str, set[str]] = {} - summaries: dict[str, list[str]] = {} - packages_of: dict[str, set[str]] = {} - for path in files: - bumps, summary = parse_changeset(path) - packages_of[path.name] = set(bumps) - if summary and not check: - summary += changeset_origin(path, repo) - for package, kind in bumps.items(): - kinds.setdefault(package, set()).add(kind) - if summary: - # Each entry shows the bump type its changeset asked for. - summaries.setdefault(package, []).append(f"`{kind}` {summary}") - - resolved = {package: resolve(package, k) for package, k in kinds.items()} - if rc_only: - stable = {p: k for p, k in resolved.items() if k in STABLE or k == "promote"} - if stable: - raise click.ClickException( - f"only rc releases are allowed from non-main branches (got {stable})" - ) - # Validate everything before touching any version file. - for package, kind in resolved.items(): - validate(package, kind) - - if check: - click.echo(f"{len(files)} changeset(s) valid ({len(kept)} kept from rc releases).") - for package in PACKAGES: - if package in resolved: - cur = read_version(pathlib.Path(PACKAGES[package])) - click.echo(f" {package}: {cur} ({resolved[package]})") - return - - lines: list[str] = [] - released: list[str] = [] - for package in PACKAGES: # stable order - if package not in resolved: - continue - kind = resolved[package] - apply(package, kind) - version = read_version(pathlib.Path(PACKAGES[package])) - released.append(f"{package} v{version}") - lines.append(f"## {package} v{version} ({kind})\n") - entries = summaries.get(package, []) - if kind in RC or kind == "next-rc": - # Keep this rc's changesets for the stable release notes. - pre.setdefault(package, []).extend( - p.name for p in files if package in packages_of[p.name] - ) - else: - # A stable release (normally promote) also lists the changesets - # kept since this package's rc releases. - entries = kept_entries(pre.pop(package, []), package, repo) + entries - for summary in entries: - lines.append("- " + summary.replace("\n", "\n ")) - lines.append("") - - # Changesets are consumed once applied (including ones listing no package), - # except those still kept for a package's stable release. - still_kept = {name for names in pre.values() for name in names} - for name in {p.name for p in files} | kept: - if name not in still_kept: - (CHANGESET_DIR / name).unlink(missing_ok=True) - if pre: - PRE_STATE.write_text(json.dumps(pre, indent=2, sort_keys=True) + "\n") - else: - PRE_STATE.unlink(missing_ok=True) - - if notes is not None: - notes.write_text("\n".join(lines)) - - title = ", ".join(released) - print(f"Release: {title or '(nothing to release)'}") - if gh_output := os.environ.get("GITHUB_OUTPUT"): - with open(gh_output, "a") as f: - f.write(f"title={title}\n") - - -if __name__ == "__main__": - main() diff --git a/.github/update_versions.py b/.github/update_versions.py deleted file mode 100644 index 691fd8a54..000000000 --- a/.github/update_versions.py +++ /dev/null @@ -1,149 +0,0 @@ -import pathlib -import re -import click -from packaging.version import Version - -PACKAGES = { - "livekit": "livekit-rtc/livekit/rtc/version.py", - "livekit-api": "livekit-api/livekit/api/version.py", - "livekit-protocol": "livekit-protocol/livekit/protocol/version.py", -} - -TAG_PREFIXES = { - "livekit": "rtc", - "livekit-api": "api", - "livekit-protocol": "protocol", -} - - -def _esc(*codes: int) -> str: - return "\033[" + ";".join(str(c) for c in codes) + "m" - - -def read_version(f: pathlib.Path) -> str: - text = f.read_text() - m = re.search(r'__version__\s*=\s*[\'"]([^\'"]+)[\'"]', text) - if not m: - raise ValueError(f"could not find __version__ in {f}") - return m.group(1) - - -def write_new_version(f: pathlib.Path, new_version: str) -> None: - text = f.read_text() - new_text = re.sub( - r'__version__\s*=\s*[\'"][^\'"]*[\'"]', - f'__version__ = "{new_version}"', - text, - count=1, - ) - f.write_text(new_text) - - -def bump_version(cur: str, bump_type: str) -> str: - v = Version(cur) - if bump_type == "release": - return v.base_version - if bump_type == "patch": - return f"{v.major}.{v.minor}.{v.micro + 1}" - if bump_type == "minor": - return f"{v.major}.{v.minor + 1}.0" - if bump_type == "major": - return f"{v.major + 1}.0.0" - raise ValueError(f"unknown bump type: {bump_type}") - - -def bump_prerelease(cur: str, bump_type: str) -> str: - v = Version(cur) - base = v.base_version - if bump_type == "rc": - if v.pre and v.pre[0] == "rc": - next_rc = v.pre[1] + 1 - else: - next_rc = 1 - return f"{base}.rc{next_rc}" - raise ValueError(f"unknown prerelease bump type: {bump_type}") - - -def update_api_protocol_dependency(new_protocol_version: str) -> None: - """Update livekit-api's dependency on livekit-protocol.""" - pyproject = pathlib.Path("livekit-api/pyproject.toml") - if not pyproject.exists(): - return - old_text = pyproject.read_text() - new_text = re.sub( - r'"livekit-protocol>=[\w.\-]+,', - f'"livekit-protocol>={new_protocol_version},', - old_text, - ) - if new_text != old_text: - pyproject.write_text(new_text) - print(f"Updated livekit-api dependency on livekit-protocol to >={new_protocol_version}") - - -def do_bump(package: str, bump_type: str) -> None: - version_path = PACKAGES[package] - vf = pathlib.Path(version_path) - cur = read_version(vf) - new = bump_version(cur, bump_type) - print(f"{package}: {_esc(31)}{cur}{_esc(0)} -> {_esc(32)}{new}{_esc(0)}") - write_new_version(vf, new) - - if package == "livekit-protocol": - update_api_protocol_dependency(new) - - -def do_prerelease(package: str, prerelease_type: str) -> None: - version_path = PACKAGES[package] - vf = pathlib.Path(version_path) - cur = read_version(vf) - new = bump_prerelease(cur, prerelease_type) - print(f"{package}: {_esc(31)}{cur}{_esc(0)} -> {_esc(32)}{new}{_esc(0)}") - write_new_version(vf, new) - - if package == "livekit-protocol": - update_api_protocol_dependency(new) - - -@click.command() -@click.option( - "--package", - type=click.Choice(list(PACKAGES.keys())), - required=True, - help="Package to bump.", -) -@click.option( - "--pre", - type=click.Choice(["rc", "none"]), - default="none", - help="Pre-release type.", -) -@click.option( - "--bump-type", - type=click.Choice(["patch", "minor", "major", "release"]), - default="patch", - help="Type of version bump.", -) -@click.option( - "--print-version", - is_flag=True, - default=False, - help="Print current version and tag prefix, don't bump.", -) -def bump(package: str, pre: str, bump_type: str, print_version: bool) -> None: - if print_version: - vf = pathlib.Path(PACKAGES[package]) - version = read_version(vf) - tag_prefix = TAG_PREFIXES[package] - # Output as key=value for easy parsing - print(f"version={version}") - print(f"tag_prefix={tag_prefix}") - return - - if pre == "none": - do_bump(package, bump_type) - else: - do_prerelease(package, pre) - - -if __name__ == "__main__": - bump() diff --git a/.github/workflows/build-api.yml b/.github/workflows/build-api.yml index 6a0aa3c31..cccbb94e3 100644 --- a/.github/workflows/build-api.yml +++ b/.github/workflows/build-api.yml @@ -6,8 +6,6 @@ on: - main paths: - livekit-api/** - tags: - - "api-v*.*.*" pull_request: branches: - main @@ -43,27 +41,3 @@ jobs: path: | livekit-api/dist/*.whl livekit-api/dist/*.tar.gz - - publish: - name: Publish API release - needs: build_wheels - runs-on: ubuntu-latest - environment: pypi - permissions: - id-token: write - if: startsWith(github.ref, 'refs/tags/api-v') && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false) - steps: - - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 - with: - name: api-release - path: dist - - - uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 - - docs: - needs: [publish] - uses: ./.github/workflows/build-docs.yml - with: - package_dir: "livekit-api" - package_name: "livekit.api" - secrets: inherit diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml index e988444c5..d57d03752 100644 --- a/.github/workflows/build-docs.yml +++ b/.github/workflows/build-docs.yml @@ -21,6 +21,11 @@ on: package_name: required: true type: string + ref: + description: The commit to document. Empty is the commit of the calling run. + required: false + type: string + default: "" secrets: PYPI_API_TOKEN: required: true @@ -39,6 +44,7 @@ jobs: steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 with: + ref: ${{ inputs.ref || github.sha }} submodules: recursive - name: Install Package to Document diff --git a/.github/workflows/build-protocol.yml b/.github/workflows/build-protocol.yml index ae82ad7e2..e541e7fa4 100644 --- a/.github/workflows/build-protocol.yml +++ b/.github/workflows/build-protocol.yml @@ -6,8 +6,6 @@ on: - main paths: - livekit-protocol/** - tags: - - "protocol-v*.*.*" pull_request: branches: - main @@ -84,27 +82,3 @@ jobs: path: | livekit-protocol/dist/*.whl livekit-protocol/dist/*.tar.gz - - publish: - name: Publish Protocol release - needs: build_wheels - runs-on: ubuntu-latest - environment: pypi - permissions: - id-token: write - if: startsWith(github.ref, 'refs/tags/protocol-v') && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false) - steps: - - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 - with: - name: protocol-release - path: dist - - - uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 - - docs: - needs: [publish] - uses: ./.github/workflows/build-docs.yml - with: - package_dir: "livekit-protocol" - package_name: "livekit.protocol" - secrets: inherit diff --git a/.github/workflows/build-rtc.yml b/.github/workflows/build-rtc.yml index 3eebae58d..744714c73 100644 --- a/.github/workflows/build-rtc.yml +++ b/.github/workflows/build-rtc.yml @@ -6,8 +6,6 @@ on: - main paths: - livekit-rtc/** - tags: - - "rtc-v*.*.*" pull_request: branches: - main @@ -195,28 +193,3 @@ jobs: LIVEKIT_URL: ${{ secrets.LIVEKIT_URL }} LIVEKIT_API_KEY: ${{ secrets.LIVEKIT_API_KEY }} LIVEKIT_API_SECRET: ${{ secrets.LIVEKIT_API_SECRET }} - - publish: - name: Publish RTC release - needs: [build_wheels, make_sdist, test] - runs-on: ubuntu-latest - environment: pypi - permissions: - id-token: write - if: startsWith(github.ref, 'refs/tags/rtc-v') && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false) - steps: - - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 - with: - pattern: rtc-release-* - path: dist - merge-multiple: true - - - uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 - - docs: - needs: [publish] - uses: ./.github/workflows/build-docs.yml - with: - package_dir: "livekit-rtc" - package_name: "livekit.rtc" - secrets: inherit diff --git a/.github/workflows/changeset-check.yml b/.github/workflows/changeset-check.yml new file mode 100644 index 000000000..683c842f0 --- /dev/null +++ b/.github/workflows/changeset-check.yml @@ -0,0 +1,31 @@ +# Fails a contributor PR that changes a versioned package without a +# changeset, with a comment that links to a prefilled changeset file. +# The `internal` label (config: [check] exempt_label) skips the check. +# On the release PR, it runs the `[check].publish_dry_run` command of each +# package that the merge releases (build and `twine check`), and fails the +# PR when one fails, before the version reaches main. +name: Changeset check + +on: + pull_request: + types: [opened, synchronize, reopened, labeled, unlabeled] + branches: [main] + +permissions: + contents: read + pull-requests: write + +jobs: + check: + # renovate/* PRs are dependency/security updates and never carry changesets + if: "!startsWith(github.event.pull_request.head.ref, 'renovate/')" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 + with: + fetch-depth: 0 # the dry run reads the tags to find what the release PR releases + submodules: true # the sdist of each package includes its submodule + - uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1 + - uses: livekit/verwalter@14fef9bf275fb347702b083d573e4a1f09bf0ef4 # v0.32.0-rc.2 + with: + command: check diff --git a/.github/workflows/changeset-reminder.yml b/.github/workflows/changeset-reminder.yml deleted file mode 100644 index 508fea72f..000000000 --- a/.github/workflows/changeset-reminder.yml +++ /dev/null @@ -1,81 +0,0 @@ -name: Changeset Reminder - -# Comment once with a short format guide when a PR has no .changeset file, and -# delete that comment once one is added. -on: - # Needed for a write token on fork PRs. This workflow never checks out or - # runs PR code; it only reads the PR's file list through the API. - pull_request_target: - types: [opened, synchronize, reopened] - -permissions: - contents: read - -jobs: - remind: - name: Changeset reminder - if: | - !startsWith(github.event.pull_request.head.ref, 'release/changesets-') - && !startsWith(github.event.pull_request.head.ref, 'renovate/') - && !endsWith(github.event.pull_request.user.login, '[bot]') - runs-on: ubuntu-latest - permissions: - pull-requests: write - steps: - - name: Comment when the PR has no changeset - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR_NUMBER: ${{ github.event.pull_request.number }} - REPO: ${{ github.repository }} - run: | - marker="" - - files=$(gh api --paginate "repos/$REPO/pulls/$PR_NUMBER/files" \ - --jq '.[] | "\(.status) \(.filename)"') - - # Dependency-only updates (lockfiles / package.json, and the root - # pyproject.toml, which is the unpublished workspace config) don't need - # a changeset. Package pyproject.toml files declare published runtime - # dependencies, so changing them still gets the reminder. - if [ -z "$(grep -vE '^[a-z]+ ((.*/)?([^/]+\.lock|package\.json|pnpm-lock\.yaml)|pyproject\.toml)$' <<< "$files")" ]; then - echo "Only dependency files changed, skipping" - exit 0 - fi - - changesets=$(grep -v '^removed ' <<< "$files" | cut -d' ' -f2- \ - | grep -E '^\.changeset/[^/]+\.md$' | grep -viE '/readme\.md$' || true) - existing=$(gh api --paginate "repos/$REPO/issues/$PR_NUMBER/comments" \ - --jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | contains(\"$marker\"))) | .id") - - if [ -n "$changesets" ]; then - echo "Changeset found:"; echo "$changesets" - # Drop the reminder once a changeset has been added - for id in $existing; do - gh api -X DELETE "repos/$REPO/issues/comments/$id" - done - exit 0 - fi - - if [ -n "$existing" ]; then - echo "Reminder already posted" - exit 0 - fi - - cat > "$RUNNER_TEMP/reminder.md" <<'EOF' - - 👋 This PR has no changeset. If it should be released, add a markdown file under `.changeset/` (any name, e.g. `.changeset/fix-token-parsing.md`): - - ```md - --- - "livekit-rtc": patch - --- - - Short description of the change, used in the release notes. - ``` - - - **Packages:** `livekit-rtc`, `livekit-api`, `livekit-protocol` (one line per package) - - **Types:** `patch`, `minor`, `major`, `patch-rc`, `minor-rc`, `major-rc`, `next-rc`, `promote` - - If this change doesn't need a release (docs, CI, tests), you can ignore this comment. - EOF - gh pr comment "$PR_NUMBER" --repo "$REPO" --body-file "$RUNNER_TEMP/reminder.md" diff --git a/.github/workflows/changeset.yml b/.github/workflows/changeset.yml deleted file mode 100644 index b7eb99fa4..000000000 --- a/.github/workflows/changeset.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Changeset - -# Validate .changeset files on every commit of every PR, with the same rules -# the Package Release workflow applies when it bumps versions. The reminder for -# PRs without a changeset lives in changeset-reminder.yml; keeping it separate -# means this workflow never reports a skipped "Validate changesets" check that -# could satisfy a required status check. -on: - pull_request: - types: [opened, synchronize, reopened] - -permissions: - contents: read - -jobs: - validate: - name: Validate changesets - # renovate/* PRs are dependency/security updates and never carry changesets - if: "!startsWith(github.event.pull_request.head.ref, 'renovate/')" - runs-on: ubuntu-latest - steps: - # Default ref is the PR merge commit, i.e. the base branch's versions plus - # every changeset that would be pending once this PR merges. - - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 - - - name: Set up Python - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7 - with: - python-version: "3.10" - - - name: Install dependencies - run: pip install click packaging - - - name: Validate changesets - env: - BASE_BRANCH: ${{ github.base_ref }} - run: | - # Only RC releases are allowed from non-main branches - args=() - if [ "$BASE_BRANCH" != "main" ]; then - args+=(--rc-only) - fi - - if ! out=$(python .github/changesets.py --check "${args[@]}" 2>&1); then - echo "$out" - echo "::error title=Invalid changeset::${out#Error: }" - exit 1 - fi - echo "$out" diff --git a/.github/workflows/manual-version-bump.yml b/.github/workflows/manual-version-bump.yml deleted file mode 100644 index a68ed5404..000000000 --- a/.github/workflows/manual-version-bump.yml +++ /dev/null @@ -1,152 +0,0 @@ -name: Manual Version Bump - -# Fallback for the changeset flow: bump one package by hand and open a release -# PR. Merging that PR publishes through the Package Release workflow. -on: - workflow_dispatch: - inputs: - package: - description: "Package to publish" - type: choice - required: true - options: - - livekit - - livekit-api - - livekit-protocol - version: - description: "What to publish" - type: choice - required: true - options: - - "patch (1.5.1 → 1.5.2)" - - "minor (1.5.1 → 1.6.0)" - - "major (1.5.1 → 2.0.0)" - - "patch-rc (1.5.1 → 1.5.2.rc1)" - - "minor-rc (1.5.1 → 1.6.0.rc1)" - - "major-rc (1.5.1 → 2.0.0.rc1)" - - "next-rc (.rc1 → .rc2)" - - "promote (1.6.0.rc2 → 1.6.0)" - branch: - description: "Branch to publish from (default: main)" - type: string - required: false - default: "main" - -permissions: - contents: write - pull-requests: write - -jobs: - bump: - name: Create release PR - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 - with: - ref: ${{ inputs.branch }} - submodules: true - - - name: Guard non-main branches - env: - INPUT_VERSION: ${{ inputs.version }} - INPUT_BRANCH: ${{ inputs.branch }} - run: | - key=$(echo "$INPUT_VERSION" | awk '{print $1}') - if [ "$INPUT_BRANCH" != "main" ]; then - case "$key" in - *-rc|next-rc) ;; # allowed - *) echo "::error::Only RC releases are allowed from non-main branches (got '$key' on '$INPUT_BRANCH')"; exit 1 ;; - esac - fi - - - name: Set up Python - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7 - with: - python-version: "3.10" - - - name: Install dependencies - run: pip install click packaging - - - name: Bump version - env: - INPUT_VERSION: ${{ inputs.version }} - INPUT_PACKAGE: ${{ inputs.package }} - run: | - key=$(echo "$INPUT_VERSION" | awk '{print $1}') - pkg="$INPUT_PACKAGE" - - case "$key" in - patch|minor|major) - python .github/update_versions.py --package "$pkg" --bump-type "$key" - ;; - patch-rc|minor-rc|major-rc) - bump="${key%-rc}" - python .github/update_versions.py --package "$pkg" --bump-type "$bump" - python .github/update_versions.py --package "$pkg" --pre rc - ;; - next-rc) - python .github/update_versions.py --package "$pkg" --pre rc - ;; - promote) - python .github/update_versions.py --package "$pkg" --bump-type release - ;; - esac - - - name: Read new version - id: version - env: - INPUT_PACKAGE: ${{ inputs.package }} - run: | - eval "$(python .github/update_versions.py --package "$INPUT_PACKAGE" --print-version)" - echo "version=$version" >> "$GITHUB_OUTPUT" - echo "tag_prefix=$tag_prefix" >> "$GITHUB_OUTPUT" - echo "Package: $INPUT_PACKAGE, New version: $version, Tag: ${tag_prefix}-v${version}" - - - name: Close existing release PRs for this package - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - TAG_PREFIX: ${{ steps.version.outputs.tag_prefix }} - run: | - prefix="release/${TAG_PREFIX}-v" - gh pr list --state open --json number,headRefName \ - --jq ".[] | select(.headRefName | startswith(\"$prefix\")) | .number" | while read -r pr; do - echo "Superseding release PR #$pr" - gh pr comment "$pr" --body "Superseded by a new release." - gh pr close "$pr" --delete-branch || true - done - - - name: Create release PR - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - VERSION: ${{ steps.version.outputs.version }} - TAG_PREFIX: ${{ steps.version.outputs.tag_prefix }} - INPUT_BRANCH: ${{ inputs.branch }} - INPUT_PACKAGE: ${{ inputs.package }} - INPUT_VERSION: ${{ inputs.version }} - ACTOR: ${{ github.actor }} - run: | - branch="release/${TAG_PREFIX}-v${VERSION}" - key=$(echo "$INPUT_VERSION" | awk '{print $1}') - - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git checkout -b "$branch" - git add -A - git commit -m "${TAG_PREFIX}-v${VERSION}" - git push --force origin "$branch" - - # Same section format as the changeset release PR, so Package Release - # can take the GitHub release notes from it. - { - echo "Merging this PR will publish the following packages to PyPI:" - echo - echo "## ${INPUT_PACKAGE} v${VERSION} (${key})" - echo - echo "- Manual version bump by @${ACTOR}." - } > "$RUNNER_TEMP/pr-body.md" - - gh pr create \ - --base "$INPUT_BRANCH" \ - --head "$branch" \ - --title "${INPUT_PACKAGE} v${VERSION}" \ - --body-file "$RUNNER_TEMP/pr-body.md" diff --git a/.github/workflows/package-release.yml b/.github/workflows/package-release.yml index e728c4679..b2fc6a0cc 100644 --- a/.github/workflows/package-release.yml +++ b/.github/workflows/package-release.yml @@ -1,253 +1,84 @@ +# After a release PR merges: build every package, then tag and create the +# GitHub releases (drafts), then upload to PyPI and make the releases +# public. The step that cannot be undone comes last. name: Package Release on: - # Step 1: A push to main (e.g. a merged PR, including from forks) or a manual - # run consumes pending .changeset files and opens/updates the release PR with - # the version bumps. This runs on `push` rather than `pull_request` so it gets - # a write-capable token for fork contributions too. - push: - branches: [main] - + # No `branches` filter: an rc PR from pre-release.yml targets the branch + # the workflow was run on. The `gate` job decides which PRs release. + pull_request: + types: [closed] + # A failed job is re-run with "Re-run failed jobs" on the run itself: + # that keeps the merge commit. This trigger is for a run that needs a + # fixed workflow file from the branch. `verwalter release` resumes from + # the current state and skips what is done. workflow_dispatch: inputs: - branch: - description: "Branch to release from (default: main)" - type: string + ref: + description: Commit or tag to build and publish. Set it to the release tag when the tag exists. Empty is the branch head. required: false - default: "main" - - # Step 2: Merging the release PR triggers build + publish - pull_request: - types: [closed] + default: "" + package: + description: Only this package; always reported to the publish job. + required: false + default: "" -# Read-only by default; jobs that write ask for it themselves, so build jobs -# (which run third-party build code) never get a write or OIDC token. +# Read-only by default: build jobs run third-party build code and never get +# a write or OIDC token. permissions: contents: read jobs: - # ── Step 1: Create / update the release PR from changesets ──── - bump: - name: Create release PR - if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' + # Only a run by hand, or a merged release PR or rc PR that verwalter + # opened: the branch name alone would let any pushed `release/*` branch + # trigger a publish. The author is `[release].author` in verwalter.toml. + gate: runs-on: ubuntu-latest permissions: - contents: write - pull-requests: write - concurrency: - group: package-release-${{ inputs.branch || github.ref_name }} - cancel-in-progress: true - env: - BASE_BRANCH: ${{ inputs.branch || github.ref_name }} + contents: read + outputs: + release: ${{ steps.verwalter.outputs.release }} + sha: ${{ steps.commit.outputs.sha }} steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 with: - ref: ${{ env.BASE_BRANCH }} - # Full history to find the commit (and PR) that added each changeset + ref: ${{ github.event.pull_request.merge_commit_sha || inputs.ref || github.sha }} fetch-depth: 0 - - - name: Set up Python - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7 - with: - python-version: "3.10" - - - name: Install dependencies - run: pip install click packaging - - - name: Apply changesets - id: changesets + # Every later job checks out this commit. A branch name in `ref` + # resolves once, here, and cannot move between the jobs. + - id: commit + run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + # `verwalter gate` answers yes for every run by hand. The release + # gate (2 approvals) covers only PRs into main, so a run by hand + # releases only a commit that is on main. + - name: Guard the run by hand + if: github.event_name == 'workflow_dispatch' env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REF: ${{ github.ref }} + PACKAGE: ${{ inputs.package }} run: | - # Only RC releases are allowed from non-main branches - args=() - if [ "$BASE_BRANCH" != "main" ]; then - args+=(--rc-only) + case "$PACKAGE" in + ""|livekit|livekit-api|livekit-protocol) ;; + *) echo "::error::Unknown package '$PACKAGE'. Use livekit, livekit-api or livekit-protocol."; exit 1 ;; + esac + if [ "$REF" != "refs/heads/main" ]; then + echo "::error::Run this workflow from main, not $REF. Set the commit to release with the ref input." + exit 1 fi - python .github/changesets.py --notes "$RUNNER_TEMP/release-notes.md" "${args[@]}" - - - name: Create or update release PR - if: steps.changesets.outputs.title != '' - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - TITLE: ${{ steps.changesets.outputs.title }} - run: | - branch="release/changesets-${BASE_BRANCH//\//-}" - - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git checkout -b "$branch" - git add -A - git commit -m "Release: ${TITLE}" - git push --force origin "$branch" - - { - echo "Merging this PR will publish the following packages to PyPI:" - echo - cat "$RUNNER_TEMP/release-notes.md" - } > "$RUNNER_TEMP/pr-body.md" - - existing=$(gh pr list --state open --head "$branch" --base "$BASE_BRANCH" --json number --jq '.[0].number // empty') - if [ -n "$existing" ]; then - gh pr edit "$existing" --title "Release: ${TITLE}" --body-file "$RUNNER_TEMP/pr-body.md" - else - gh pr create \ - --base "$BASE_BRANCH" \ - --head "$branch" \ - --title "Release: ${TITLE}" \ - --body-file "$RUNNER_TEMP/pr-body.md" - fi - - # Pending changesets can disappear after the release PR was opened (e.g. - # reverted); merging that stale PR would still publish. - - name: Close stale release PR - if: steps.changesets.outputs.title == '' - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - branch="release/changesets-${BASE_BRANCH//\//-}" - existing=$(gh pr list --state open --head "$branch" --base "$BASE_BRANCH" --json number --jq '.[0].number // empty') - if [ -n "$existing" ]; then - gh pr comment "$existing" --body "Closing: no pending changesets left to release." - gh pr close "$existing" --delete-branch + if ! git merge-base --is-ancestor HEAD origin/main; then + echo "::error::$(git rev-parse HEAD) is not on main. Only a commit on main can be released by hand." + exit 1 fi - - # ── Step 2: Publish on merge ────────────────────────────────── - detect: - name: Detect packages - # Only release PRs opened by a bump job (same repo, github-actions[bot], - # release/* branch: release/changesets-* from this workflow or - # release/-v from Manual Version Bump) may trigger - # publishing; the branch name alone is not trusted. - if: | - github.event_name == 'pull_request' - && github.event.pull_request.merged == true - && startsWith(github.event.pull_request.head.ref, 'release/') - && github.event.pull_request.head.repo.full_name == github.repository - && github.event.pull_request.user.login == 'github-actions[bot]' - runs-on: ubuntu-latest - permissions: - contents: read - pull-requests: read - outputs: - rtc: ${{ steps.detect.outputs.rtc }} - api: ${{ steps.detect.outputs.api }} - protocol: ${{ steps.detect.outputs.protocol }} - tags: ${{ steps.detect.outputs.tags }} - steps: - - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 + - id: verwalter + uses: livekit/verwalter@14fef9bf275fb347702b083d573e4a1f09bf0ef4 # v0.32.0-rc.2 with: - ref: ${{ github.event.pull_request.merge_commit_sha }} + command: gate - - name: Set up Python - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7 - with: - python-version: "3.10" - - - name: Install dependencies - run: pip install click packaging - - - name: Detect bumped packages - id: detect - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR_NUMBER: ${{ github.event.pull_request.number }} - REPO: ${{ github.repository }} - run: | - # A package is released when the release PR changed its version.py - files=$(gh api --paginate "repos/$REPO/pulls/$PR_NUMBER/files" --jq '.[].filename') - - tags=() - for entry in "rtc:livekit:livekit-rtc/livekit/rtc/version.py" \ - "api:livekit-api:livekit-api/livekit/api/version.py" \ - "protocol:livekit-protocol:livekit-protocol/livekit/protocol/version.py"; do - IFS=: read -r key package path <<< "$entry" - if grep -qxF "$path" <<< "$files"; then - eval "$(python .github/update_versions.py --package "$package" --print-version)" - tags+=("${tag_prefix}-v${version}") - echo "$key=true" >> "$GITHUB_OUTPUT" - echo "Releasing $package v$version" - else - echo "$key=false" >> "$GITHUB_OUTPUT" - fi - done - - echo "tags=${tags[*]}" >> "$GITHUB_OUTPUT" - - tag: - name: Tag & create GitHub releases - needs: detect - if: needs.detect.outputs.tags != '' - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 - with: - ref: ${{ github.event.pull_request.merge_commit_sha }} - - - name: Create git tags - env: - TAGS: ${{ needs.detect.outputs.tags }} - run: | - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - for tag in $TAGS; do - git tag "$tag" - git push origin "$tag" - done - - - name: Create GitHub releases - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - TAGS: ${{ needs.detect.outputs.tags }} - PR_BODY: ${{ github.event.pull_request.body }} - PR_NUMBER: ${{ github.event.pull_request.number }} - run: | - printf '%s\n' "$PR_BODY" > "$RUNNER_TEMP/pr-body.md" - - for tag in $TAGS; do - prefix="${tag%%-v*}" - version="${tag#*-v}" - case "$prefix" in - rtc) package="livekit" ;; - api) package="livekit-api" ;; - protocol) package="livekit-protocol" ;; - esac - - # Take this package's "## v (...)" section from - # the release PR body (written from the consumed changesets) - notes="$RUNNER_TEMP/notes-$tag.md" - awk -v heading="## $package v$version " ' - index($0, heading) == 1 { found = 1; next } - found && /^## / { exit } - # Buffer blank lines so leading/trailing ones are dropped - found && /^[[:space:]]*$/ { if (started) blank = blank "\n"; next } - found { printf "%s%s\n", blank, $0; blank = ""; started = 1 } - ' "$RUNNER_TEMP/pr-body.md" > "$notes" - if ! grep -q '[^[:space:]]' "$notes"; then - echo "Released from #$PR_NUMBER." > "$notes" - fi - - args=() - if [[ "$version" == *rc* ]]; then - args+=(--prerelease) - fi - # Created as a draft; each publish job makes its release public - # only after the PyPI upload succeeds. - gh release create "$tag" \ - --draft \ - --verify-tag \ - --title "$package v$version" \ - --notes-file "$notes" \ - "${args[@]}" - done - - # ── RTC builds (multi-platform) ────────────────────────────── + # ── Builds ─────────────────────────────────────────────────── build-rtc: name: Build RTC wheels (${{ matrix.archs }}) - needs: detect - if: needs.detect.outputs.rtc == 'true' + needs: gate + if: needs.gate.outputs.release == 'true' runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -269,6 +100,7 @@ jobs: steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 with: + ref: ${{ needs.gate.outputs.sha }} submodules: true - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7 @@ -288,8 +120,8 @@ jobs: build-rtc-sdist: name: Build RTC sdist - needs: detect - if: needs.detect.outputs.rtc == 'true' + needs: gate + if: needs.gate.outputs.release == 'true' runs-on: ubuntu-latest defaults: run: @@ -297,6 +129,7 @@ jobs: steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 with: + ref: ${{ needs.gate.outputs.sha }} submodules: true - name: Build sdist @@ -309,52 +142,21 @@ jobs: name: dist-rtc-sdist path: livekit-rtc/dist/*.tar.gz - publish-rtc: - name: Publish livekit (RTC) - needs: [detect, build-rtc, build-rtc-sdist, tag] - if: needs.detect.outputs.rtc == 'true' - runs-on: ubuntu-latest - environment: pypi - permissions: - contents: write - id-token: write - steps: - - name: Download build artifacts - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 - with: - pattern: dist-rtc-* - path: dist - merge-multiple: true - - - name: List distributions - run: ls -la dist/ - - - name: Publish to PyPI - uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 - - - name: Publish GitHub release - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - TAGS: ${{ needs.detect.outputs.tags }} - run: | - for tag in $TAGS; do - if [[ "$tag" == rtc-v* ]]; then - gh release edit "$tag" --repo "$GITHUB_REPOSITORY" --draft=false - fi - done - - # ── API build ──────────────────────────────────────────────── - build-api: - name: Build API - needs: detect - if: needs.detect.outputs.api == 'true' + build: + name: Build ${{ matrix.package }} + needs: gate + if: needs.gate.outputs.release == 'true' runs-on: ubuntu-latest + strategy: + matrix: + package: [livekit-api, livekit-protocol] defaults: run: - working-directory: ./livekit-api + working-directory: ./${{ matrix.package }} steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 with: + ref: ${{ needs.gate.outputs.sha }} submodules: true - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7 @@ -366,132 +168,168 @@ jobs: - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 with: - name: dist-api + name: dist-${{ matrix.package }} path: | - livekit-api/dist/*.whl - livekit-api/dist/*.tar.gz + ${{ matrix.package }}/dist/*.whl + ${{ matrix.package }}/dist/*.tar.gz - publish-api: - name: Publish livekit-api - needs: [detect, build-api, tag] - if: needs.detect.outputs.api == 'true' + # ── Tag & GitHub releases ──────────────────────────────────── + release: + needs: [gate, build-rtc, build-rtc-sdist, build] runs-on: ubuntu-latest - environment: pypi permissions: contents: write - id-token: write + outputs: + released: ${{ steps.verwalter.outputs.released }} + releases: ${{ steps.verwalter.outputs.releases }} + docs: ${{ steps.docs.outputs.tags }} steps: - - name: Download build artifact - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 with: - name: dist-api - path: dist/ - - - name: List distributions - run: ls -la dist/ - - - name: Publish to PyPI - uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 - - - name: Publish GitHub release + # The merge commit itself: a push to main right after the merge + # must not move the tags. + ref: ${{ needs.gate.outputs.sha }} + fetch-depth: 0 + - id: verwalter + uses: livekit/verwalter@14fef9bf275fb347702b083d573e4a1f09bf0ef4 # v0.32.0-rc.2 + with: + command: release + args: ${{ inputs.package && format('--package {0}', inputs.package) || '' }} + # The docs site holds one version per package. Only the newest final + # tag of a package may deploy: not an rc, and not an older version + # that a run by hand reports again. Output: {"": ""}. + - id: docs env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - TAGS: ${{ needs.detect.outputs.tags }} + RELEASES: ${{ steps.verwalter.outputs.releases }} run: | - for tag in $TAGS; do - if [[ "$tag" == api-v* ]]; then - gh release edit "$tag" --repo "$GITHUB_REPOSITORY" --draft=false + git fetch -q --tags --force origin + docs='{}' + while read -r pkg tag; do + [ -n "$pkg" ] || continue + newest=$(git tag --list "${tag%-v*}-v*" | grep -v -- '-rc' | sort -V | tail -n 1) + if [ "$tag" = "$newest" ]; then + docs=$(jq -c --arg p "$pkg" --arg t "$tag" '. + {($p): $t}' <<< "$docs") + else + echo "No docs for $tag: $newest is newer" fi - done - - # ── Protocol build ─────────────────────────────────────────── - build-protocol: - name: Build Protocol - needs: detect - if: needs.detect.outputs.protocol == 'true' + done < <(jq -r '.[] | select(.prerelease | not) | "\(.package) \(.tag)"' <<< "${RELEASES:-[]}") + echo "tags=$docs" >> "$GITHUB_OUTPUT" + + # ── PyPI ───────────────────────────────────────────────────── + # `verwalter publish` runs the publish command of verwalter.toml for each + # released package: dependencies first, a failure blocks only its + # dependents, a package whose source changed since its tag fails, and a + # draft goes public only when PyPI has its sdist, which uploads last. + publish: + needs: [gate, release] + if: needs.release.outputs.released == 'true' || github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest - defaults: - run: - working-directory: ./livekit-protocol + environment: pypi + permissions: + contents: write # the tool makes the draft releases public + id-token: write # trusted publishing and the attestations + outputs: + docs: ${{ steps.docs.outputs.tags }} steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 with: - submodules: true - - - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7 - - - name: Build wheel & sdist - run: | - pip3 install build wheel - python3 -m build --wheel --sdist + ref: ${{ needs.gate.outputs.sha }} + fetch-depth: 0 # tags decide what is published - - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 + - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 with: - name: dist-protocol - path: | - livekit-protocol/dist/*.whl - livekit-protocol/dist/*.tar.gz - - publish-protocol: - name: Publish livekit-protocol - needs: [detect, build-protocol, tag] - if: needs.detect.outputs.protocol == 'true' - runs-on: ubuntu-latest - environment: pypi - permissions: - contents: write - id-token: write - steps: - - name: Download build artifact - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 + pattern: dist-rtc-* + path: dist/livekit + merge-multiple: true + - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 with: - name: dist-protocol - path: dist/ + name: dist-livekit-api + path: dist/livekit-api + - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 + with: + name: dist-livekit-protocol + path: dist/livekit-protocol - name: List distributions - run: ls -la dist/ + run: ls -laR dist/ + + - uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1 - - name: Publish to PyPI - uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 + - name: Upload to PyPI and make the GitHub releases public + uses: livekit/verwalter@14fef9bf275fb347702b083d573e4a1f09bf0ef4 # v0.32.0-rc.2 + env: + GH_TOKEN: ${{ github.token }} + with: + command: publish + releases: ${{ needs.release.outputs.releases }} - - name: Publish GitHub release + # Docs only for a release that is public now: a failed or blocked + # package keeps its draft, and the others still get their docs. + - id: docs + if: always() env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - TAGS: ${{ needs.detect.outputs.tags }} + GH_TOKEN: ${{ github.token }} + CANDIDATES: ${{ needs.release.outputs.docs }} run: | - for tag in $TAGS; do - if [[ "$tag" == protocol-v* ]]; then - gh release edit "$tag" --repo "$GITHUB_REPOSITORY" --draft=false + [ -n "$CANDIDATES" ] || CANDIDATES='{}' + docs='{}' + while read -r pkg tag; do + [ -n "$pkg" ] || continue + if [ "$(gh release view "$tag" --json isDraft -q .isDraft)" = "false" ]; then + docs=$(jq -c --arg p "$pkg" --arg t "$tag" '. + {($p): $t}' <<< "$docs") + else + echo "No docs for $tag: its release is still a draft" fi - done + done < <(jq -r 'to_entries[] | "\(.key) \(.value)"' <<< "$CANDIDATES") + echo "tags=$docs" >> "$GITHUB_OUTPUT" + + # The end state, asserted: fails when a tag is not on the remote, a GitHub + # release is missing or still a draft, or PyPI does not have the sdist. + verify: + needs: [gate, publish] + runs-on: ubuntu-latest + permissions: + contents: write # reads only. A draft release is visible only with write access + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 + with: + ref: ${{ needs.gate.outputs.sha }} + fetch-depth: 0 + - uses: livekit/verwalter@14fef9bf275fb347702b083d573e4a1f09bf0ef4 # v0.32.0-rc.2 + with: + command: status + args: --check - # ── Docs ───────────────────────────────────────────────────── + # ── Docs (the newest final version only, once public, built from its tag) ─ docs-rtc: name: Build RTC docs - needs: [detect, publish-rtc] - if: needs.detect.outputs.rtc == 'true' + needs: [gate, publish] + if: ${{ !cancelled() && fromJSON(needs.publish.outputs.docs || '{}')['livekit'] != null }} uses: ./.github/workflows/build-docs.yml with: package_dir: livekit-rtc package_name: livekit.rtc + ref: ${{ fromJSON(needs.publish.outputs.docs)['livekit'] }} secrets: inherit docs-api: name: Build API docs - needs: [detect, publish-api] - if: needs.detect.outputs.api == 'true' + needs: [gate, publish] + if: ${{ !cancelled() && fromJSON(needs.publish.outputs.docs || '{}')['livekit-api'] != null }} uses: ./.github/workflows/build-docs.yml with: package_dir: livekit-api package_name: livekit.api + ref: ${{ fromJSON(needs.publish.outputs.docs)['livekit-api'] }} secrets: inherit docs-protocol: name: Build Protocol docs - needs: [detect, publish-protocol] - if: needs.detect.outputs.protocol == 'true' + needs: [gate, publish] + if: ${{ !cancelled() && fromJSON(needs.publish.outputs.docs || '{}')['livekit-protocol'] != null }} uses: ./.github/workflows/build-docs.yml with: package_dir: livekit-protocol package_name: livekit.protocol + ref: ${{ fromJSON(needs.publish.outputs.docs)['livekit-protocol'] }} secrets: inherit diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml new file mode 100644 index 000000000..f32a3fb54 --- /dev/null +++ b/.github/workflows/pre-release.yml @@ -0,0 +1,27 @@ +# On demand: open an rc PR from the branch the workflow is run on. It +# carries every package with a pending changeset, each at its own rc +# version. The levels come from the changesets. Merging the PR tags +# 1.6.0-rc.1; the next run numbers rc.2. Changesets stay pending for the +# final release. +name: Pre-release PR + +on: + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +jobs: + pr: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 + with: + fetch-depth: 0 # the tags number the rc + - uses: livekit/verwalter@14fef9bf275fb347702b083d573e4a1f09bf0ef4 # v0.32.0-rc.2 + with: + command: pre-release + args: --target ${{ github.ref_name }} + app-client-id: ${{ secrets.VERWALTER_RELEASE_CLIENT_ID }} + app-private-key: ${{ secrets.VERWALTER_RELEASE_APP_KEY }} diff --git a/.github/workflows/release-gate.yml b/.github/workflows/release-gate.yml index 7ed81085a..3d34c8582 100644 --- a/.github/workflows/release-gate.yml +++ b/.github/workflows/release-gate.yml @@ -18,6 +18,7 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} HEAD_REF: ${{ github.event.pull_request.head.ref }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} PR_AUTHOR: ${{ github.event.pull_request.user.login }} PR_NUMBER: ${{ github.event.pull_request.number }} REPO: ${{ github.repository }} @@ -27,15 +28,18 @@ jobs: exit 0 fi - if [ "$PR_AUTHOR" != "github-actions[bot]" ]; then - echo "::error::Release PRs must be created by the publish workflow, not by '$PR_AUTHOR'" + # The same author that `verwalter gate` accepts ([release].author) + if [ "$PR_AUTHOR" != "verwalter-release[bot]" ]; then + echo "::error::Release PRs must be created by verwalter (release-pr.yml or pre-release.yml), not by '$PR_AUTHOR'" exit 1 fi - approvals=$(gh api "repos/$REPO/pulls/$PR_NUMBER/reviews" \ - --jq '[group_by(.user.login)[] | sort_by(.submitted_at) | last | select(.state == "APPROVED") | .user.login] | length') - echo "Approvals: $approvals" + # Each push to main regenerates the release branch. Only an + # approval of the current head commit counts. + approvals=$(gh api --paginate "repos/$REPO/pulls/$PR_NUMBER/reviews" \ + | jq -s --arg sha "$HEAD_SHA" '[add | .[] | select(.commit_id == $sha and (.state == "APPROVED" or .state == "CHANGES_REQUESTED" or .state == "DISMISSED"))] | group_by(.user.login) | map(sort_by(.submitted_at) | last | select(.state == "APPROVED")) | length') + echo "Approvals of $HEAD_SHA: $approvals" if [ "$approvals" -lt 2 ]; then - echo "::error::Release PRs require at least 2 approvals (got $approvals)" + echo "::error::Release PRs require at least 2 approvals of the head commit (got $approvals)" exit 1 fi diff --git a/.github/workflows/release-pr.yml b/.github/workflows/release-pr.yml new file mode 100644 index 000000000..39b1029a2 --- /dev/null +++ b/.github/workflows/release-pr.yml @@ -0,0 +1,30 @@ +# Keeps one release PR open while changesets are pending. Runs on every +# push to main and regenerates the release branch from main. +name: Release PRs + +on: + push: + branches: [main] + +permissions: + contents: write + pull-requests: write + +concurrency: + group: release-prs + cancel-in-progress: true + +jobs: + pr: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 + with: + fetch-depth: 0 # the commit that added a changeset gives its changelog line the PR and author + - uses: livekit/verwalter@14fef9bf275fb347702b083d573e4a1f09bf0ef4 # v0.32.0-rc.2 + with: + command: pr + # A GitHub App token lets the release PRs trigger CI; the default + # github.token does not. Without these secrets, github.token is used. + app-client-id: ${{ secrets.VERWALTER_RELEASE_CLIENT_ID }} + app-private-key: ${{ secrets.VERWALTER_RELEASE_APP_KEY }} diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 000000000..4999523d8 --- /dev/null +++ b/RELEASING.md @@ -0,0 +1,86 @@ +# Releasing python-sdks + +This repository releases with [verwalter](https://github.com/livekit/verwalter). +The [verwalter cheat sheet](https://github.com/livekit/verwalter/blob/main/docs/cheat-sheet.md) +has the commands that every repository shares. This file holds what is +specific to this repository. + +## Packages + +| Package | Path | Tag | Goes to | +|---|---|---|---| +| `livekit` | `livekit-rtc` | `rtc-v` | PyPI: 5 wheel platforms, sdist | +| `livekit-api` | `livekit-api` | `api-v` | PyPI | +| `livekit-protocol` | `livekit-protocol` | `protocol-v` | PyPI | + +Each package keeps its version in `livekit//version.py`. + +`livekit-api` depends on `livekit-protocol`. A release of `livekit-protocol` +also releases `livekit-api` as a patch. The release moves the +`livekit-protocol` requirement in `livekit-api/pyproject.toml` to the new +version, and to the next major for a major release. + +## Workflows + +| File | Trigger | Does | +|---|---|---| +| `changeset-check.yml` | A PR opens or changes | Fails a package change with no changeset. Builds and runs `twine check` on the release PR. | +| `release-pr.yml` | A push to `main` | Keeps the release PR `release/main` current. | +| `pre-release.yml` | Run by hand | Opens an rc PR from its branch. | +| `release-gate.yml` | A `release/*` PR or review | Requires the verwalter author and 2 approvals of the head commit. | +| `package-release.yml` | The release PR merges | Builds, tags, uploads to PyPI, publishes the docs. | +| `build-docs.yml` | Called by `package-release.yml` | Uploads the pdoc docs of a final version to S3. | + +`changeset-check.yml` skips `renovate/*` branches. `release-gate.yml` is a +required check on `main`. The `gate` job of `package-release.yml` releases only +a merged PR from `verwalter-release[bot]`, or a run by hand from `main`. A run +by hand releases only a commit that is on `main`. + +## Release + +1. Merge the release PR. It needs 2 approvals of its head commit. A push to + `main` regenerates the PR, and the approvals then count no more. +2. Watch the run of `package-release.yml`: `gh run list --workflow package-release.yml --limit 1`. + +`verwalter publish` uploads with twine: the wheels first, the sdist last. A +version counts as on PyPI when its sdist is there, so a half upload stays a +draft, and a re-run uploads the missing files. The `verify` job checks the end +state. Each tag has a public GitHub release, and PyPI has each sdist. For a final version, the docs job of the package +must also be green. + +## Pre-release + +Run `gh workflow run pre-release.yml --ref `. The pending changesets +decide the packages and the levels. The rc is `1.6.0rc1` in `version.py` and on +PyPI, and `1.6.0-rc.1` in the tag. The changesets stay pending for the final +release. + + +An rc includes only the packages with a pending changeset. For a major rc of +`livekit-protocol`, also add a `patch` changeset for `livekit-api`. Else the rc +PR leaves `livekit-api` at `livekit-protocol<3.0.0`, which excludes the rc, and +the API tests cannot install both packages. + +The release gate covers only PRs into `main`. An rc PR into another branch +needs no approval, and its merge releases the rc. + +## A release failed + +Find the cause first. The +[recovery section](https://github.com/livekit/verwalter/blob/main/docs/release-workflows.md#recovery) +has the paths by cause. + +| Situation | Command | +|---|---| +| A job failed for a transient reason | `gh run rerun --failed` | +| The workflow needed a fix, now on `main` | `gh workflow run package-release.yml -f ref=` | +| `publish` failed a package with `HEAD changed the source since ` | `gh workflow run package-release.yml -f ref= -f package=` | +| A build failed. The builds run before the tag, so no tag exists. | Merge the fix to `main` without a changeset, then `gh workflow run package-release.yml` | +| The released commit is wrong | `verwalter release --abandon `, then a changeset and the next version | + +The PyPI upload skips files that PyPI has, so a re-run is safe. PyPI never +replaces a version. Yank a broken version on PyPI and release the next one. + +## Who to ask + +The owners in `.github/CODEOWNERS`. diff --git a/verwalter.toml b/verwalter.toml new file mode 100644 index 000000000..81940d5e5 --- /dev/null +++ b/verwalter.toml @@ -0,0 +1,34 @@ +#:schema https://raw.githubusercontent.com/livekit/verwalter/main/schemas/v1.json + +[workspace] +members = ["livekit-rtc", "livekit-api", "livekit-protocol"] +exclude = ["python-sdks"] # the uv workspace root, never published + +[check] +publish_dry_run = "uv build --out-dir dist && uvx twine check dist/*" # PyPI has no built-in dry run + +# A PyPI version has many files, and PyPI shows the version after the first +# one. So each package checks for its sdist (`publish.exists_url`), which twine +# uploads last after the wheels: a half upload stays a draft, and a re-run +# with --skip-existing uploads the missing files. `{version}` is PEP 440 there. +# The command signs PEP 740 attestations, which the built-in one does not. +# The release workflow builds into dist// at the root. +[publish] +registry = "pypi" +command = "uvx pypi-attestations@0.0.31 sign $VERWALTER_ROOT/dist/{package}/* && uvx twine@7.0.0 upload --attestations --skip-existing $VERWALTER_ROOT/dist/{package}/*" + +[packages.livekit] +versioning.files = [{ path = "livekit/rtc/version.py", regex = '__version__ = "(?[^"]+)"' }] +release.tag = "rtc-v{version}" +publish.exists_url = "https://files.pythonhosted.org/packages/source/l/livekit/livekit-{version}.tar.gz" +check.publish_dry_run = "uv build --sdist --out-dir dist && uvx twine check dist/*" # the wheels need cibuildwheel and the FFI binaries + +[packages.livekit-api] +versioning.files = [{ path = "livekit/api/version.py", regex = '__version__ = "(?[^"]+)"' }] +release.tag = "api-v{version}" +publish.exists_url = "https://files.pythonhosted.org/packages/source/l/livekit-api/livekit_api-{version}.tar.gz" + +[packages.livekit-protocol] +versioning.files = [{ path = "livekit/protocol/version.py", regex = '__version__ = "(?[^"]+)"' }] +release.tag = "protocol-v{version}" +publish.exists_url = "https://files.pythonhosted.org/packages/source/l/livekit-protocol/livekit_protocol-{version}.tar.gz"