Skip to content

Commit 7a057b3

Browse files
committed
feat: handle releases in mirror
feat: ignore yanked releases feat: replace older tag release as new HEAD
1 parent 9d6994f commit 7a057b3

File tree

4 files changed

+69
-40
lines changed

4 files changed

+69
-40
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,5 @@ jobs:
3030
git config user.email "[email protected]"
3131
3232
- run: python mirror.py
33-
34-
- name: check for unpushed commits
35-
id: check_unpushed
36-
run: |
37-
UNPUSHED_COMMITS=$(git log origin/main..HEAD)
38-
if [ -z "$UNPUSHED_COMMITS" ]; then
39-
echo "No unpushed commits found."
40-
echo "changes_exist=false" >> $GITHUB_ENV
41-
else
42-
echo "Unpushed commits found."
43-
echo "changes_exist=true" >> $GITHUB_ENV
44-
fi
45-
46-
- name: push changes if they exist
47-
if: env.changes_exist == 'true'
48-
run: |
49-
git push origin HEAD:refs/heads/main
50-
git push origin HEAD:refs/heads/main --tags
51-
52-
- name: create release on new tag if new changes exist
53-
if: env.changes_exist == 'true'
54-
run: |
55-
TAG_NAME=$(git describe --tags $(git rev-list --tags --max-count=1))
56-
echo $TAG_NAME
57-
gh release create "$TAG_NAME" \
58-
--title "$TAG_NAME" \
59-
--notes "See: https://github.com/astral-sh/uv/releases/tag/$TAG_NAME" \
60-
--latest
6133
env:
6234
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ To compile your requirements via pre-commit, add the following to your `.pre-com
1919
```yaml
2020
- repo: https://github.com/astral-sh/uv-pre-commit
2121
# uv version.
22-
rev: 0.2.13
22+
rev: 0.2.17
2323
hooks:
2424
# Run the pip compile
2525
- id: pip-compile
@@ -31,7 +31,7 @@ To compile alternative files, modify the `args` and `files`:
3131
```yaml
3232
- repo: https://github.com/astral-sh/uv-pre-commit
3333
# uv version.
34-
rev: 0.2.13
34+
rev: 0.2.17
3535
hooks:
3636
# Run the pip compile
3737
- id: pip-compile
@@ -44,7 +44,7 @@ To run the hook over multiple files at the same time:
4444
```yaml
4545
- repo: https://github.com/astral-sh/uv-pre-commit
4646
# uv version.
47-
rev: 0.2.13
47+
rev: 0.2.17
4848
hooks:
4949
# Run the pip compile
5050
- id: pip-compile

mirror.py

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,84 @@ def main():
1313
with open(Path(__file__).parent / "pyproject.toml", "rb") as f:
1414
pyproject = tomllib.load(f)
1515

16-
all_versions = get_all_versions()
16+
all_releases = get_all_releases()
1717
current_version = get_current_version(pyproject=pyproject)
18-
target_versions = [v for v in all_versions if v > current_version]
18+
all_non_yanked_versions = sorted([
19+
release_version
20+
for release_version, release in all_releases.items()
21+
if not any([asset["yanked"] for asset in release])
22+
])
23+
24+
target_versions = [v for v in all_non_yanked_versions if v > current_version]
25+
26+
if not target_versions and not any([
27+
asset["yanked"] for asset in all_releases[current_version]
28+
]):
29+
last_valid_version = all_non_yanked_versions[-1]
30+
paths = process_version(last_valid_version)
31+
if subprocess.check_output(["git", "status", "-s"]).strip():
32+
push_changed_version(paths, f"Mirror: yanked {current_version}")
33+
34+
# Make `last_valid_version` the top tag and release
35+
subprocess.run(
36+
[
37+
"gh",
38+
"release",
39+
"delete",
40+
f"{last_valid_version}",
41+
"--cleanup-tag",
42+
"--yes",
43+
],
44+
check=True,
45+
)
46+
create_tagged_release(last_valid_version)
47+
return
1948

2049
for version in target_versions:
2150
paths = process_version(version)
2251
if subprocess.check_output(["git", "status", "-s"]).strip():
23-
subprocess.run(["git", "add", *paths], check=True)
24-
subprocess.run(["git", "commit", "-m", f"Mirror: {version}"], check=True)
25-
subprocess.run(["git", "tag", f"{version}"], check=True)
52+
push_changed_version(paths, f"Mirror: {version}")
53+
create_tagged_release(version)
2654
else:
2755
print(f"No change {version}")
2856

2957

30-
def get_all_versions() -> list[Version]:
58+
def push_changed_version(paths: typing.Sequence[str], commit_message: str) -> None:
59+
subprocess.run(["git", "add", *paths], check=True)
60+
subprocess.run(["git", "commit", "-m", commit_message], check=True)
61+
subprocess.run(["git", "push", "origin", "HEAD:refs/heads/main"], check=True)
62+
63+
64+
def create_tagged_release(version: Version) -> None:
65+
subprocess.run(["git", "tag", f"{version}"], check=True)
66+
subprocess.run(
67+
["git", "push", "origin", "HEAD:refs/heads/main", "--tags"], check=False
68+
)
69+
subprocess.run(
70+
[
71+
"gh",
72+
"release",
73+
"create",
74+
f"{version}",
75+
"--title",
76+
f"{version}",
77+
"--notes",
78+
f"See: https://github.com/astral-sh/uv/releases/tag/{version}",
79+
"--latest",
80+
],
81+
check=False,
82+
)
83+
84+
85+
def get_all_releases() -> dict[Version, list[dict[str, typing.Any]]]:
3186
response = urllib3.request("GET", "https://pypi.org/pypi/uv/json")
3287
if response.status != 200:
3388
raise RuntimeError("Failed to fetch versions from pypi")
3489

35-
versions = [Version(release) for release in response.json()["releases"]]
36-
return sorted(versions)
90+
return {
91+
Version(release_version): release
92+
for release_version, release in response.json()["releases"].items()
93+
}
3794

3895

3996
def get_current_version(pyproject: dict) -> Version:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "uv-pre-commit"
33
version = "0.0.0"
44
dependencies = [
5-
"uv==0.2.13",
5+
"uv==0.2.17",
66
]
77

88
[project.optional-dependencies]

0 commit comments

Comments
 (0)