Skip to content

Commit a1588cc

Browse files
authored
Merge pull request pypa#1899 from konstin/konsti/update-uv-build-version-automatically
Update uv_build version automatically
2 parents a6c4683 + b036f24 commit a1588cc

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

.github/workflows/test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@ on:
66
branches-ignore:
77
- gh-readonly-queue/** # Temporary merge queue-related GH-made branches
88
pull_request:
9+
types:
10+
- opened # default
11+
- synchronize # default
12+
- reopened # default
13+
- ready_for_review # used in PRs created from GitHub Actions workflows
914
workflow_call:
1015

1116
concurrency:
1217
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
1318
cancel-in-progress: true
1419

20+
permissions: {}
21+
1522
jobs:
1623
build:
1724
name: ${{ matrix.noxenv }}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
3+
name: Update uv build version
4+
5+
on:
6+
schedule:
7+
- cron: "0 6 * * 1" # mondays at 6am
8+
workflow_dispatch:
9+
10+
jobs:
11+
update-uv-build-version:
12+
name: Update uv_build version
13+
if: github.repository_owner == 'pypa' # suppress noise in forks
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
17+
pull-requests: write
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
with:
22+
persist-credentials: false
23+
- name: Set up uv
24+
uses: astral-sh/setup-uv@v5
25+
- name: Update uv_build version
26+
id: update_script
27+
run: uv run scripts/update_uv_build_version.py
28+
- # If there are no changes, no pull request will be created and the action exits silently.
29+
name: Create Pull Request
30+
uses: peter-evans/create-pull-request@v7
31+
with:
32+
token: ${{ secrets.GITHUB_TOKEN }}
33+
commit-message: Update uv_build version to ${{ steps.update_script.outputs.version }}
34+
title: Update uv_build version to ${{ steps.update_script.outputs.version }}
35+
draft: true # Trigger CI by un-drafting the PR, otherwise `GITHUB_TOKEN` PRs don't trigger CI.
36+
body: |
37+
Automated update of uv_build version bounds for uv ${{ steps.update_script.outputs.version }}.
38+
39+
This PR was created automatically by the cron workflow, ping `@konstin` for problems.
40+
branch: bot/update-uv-build-version
41+
delete-branch: true
42+
43+
...

scripts/update_uv_build_version.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# /// script
2+
# requires-python = ">= 3.12"
3+
# dependencies = [
4+
# "httpx>=0.28.1,<0.29",
5+
# "packaging>=25.0",
6+
# ]
7+
# ///
8+
import os
9+
import re
10+
from pathlib import Path
11+
12+
import httpx
13+
from packaging.utils import parse_wheel_filename
14+
from packaging.version import Version
15+
16+
17+
def main():
18+
response = httpx.get(
19+
"https://pypi.org/simple/uv-build/",
20+
headers={"Accept": "application/vnd.pypi.simple.v1+json"},
21+
)
22+
response.raise_for_status()
23+
data = response.json()
24+
current_release = None
25+
for file in data["files"]:
26+
if not file["filename"].endswith(".whl"):
27+
continue
28+
_name, version, _build, _tags = parse_wheel_filename(file["filename"])
29+
if version.is_prerelease:
30+
continue
31+
if current_release is None or version > current_release:
32+
current_release = version
33+
34+
[major, minor, _patch] = current_release.release
35+
if major != 0:
36+
raise NotImplementedError("The script needs to be updated for uv 1.x")
37+
upper_bound = Version(f"{major}.{minor + 1}.0")
38+
39+
repository_root = Path(__file__).parent.parent
40+
existing = repository_root.joinpath(
41+
"source/shared/build-backend-tabs.rst"
42+
).read_text()
43+
replacement = f'requires = ["uv_build >= {current_release}, <{upper_bound}"]'
44+
searcher = re.compile(re.escape('requires = ["uv_build') + ".*" + re.escape('"]'))
45+
if not searcher.search(existing):
46+
raise RuntimeError("Could not `uv-build` entry")
47+
updated = searcher.sub(replacement, existing)
48+
49+
if existing != updated:
50+
print("Updating source/shared/build-backend-tabs.rst")
51+
Path("source/shared/build-backend-tabs.rst").write_text(updated)
52+
if github_output := os.environ.get("GITHUB_OUTPUT"):
53+
with open(github_output, "a") as f:
54+
f.write(f"version={current_release}\n")
55+
f.write("updated=true\n")
56+
else:
57+
print("Already up-to-date source/shared/build-backend-tabs.rst")
58+
if github_output := os.environ.get("GITHUB_OUTPUT"):
59+
with open(github_output, "a") as f:
60+
f.write("updated=false\n")
61+
62+
63+
if __name__ == "__main__":
64+
main()

0 commit comments

Comments
 (0)