Skip to content

Commit d5bdc40

Browse files
authored
action: add a fatal error if no dists were collected (#15)
1 parent 2c72773 commit d5bdc40

File tree

4 files changed

+75
-4
lines changed

4 files changed

+75
-4
lines changed

action.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ def _collect_dists(patterns: set[str]) -> list[tuple[Path, Distribution]]:
113113
"""
114114

115115
files = _unroll_files(patterns)
116-
dists = []
117116

117+
dists = []
118118
for file in files:
119119
try:
120120
dist = Distribution.from_file(file)
@@ -162,6 +162,13 @@ def _attest(
162162
and an error will be raised instead.
163163
"""
164164

165+
if not dists:
166+
_fatal(
167+
"No distributions to attest",
168+
detail="No valid Python distributions were collected from the specified paths.",
169+
tip="Ensure that the `paths` input points to valid distribution files.",
170+
)
171+
165172
# Before setting up any signing state, precompute the paths we intend
166173
# to write attestations to (and fail if any already exist and overwrite
167174
# is disabled).

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ classifiers = [
1616

1717
[dependency-groups]
1818
dev = [
19+
"inline-snapshot>=0.31.1",
1920
"pyright>=1.1.407",
2021
"pytest>=9.0.1",
2122
"requests>=2.32.5",

test.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import pytest
77
import requests
8+
from inline_snapshot import snapshot
89
from pypi_attestations import Attestation, GitHubPublisher
910
from sigstore import oidc
1011

@@ -14,11 +15,16 @@
1415

1516

1617
@pytest.fixture(autouse=True)
17-
def suppress_summary(monkeypatch: pytest.MonkeyPatch) -> None:
18+
def capture_summary(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> Path:
1819
"""
19-
Prevent writing to the GitHub Actions job summary during tests.
20+
Capture the GitHub Actions job summary to a temporary file.
2021
"""
21-
monkeypatch.delenv("GITHUB_STEP_SUMMARY", raising=False)
22+
23+
summary_path = tmp_path / "GITHUB_STEP_SUMMARY"
24+
summary_path.touch()
25+
monkeypatch.setenv("GITHUB_STEP_SUMMARY", str(summary_path))
26+
27+
return summary_path
2228

2329

2430
@pytest.fixture(scope="session")
@@ -213,3 +219,24 @@ def test_attest_verify(
213219
dist=dist,
214220
offline=True,
215221
)
222+
223+
224+
def test_attest_no_dists(
225+
id_token: oidc.IdentityToken,
226+
capture_summary: Path,
227+
) -> None:
228+
with pytest.raises(SystemExit):
229+
action._attest(
230+
[],
231+
id_token,
232+
overwrite=False,
233+
)
234+
235+
assert capture_summary.read_text() == snapshot("""\
236+
### ❌ Fatal: No distributions to attest
237+
238+
No valid Python distributions were collected from the specified paths.
239+
240+
> [!TIP]
241+
> Ensure that the `paths` input points to valid distribution files.
242+
""")

uv.lock

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)