-
Notifications
You must be signed in to change notification settings - Fork 113
ci: add PyPI publish workflow with trusted publishing #601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
80f2d3b
ci: add PyPI publish workflow with trusted publishing
theomonnom 189abf8
ci: support per-package releases in publish workflow
theomonnom c178bb3
ci: fix script injection, unique approvals, scope PR closing per-package
theomonnom 883f27d
ci: improve release gate approval counting and remove paths filter
theomonnom 277af7e
ci: fix script injection in build-docs workflow
theomonnom 1c8692e
ci: tag the actual merge commit, not the test merge ref
theomonnom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| 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", | ||
| } | ||
|
|
||
|
|
||
| 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("bump") | ||
| @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.", | ||
| ) | ||
| def bump(package: str, pre: str, bump_type: str) -> None: | ||
| if pre == "none": | ||
| do_bump(package, bump_type) | ||
| else: | ||
| do_prerelease(package, pre) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| bump() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Major version bump of livekit-protocol creates unsatisfiable dependency constraint in livekit-api
update_api_protocol_dependencyonly updates the lower bound of the version constraint inlivekit-api/pyproject.tomlbut leaves the upper bound untouched. When doing amajorbump (e.g.,1.1.4→2.0.0), the existing dependency"livekit-protocol>=1.1.1,<2.0.0"atlivekit-api/pyproject.toml:33becomes"livekit-protocol>=2.0.0,<2.0.0"— an impossible constraint that no version can satisfy. This would produce a broken release PR for livekit-api.Trace through the code
The regex
r'"livekit-protocol>=[\w.\-]+,'matches"livekit-protocol>=1.1.1,(up to and including the first comma). The replacement inserts the new version>=2.0.0,, but<2.0.0remains from the original text, yielding>=2.0.0,<2.0.0.Prompt for agents
Was this helpful? React with 👍 or 👎 to provide feedback.