Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/actions/ci/version-check/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ runs:
- name: Check version consistency
run: |
# Get reference version from pyproject.toml
REFERENCE_VERSION=$(uv run ci-version-pyproject)
REFERENCE_VERSION=$(uv run ci-pyproject-version)
echo "Reference version (pyproject.toml): $REFERENCE_VERSION"

MISMATCH=false

# Check uv.lock
LOCK_VERSION=$(uv run ci-version-uv-lock)
LOCK_VERSION=$(uv run ci-uv-lock-version)
if [ "$LOCK_VERSION" != "$REFERENCE_VERSION" ]; then
echo "❌ uv.lock: $LOCK_VERSION (expected $REFERENCE_VERSION)"
MISMATCH=true
Expand Down
4 changes: 2 additions & 2 deletions docs/WORKFLOWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ steps:
- Location: `version-check/action.yml`
- Steps:
- Uses the `install-python-dev` action
- Extracts version from `pyproject.toml` using `uv run ci-version-pyproject`
- Verifies `uv.lock` version matches using `uv run ci-version-uv-lock`
- Extracts version from `pyproject.toml` using `uv run ci-pyproject-version`
- Verifies `uv.lock` version matches using `uv run ci-uv-lock-version`
- Optionally checks additional version files via `additional-versions` input
- Fails if any version mismatch is detected

Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ dev = [
repository = "https://github.com/javidahmed64592/template-python"

[project.scripts]
ci-version-pyproject = "template_python.workflows:print_version_pyproject"
ci-version-uv-lock = "template_python.workflows:print_version_uv_lock"
ci-pyproject-version = "template_python.workflows:print_version_pyproject"
ci-pyproject-name = "template_python.workflows:print_name_pyproject"
ci-uv-lock-version = "template_python.workflows:print_version_uv_lock"
example-entrypoint = "template_python.main:example_function"

[tool.hatch.metadata]
Expand Down
18 changes: 15 additions & 3 deletions template_python/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,22 @@ def _get_version_pyproject() -> str:
return str(pyproject["project"]["version"])


@cache
def _get_name_pyproject() -> str:
"""Get the name from pyproject.toml."""
pyproject = _load_pyproject()
return str(pyproject["project"]["name"])


@cache
def _get_version_uv_lock() -> str:
"""Get the version from uv.lock."""
pyproject = _load_pyproject()
name = _get_name_pyproject()
uv_lock = _load_uv_lock()
if pkg := next((p for p in uv_lock["package"] if p["name"] == pyproject["project"]["name"]), None):
if pkg := next((p for p in uv_lock["package"] if p["name"] == name), None):
return str(pkg["version"])

error_msg = f"Package '{pyproject['project']['name']}' not found in uv.lock"
error_msg = f"Package '{name}' not found in uv.lock"
raise ValueError(error_msg)


Expand All @@ -44,6 +51,11 @@ def print_version_pyproject() -> None:
print(_get_version_pyproject())


def print_name_pyproject() -> None:
"""Get the name from pyproject.toml."""
print(_get_name_pyproject())


def print_version_uv_lock() -> None:
"""Get the version from uv.lock."""
print(_get_version_uv_lock())
15 changes: 13 additions & 2 deletions tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import pytest

from template_python.workflows import (
_get_name_pyproject,
_get_version_pyproject,
_get_version_uv_lock,
_load_pyproject,
_load_uv_lock,
print_name_pyproject,
print_version_pyproject,
print_version_uv_lock,
)
Expand All @@ -26,16 +28,21 @@ def test_load_pyproject(self) -> None:

def test_load_uv_lock(self) -> None:
"""Test loading the uv.lock file."""
pyproject = _load_pyproject()
name = _get_name_pyproject()
uv_lock = _load_uv_lock()
assert "package" in uv_lock
assert any(p["name"] == pyproject["project"]["name"] for p in uv_lock["package"])
assert any(p["name"] == name for p in uv_lock["package"])

def test_get_version_pyproject(self) -> None:
"""Test getting the version from pyproject.toml."""
version = _get_version_pyproject()
assert isinstance(version, str)

def test_get_name_pyproject(self) -> None:
"""Test getting the name from pyproject.toml."""
name = _get_name_pyproject()
assert isinstance(name, str)

def test_get_version_uv_lock(self) -> None:
"""Test getting the version from uv.lock."""
version = _get_version_uv_lock()
Expand All @@ -57,6 +64,10 @@ def test_print_version_pyproject(self) -> None:
"""Test printing the version from pyproject.toml."""
print_version_pyproject()

def test_print_name_pyproject(self) -> None:
"""Test printing the name from pyproject.toml."""
print_name_pyproject()

def test_print_version_uv_lock(self) -> None:
"""Test printing the version from uv.lock."""
print_version_uv_lock()
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading