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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.13"
# dependencies = ["typer"]
# dependencies = ["typer>=0.17,<0.18"]
# ///
"""Verify that the GitHub Release for the provided tag exists and is published."""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.13"
# dependencies = ["typer"]
# dependencies = ["typer>=0.17,<0.18"]
# ///
"""Validate that the caller supplied the expected confirmation string."""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.13"
# dependencies = ["typer"]
# dependencies = ["typer>=0.17,<0.18"]
# ///
"""Resolve the release tag and semantic version for the current run."""

Expand Down
21 changes: 14 additions & 7 deletions .github/actions/release-to-pypi-uv/scripts/publish_release.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.13"
# dependencies = ["typer"]
# dependencies = ["typer>=0.17,<0.18"]
# ///
"""Publish the built distributions using uv."""

Expand Down Expand Up @@ -31,8 +31,6 @@ def _extend_sys_path() -> None:
candidates.append(scripts_dir.parents[3])

for candidate in candidates:
if not candidate:
continue
if not candidate.exists():
continue
path_str = str(candidate)
Expand All @@ -44,24 +42,33 @@ def _extend_sys_path() -> None:

from cmd_utils import run_cmd # noqa: E402

INDEX_OPTION = typer.Option("", envvar="INPUT_UV_INDEX")
INDEX_OPTION = typer.Option(
"",
envvar="INPUT_UV_INDEX",
help="Optional index name or URL for uv publish.",
)


def main(index: str = INDEX_OPTION) -> None:
def main(index: str = "") -> None:
"""Publish the built distributions with uv.

Parameters
----------
index : str
Optional package index name or URL to pass to ``uv publish``.
"""
if index:
if index := index.strip():
typer.echo(f"Publishing with uv to index '{index}'")
run_cmd(["uv", "publish", "--index", index])
else:
typer.echo("Publishing with uv to default index (PyPI)")
run_cmd(["uv", "publish"])


def cli(index: str = INDEX_OPTION) -> None:
"""CLI entrypoint."""
main(index=index)


if __name__ == "__main__":
typer.run(main)
typer.run(cli)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.13"
# dependencies = ["typer"]
# dependencies = ["typer>=0.17,<0.18"]
# ///
"""Validate that project versions in pyproject.toml files match the release version."""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.13"
# dependencies = ["typer"]
# dependencies = ["typer>=0.17,<0.18"]
# ///
"""Append a short release summary for the workflow run."""

Expand Down
73 changes: 70 additions & 3 deletions .github/actions/release-to-pypi-uv/tests/test_publish_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from types import ModuleType

import pytest
from typer.testing import CliRunner

from ._helpers import REPO_ROOT, load_script_module

Expand All @@ -22,7 +23,9 @@ def fixture_publish_module() -> ModuleType:


def test_publish_default_index(
monkeypatch: pytest.MonkeyPatch, publish_module: ModuleType
monkeypatch: pytest.MonkeyPatch,
capsys: pytest.CaptureFixture[str],
publish_module: ModuleType,
) -> None:
"""Invoke ``uv publish`` without an index when none is provided."""
calls: list[list[str]] = []
Expand All @@ -35,10 +38,14 @@ def fake_run_cmd(args: list[str], **_: object) -> None:
publish_module.main(index="")

assert calls == [["uv", "publish"]]
captured = capsys.readouterr()
assert "Publishing with uv to default index (PyPI)" in captured.out


def test_publish_custom_index(
monkeypatch: pytest.MonkeyPatch, publish_module: ModuleType
monkeypatch: pytest.MonkeyPatch,
capsys: pytest.CaptureFixture[str],
publish_module: ModuleType,
) -> None:
"""Add the ``--index`` flag when a custom index value is supplied."""
calls: list[list[str]] = []
Expand All @@ -48,9 +55,11 @@ def fake_run_cmd(args: list[str], **_: object) -> None:

monkeypatch.setattr(publish_module, "run_cmd", fake_run_cmd)

publish_module.main(index="testpypi")
publish_module.main(index=" testpypi ")

assert calls == [["uv", "publish", "--index", "testpypi"]]
captured = capsys.readouterr()
assert "Publishing with uv to index 'testpypi'" in captured.out


def test_publish_run_cmd_error(
Expand All @@ -69,3 +78,61 @@ def fake_run_cmd(_: list[str], **__: object) -> None:

with pytest.raises(DummyError):
publish_module.main(index="")


def test_cli_proxies_to_main(
monkeypatch: pytest.MonkeyPatch, publish_module: ModuleType
) -> None:
"""Ensure the CLI entrypoint forwards arguments to ``main``."""
received: dict[str, str] = {}

def fake_main(*, index: str) -> None:
received["index"] = index

monkeypatch.setattr(publish_module, "main", fake_main)

publish_module.cli(index="mirror")

assert received == {"index": "mirror"}


def test_cli_runner_default_index(
monkeypatch: pytest.MonkeyPatch, publish_module: ModuleType
) -> None:
"""Exercise the CLI behaviour when no index is provided."""
calls: list[list[str]] = []

def fake_run_cmd(args: list[str], **_: object) -> None:
calls.append(args)

monkeypatch.setattr(publish_module, "run_cmd", fake_run_cmd)

runner = CliRunner()
app = publish_module.typer.Typer()
app.command()(publish_module.cli)
result = runner.invoke(app, [])

assert result.exit_code == 0
assert calls == [["uv", "publish"]]
assert "Publishing with uv to default index (PyPI)" in result.output


def test_cli_runner_respects_env_index(
monkeypatch: pytest.MonkeyPatch, publish_module: ModuleType
) -> None:
"""Accept the index from the GitHub Action input environment variable."""
calls: list[list[str]] = []

def fake_run_cmd(args: list[str], **_: object) -> None:
calls.append(args)

monkeypatch.setattr(publish_module, "run_cmd", fake_run_cmd)

runner = CliRunner()
app = publish_module.typer.Typer()
app.command()(publish_module.cli)
result = runner.invoke(app, [], env={"INPUT_UV_INDEX": "testpypi"})

assert result.exit_code == 0
assert calls == [["uv", "publish", "--index", "testpypi"]]
assert "Publishing with uv to index 'testpypi'" in result.output
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from types import ModuleType

import pytest
from typer.testing import CliRunner

from ._helpers import load_script_module

Expand All @@ -32,7 +33,7 @@ def _write_pyproject(base: Path, content: str) -> None:
(base / "pyproject.toml").write_text(content.strip())


def _invoke_main(module: ModuleType, **kwargs: str) -> None:
def _invoke_main(module: ModuleType, **kwargs: object) -> None:
"""Invoke ``module.main`` with defaults tailored for the tests."""
kwargs.setdefault("pattern", "**/pyproject.toml")
kwargs.setdefault("fail_on_dynamic", "false")
Expand Down Expand Up @@ -61,6 +62,28 @@ def test_passes_when_versions_match(
)


def test_cli_defaults_when_optional_parameters_omitted(
project_root: Path, module: ModuleType
) -> None:
"""Use default CLI values when optional flags are not provided."""
_write_pyproject(
project_root / "pkg",
"""
[project]
name = "demo"
version = "1.0.0"
""",
)

runner = CliRunner()
app = module.typer.Typer()
app.command()(module.main)
result = runner.invoke(app, ["--version", "1.0.0"])

assert result.exit_code == 0
assert "all versions match 1.0.0" in result.output


def test_fails_on_mismatch(
project_root: Path, module: ModuleType, capsys: pytest.CaptureFixture[str]
) -> None:
Expand Down Expand Up @@ -199,7 +222,7 @@ def test_dynamic_version_allowed_when_flag_unset(
""",
)

_invoke_main(module, version="1.0.0", fail_on_dynamic="")
Comment thread
leynos marked this conversation as resolved.
_invoke_main(module, version="1.0.0")

captured = capsys.readouterr()
assert "uses dynamic 'version'" in captured.out
Expand Down Expand Up @@ -297,6 +320,26 @@ def fake_glob(
assert discovered == [first, second]


def test_iter_files_discovers_paths_in_sorted_order(
project_root: Path,
module: ModuleType,
) -> None:
"""Ensure discovery order remains deterministic for reproducible output."""
for name in ("pkg_c", "pkg_a", "pkg_b"):
_write_pyproject(
project_root / name,
"""
[project]
name = "demo"
version = "1.0.0"
""",
)

discovered = list(module._iter_files("**/pyproject.toml"))
relative = [path.as_posix() for path in discovered]
assert relative == sorted(relative)


@pytest.mark.parametrize("value", ["true", "TRUE", "Yes", "1", "on"])
def test_parse_bool_truthy_values(module: ModuleType, value: str) -> None:
"""Treat recognised truthy values as ``True`` for configuration flags."""
Expand Down
49 changes: 46 additions & 3 deletions .github/actions/rust-build-release/tests/test_cross_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
CMD_MOX_UNSUPPORTED,
_register_cross_version_stub,
_register_docker_info_stub,
_register_podman_info_stub,
_register_rustup_toolchain_stub,
)

Expand Down Expand Up @@ -421,9 +422,14 @@ def fake_which(name: str) -> str | None:
cmd_mox.verify()

assert len(harness.calls) == 2
assert "--git" in harness.calls[1]
assert "--tag" in harness.calls[1]
assert "v0.2.5" in harness.calls[1]
first, second = harness.calls
# First attempt was crates.io
assert "--git" not in first
assert "--tag" not in first
# Second attempt is the git fallback with a tag
assert "--git" in second
assert "--tag" in second
assert "v0.2.5" in second
assert path == cross_path
assert ver == "0.2.5"

Expand Down Expand Up @@ -463,6 +469,43 @@ def fake_which(name: str) -> str | None:
assert all(cmd[0] != "cross" for cmd in app_env.calls)


@CMD_MOX_UNSUPPORTED
def test_falls_back_to_cargo_when_podman_unusable(
main_module: ModuleType,
cross_module: ModuleType,
module_harness: HarnessFactory,
cmd_mox: CmdMox,
) -> None:
"""Falls back to cargo when podman exists but is unusable."""
cross_env = module_harness(cross_module)
app_env = module_harness(main_module)

default_toolchain = main_module.DEFAULT_TOOLCHAIN
rustup_stdout = f"{default_toolchain}-x86_64-unknown-linux-gnu\n"
cross_path = _register_cross_version_stub(cmd_mox)
rustup_path = _register_rustup_toolchain_stub(cmd_mox, rustup_stdout)
podman_path = _register_podman_info_stub(cmd_mox, exit_code=1)

def fake_which(name: str) -> str | None:
if name == "podman":
return podman_path
if name == "cross":
return cross_path
if name == "rustup":
return rustup_path
return None

cross_env.patch_shutil_which(fake_which)
app_env.patch_shutil_which(fake_which)

cmd_mox.replay()
main_module.main("x86_64-unknown-linux-gnu", default_toolchain)
cmd_mox.verify()

assert any(cmd[0] == "cargo" for cmd in app_env.calls)
assert all(cmd[0] != "cross" for cmd in app_env.calls)


def test_returns_none_when_install_fails_on_windows(
cross_module: ModuleType,
module_harness: HarnessFactory,
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test: .venv ## Run tests
lint: ## Check test scripts and actions
uvx ruff check
find .github/actions -type f \( -name 'action.yml' -o -name 'action.yaml' \) -print0 \
| xargs -r -0 -n1 ${HOME}/.bun/bin/action-validator
| xargs -r -0 -n1 bunx -y @action-validator/cli

typecheck: .venv ## Run static type checking with Ty
./.venv/bin/ty check \
Expand Down
Loading