Skip to content

Commit dd1ad2b

Browse files
authored
Pass client_sha and client_sha_url as pytest metadata (#288)
* Pass client_sha and client_sha_url as pytest metadata * Do the same for workflow_run * Inject environment variables directly into JSON report * Drop pytest-metadata as a top level dep
1 parent e791f60 commit dd1ad2b

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

.github/scripts/generate_client_report.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,18 @@ def __init__(self, report_path: Path):
2929
data = json.load(f)
3030

3131
self.name = report_path.name.replace(".json", "")
32-
self.client_sha = os.getenv("GHA_SIGSTORE_CONFORMANCE_CLIENT_SHA", "")
33-
self.client_sha_url = os.getenv("GHA_SIGSTORE_CONFORMANCE_CLIENT_SHA_URL", "")
34-
self.workflow_run = os.getenv("GHA_SIGSTORE_CONFORMANCE_WORKFLOW_RUN", "")
3532

3633
if data == {}:
3734
return # no results found
3835
self.results_found = True
3936

40-
self.conformance_action_version = data.get("environment", {}).get(
37+
environment = data.get("environment", {})
38+
self.conformance_action_version = environment.get(
4139
"conformance_action_version", "unknown"
4240
)
41+
self.client_sha = environment.get("client_sha", "")
42+
self.client_sha_url = environment.get("client_sha_url", "")
43+
self.workflow_run = environment.get("workflow_run", "")
4344

4445
summary = data["summary"]
4546
self.total = summary["total"]

action.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ def _debug(msg):
3030
def _sigstore_conformance(environment: str) -> int:
3131
args = ["--json-report", "--json-report-file=conformance-report.json", "--durations=0"]
3232

33-
version = os.getenv("GHA_SIGSTORE_CONFORMANCE_ACTION_VERSION", "unknown")
34-
args.extend(["--metadata", "conformance_action_version", version])
33+
3534

3635
if _DEBUG:
3736
args.extend(["-s", "-vv", "--showlocals"])
@@ -52,7 +51,30 @@ def _sigstore_conformance(environment: str) -> int:
5251
print(f"running sigstore-conformance against Sigstore {environment} infrastructure")
5352
_debug(f"running: sigstore-conformance {[str(a) for a in args]}")
5453

55-
return pytest.main([str(_ACTION_PATH / "test"), *args])
54+
status = pytest.main([str(_ACTION_PATH / "test"), *args])
55+
56+
# Inject the action version into the report
57+
with open("conformance-report.json", "r+") as f:
58+
report_data = json.load(f)
59+
if "environment" not in report_data:
60+
report_data["environment"] = {}
61+
report_data["environment"]["conformance_action_version"] = os.getenv(
62+
"GHA_SIGSTORE_CONFORMANCE_ACTION_VERSION", "unknown"
63+
)
64+
client_sha = os.getenv("GHA_SIGSTORE_CONFORMANCE_CLIENT_SHA")
65+
if client_sha:
66+
report_data["environment"]["client_sha"] = client_sha
67+
client_sha_url = os.getenv("GHA_SIGSTORE_CONFORMANCE_CLIENT_SHA_URL")
68+
if client_sha_url:
69+
report_data["environment"]["client_sha_url"] = client_sha_url
70+
workflow_run = os.getenv("GHA_SIGSTORE_CONFORMANCE_WORKFLOW_RUN")
71+
if workflow_run:
72+
report_data["environment"]["workflow_run"] = workflow_run
73+
f.seek(0)
74+
json.dump(report_data, f, indent=4)
75+
f.truncate()
76+
77+
return status
5678

5779

5880
# Run against chosen environment

requirements.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
pytest==9.0.0
22
pytest-json-report==1.5.0
3-
pytest-metadata==3.1.1
43
pytest-subtests==0.15.0
54
requests==2.32.5
65
cryptography==46.0.3

requirements.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,7 @@ pytest-json-report==1.5.0 \
607607
pytest-metadata==3.1.1 \
608608
--hash=sha256:c8e0844db684ee1c798cfa38908d20d67d0463ecb6137c72e91f418558dd5f4b \
609609
--hash=sha256:d2a29b0355fbc03f168aa96d41ff88b1a3b44a3b02acbe491801c98a048017c8
610-
# via
611-
# -r requirements.in
612-
# pytest-json-report
610+
# via pytest-json-report
613611
pytest-subtests==0.15.0 \
614612
--hash=sha256:cb495bde05551b784b8f0b8adfaa27edb4131469a27c339b80fd8d6ba33f887c \
615613
--hash=sha256:da2d0ce348e1f8d831d5a40d81e3aeac439fec50bd5251cbb7791402696a9493

0 commit comments

Comments
 (0)