Skip to content

Commit 844b783

Browse files
committed
do not attempt to cache me
Signed-off-by: William Woodruff <william@astral.sh>
1 parent bb9565f commit 844b783

2 files changed

Lines changed: 40 additions & 8 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ fix:
1414

1515
.PHONY: test
1616
test:
17-
uvx --with=requests --with-requirements=action.py pytest test.py
17+
uvx --with=requests --with-requirements=action.py pytest -s -o log_cli=true -o log_cli_level=DEBUG test.py

test.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import logging
12
import subprocess
3+
import time
24
import uuid
35
from pathlib import Path
46

@@ -8,16 +10,46 @@
810

911
import action
1012

13+
logger = logging.getLogger(__name__)
14+
1115

1216
@pytest.fixture(scope="session")
1317
def id_token() -> oidc.IdentityToken:
14-
resp = requests.get(
15-
"https://raw.githubusercontent.com/sigstore-conformance/extremely-dangerous-public-oidc-beacon/refs/heads/current-token/oidc-token.txt",
16-
params={"cachebuster": uuid.uuid4().hex},
17-
)
18-
resp.raise_for_status()
19-
id_token = resp.text.strip()
20-
return oidc.IdentityToken(id_token)
18+
def _id_token() -> oidc.IdentityToken | None:
19+
# GitHub loves to cache things it has no business caching.
20+
result = subprocess.run(
21+
[
22+
"git",
23+
"ls-remote",
24+
"https://github.com/sigstore-conformance/extremely-dangerous-public-oidc-beacon",
25+
"refs/heads/current-token",
26+
],
27+
capture_output=True,
28+
text=True,
29+
check=True,
30+
)
31+
ref = result.stdout.split()[0]
32+
33+
resp = requests.get(
34+
f"https://raw.githubusercontent.com/sigstore-conformance/extremely-dangerous-public-oidc-beacon/{ref}/oidc-token.txt",
35+
)
36+
resp.raise_for_status()
37+
id_token = resp.text.strip()
38+
try:
39+
return oidc.IdentityToken(id_token)
40+
except Exception:
41+
return None
42+
43+
# Try up to 10 times to get a valid token, waiting 3 seconds between attempts.
44+
for n in range(10):
45+
token = _id_token()
46+
if token is not None:
47+
return token
48+
else:
49+
logger.warning(f"Waiting for valid OIDC identity token, try {n}...")
50+
time.sleep(3)
51+
52+
raise RuntimeError("Failed to obtain OIDC identity token for tests")
2153

2254

2355
@pytest.fixture

0 commit comments

Comments
 (0)