Skip to content

Commit 250267e

Browse files
committed
ci(version-check): require uv.lock sync alongside pyproject changes
Resolves CE-202. Mirrors the workflow + script changes from socket-python-cli#204 so the SDK catches lockfile drift the same way the CLI now does: - workflow: trigger paths drop unused setup.py, add uv.lock; new step fails CI if pyproject.toml is modified without uv.lock. - sync_version.py: new run_uv_lock() helper runs 'uv lock' and signals whether the lockfile changed. Wired into all three exit paths (--dev auto-bump, normal auto-bump, already-bumped) so the hook either updates uv.lock for you or tells you to commit it.
1 parent 41039a8 commit 250267e

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

.github/workflows/version-check.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ on:
44
types: [opened, synchronize, ready_for_review]
55
paths:
66
- 'socketdev/**'
7-
- 'setup.py'
87
- 'pyproject.toml'
8+
- 'uv.lock'
99

1010
permissions:
1111
contents: read
@@ -44,6 +44,18 @@ jobs:
4444
print(f'✅ Version properly incremented from {main_ver} to {pr_ver}')
4545
"
4646
47+
- name: Require uv.lock update when pyproject changes
48+
run: |
49+
CHANGED_FILES="$(git diff --name-only origin/main...HEAD)"
50+
51+
if echo "$CHANGED_FILES" | grep -qx 'pyproject.toml'; then
52+
if ! echo "$CHANGED_FILES" | grep -qx 'uv.lock'; then
53+
echo "❌ pyproject.toml changed, but uv.lock was not updated."
54+
echo "Run 'uv lock' and commit uv.lock with the version bump."
55+
exit 1
56+
fi
57+
fi
58+
4759
- name: Manage PR Comment
4860
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
4961
if: always()

.hooks/sync_version.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
VERSION_FILE = pathlib.Path("socketdev/version.py")
1010
PYPROJECT_FILE = pathlib.Path("pyproject.toml")
11+
UV_LOCK_FILE = pathlib.Path("uv.lock")
1112

1213
VERSION_PATTERN = re.compile(r"__version__\s*=\s*['\"]([^'\"]+)['\"]")
1314
PYPROJECT_PATTERN = re.compile(r'^version\s*=\s*".*"$', re.MULTILINE)
@@ -68,6 +69,22 @@ def inject_version(version: str):
6869
new_pyproject = PYPROJECT_PATTERN.sub(f'version = "{version}"', pyproject)
6970
PYPROJECT_FILE.write_text(new_pyproject)
7071

72+
73+
def run_uv_lock() -> bool:
74+
before = UV_LOCK_FILE.read_bytes() if UV_LOCK_FILE.exists() else b""
75+
try:
76+
subprocess.run(["uv", "lock"], check=True, text=True)
77+
except FileNotFoundError:
78+
print("❌ `uv` is required but was not found in PATH.")
79+
sys.exit(1)
80+
except subprocess.CalledProcessError:
81+
print("❌ `uv lock` failed. Please run it manually and fix any errors.")
82+
sys.exit(1)
83+
84+
after = UV_LOCK_FILE.read_bytes() if UV_LOCK_FILE.exists() else b""
85+
return before != after
86+
87+
7188
def main():
7289
dev_mode = "--dev" in sys.argv
7390
current_version = read_version_from_version_file(VERSION_FILE)
@@ -80,15 +97,24 @@ def main():
8097
base_version = current_version.split(".dev")[0] if ".dev" in current_version else current_version
8198
new_version = find_next_available_dev_version(base_version)
8299
inject_version(new_version)
83-
print("⚠️ Version was unchanged — auto-bumped. Please git add + commit again.")
100+
uv_lock_changed = run_uv_lock()
101+
lock_hint = " and uv.lock" if uv_lock_changed else ""
102+
print(f"⚠️ Version was unchanged — auto-bumped. Please git add{lock_hint} + commit again.")
84103
sys.exit(0)
85104
else:
86105
new_version = bump_patch_version(current_version)
87106
inject_version(new_version)
88-
print("⚠️ Version was unchanged — auto-bumped. Please git add + commit again.")
107+
uv_lock_changed = run_uv_lock()
108+
lock_hint = " and uv.lock" if uv_lock_changed else ""
109+
print(f"⚠️ Version was unchanged — auto-bumped. Please git add{lock_hint} + commit again.")
89110
sys.exit(1)
90111
else:
91-
print("✅ Version already bumped — proceeding.")
112+
uv_lock_changed = run_uv_lock()
113+
if uv_lock_changed:
114+
print("⚠️ Version already bumped, but uv.lock was out of date and has been updated. Please git add uv.lock + commit again.")
115+
sys.exit(1)
116+
117+
print("✅ Version already bumped and uv.lock is up to date — proceeding.")
92118
sys.exit(0)
93119

94120
if __name__ == "__main__":

0 commit comments

Comments
 (0)