Repository navigation
[CI] Pin the nightly changelog to the repository uv and check uv pins in pre-commit #9343
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| # Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md). | ||
| # All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| """Pre-commit hook: every uv pin in the repository names one version, and ``uv.lock`` was written by it. | ||
|
|
||
| uv releases serialize ``uv.lock`` differently (its ``revision`` and some dependency lists). A lock written by one uv | ||
| and re-locked by another changes more than package versions, which the nightly changelog compile rejects. | ||
| ``uv lock --check`` accepts either form, so the lock's ``revision`` is checked instead. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import re | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| import yaml | ||
|
|
||
| REPO_ROOT = Path(__file__).resolve().parents[2] | ||
|
|
||
| LOCK_REVISION = {"0.12.9": 3} | ||
| """The ``uv.lock`` revision each pinned uv writes. Add the new entry when changing the pin.""" | ||
|
|
||
| IMAGE_FILES = ("docker/Dockerfile.*", "docker/test/*.py", "source/isaaclab/test/install_ci/Dockerfile.installci") | ||
| IMAGE_PIN = re.compile(r"ghcr\.io/astral-sh/uv:(\d+\.\d+\.\d+)") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Find every uv image reference first, then reject unsupported or unpinned tags. |
||
|
|
||
|
|
||
| def image_pins() -> list[tuple[str, str]]: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Warning · Style Consistency — Keep file-local scanners private These scanners and lock_revision have no callers outside this file. Their public names contradict the repository's private-function convention; prefix them with underscores and place them after main. |
||
| """Return ``(location, version)`` for every ``ghcr.io/astral-sh/uv`` image reference.""" | ||
| pins = [] | ||
| for pattern in IMAGE_FILES: | ||
| for path in sorted(REPO_ROOT.glob(pattern)): | ||
| for number, line in enumerate(path.read_text(encoding="utf-8").splitlines(), start=1): | ||
| location = f"{path.relative_to(REPO_ROOT)}:{number}" | ||
| pins += [(location, version) for version in IMAGE_PIN.findall(line)] | ||
| return pins | ||
|
|
||
|
|
||
| def workflow_pins() -> list[tuple[str, str]]: | ||
| """Return ``(location, version)`` for every ``astral-sh/setup-uv`` step that sets ``version``. | ||
|
|
||
| Steps without ``version`` are skipped: they install the latest uv and do not write ``uv.lock``. | ||
| """ | ||
| pins = [] | ||
| for path in sorted((REPO_ROOT / ".github").rglob("*.y*ml")): | ||
| document = yaml.safe_load(path.read_text(encoding="utf-8")) | ||
| if not isinstance(document, dict): | ||
| continue | ||
| steps = [step for job in (document.get("jobs") or {}).values() for step in job.get("steps") or []] | ||
| steps += (document.get("runs") or {}).get("steps") or [] # composite actions | ||
| for step in steps: | ||
| inputs = step.get("with") or {} | ||
| if str(step.get("uses", "")).startswith("astral-sh/setup-uv@") and "version" in inputs: | ||
| location = f"{path.relative_to(REPO_ROOT)} (step {step.get('name') or step['uses']!r})" | ||
| pins.append((location, str(inputs["version"]))) | ||
| return pins | ||
|
|
||
|
|
||
| def lock_revision() -> int | None: | ||
| """Return the ``revision`` from the ``uv.lock`` header, or ``None`` if it has none.""" | ||
| with open(REPO_ROOT / "uv.lock", encoding="utf-8") as lock: | ||
| for line in lock: | ||
| if match := re.fullmatch(r"revision = (\d+)\s*", line): | ||
| return int(match[1]) | ||
| if line.startswith("["): | ||
| return None | ||
| return None | ||
|
|
||
|
|
||
| def main() -> int: | ||
| """Print every disagreement and return 1 if there is one.""" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Warning · Style Consistency — Correct the failure docstring main returns on the first failed check, so it never prints every disagreement. Describe first-failure behavior or collect the errors before returning. |
||
| pins = image_pins() + workflow_pins() | ||
| versions = sorted({version for _, version in pins}) | ||
| if len(versions) != 1: | ||
| listing = "\n".join(f" {location}: {version}" for location, version in pins) | ||
| print(f"uv is pinned to {len(versions)} versions; pin one everywhere:\n{listing}", file=sys.stderr) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Warning · Style Consistency — Log CLI failures All three failure branches print diagnostics, contrary to the contribution guide's CLI failure rule. Use a module-level logger.error for those messages. |
||
| return 1 | ||
| version = versions[0] | ||
| if version not in LOCK_REVISION: | ||
| print(f"uv {version} has no LOCK_REVISION entry in {Path(__file__).relative_to(REPO_ROOT)}", file=sys.stderr) | ||
| return 1 | ||
| revision, expected = lock_revision(), LOCK_REVISION[version] | ||
| if revision != expected: | ||
| print( | ||
| f"uv.lock has revision {revision}, but uv {version} writes revision {expected}: another uv wrote it." | ||
| f" Restore uv.lock from your base branch and re-lock with `uvx uv@{version} lock`.", | ||
| file=sys.stderr, | ||
| ) | ||
| return 1 | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) | ||
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.
🟡 Warning · Style Consistency — Describe the header check accurately
The hook checks a revision number, not which uv wrote the lockfile. This overstates its guarantee; describe the pin and header-revision comparison instead.