|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Patch Hive's Lean simulator Dockerfile for CI. |
| 3 | +
|
| 4 | +The pinned Hive Dockerfile uses unauthenticated GitHub API `ADD` instructions |
| 5 | +as cache-busters for commit/release metadata. GitHub-hosted runners can hit the |
| 6 | +anonymous API rate limit there before Hive starts. Replace those remote fetches |
| 7 | +with local metadata stubs; the build still downloads the actual pinned assets |
| 8 | +through the later `git clone`/`curl` steps. |
| 9 | +""" |
| 10 | + |
| 11 | +from __future__ import annotations |
| 12 | + |
| 13 | +import pathlib |
| 14 | +import sys |
| 15 | + |
| 16 | + |
| 17 | +REPLACEMENTS = { |
| 18 | + "ADD ${LEAN_SPEC_DEVNET4_COMMIT_METADATA_URL} /tmp/devnet4-commit.json": |
| 19 | + 'RUN printf \'{"sha":"%s"}\\n\' "$devnet4_tag" > /tmp/devnet4-commit.json', |
| 20 | + "ADD ${LEAN_SPEC_DEVNET5_COMMIT_METADATA_URL} /tmp/devnet5-commit.json": |
| 21 | + 'RUN printf \'{"sha":"%s"}\\n\' "$devnet5_tag" > /tmp/devnet5-commit.json', |
| 22 | + "ADD ${LEAN_SPEC_TESTS_METADATA_URL} /tmp/lean-spec-tests-commit.json": |
| 23 | + 'RUN printf \'{"sha":"%s"}\\n\' "$lean_spec_tests_ref" > /tmp/lean-spec-tests-commit.json', |
| 24 | + "ADD ${LEAN_SPEC_FIXTURES_METADATA_URL} /tmp/devnet5-lean-spec-fixtures-release.json": |
| 25 | + 'RUN printf \'{"tag_name":"%s"}\\n\' "$lean_spec_fixtures_tag" > /tmp/devnet5-lean-spec-fixtures-release.json', |
| 26 | + "ADD ${LEAN_SPEC_DEVNET5_KEYS_METADATA_URL} /tmp/devnet5-keys-release.json": |
| 27 | + 'RUN printf \'{"tag_name":"%s"}\\n\' "$devnet5_keys_tag" > /tmp/devnet5-keys-release.json', |
| 28 | +} |
| 29 | + |
| 30 | + |
| 31 | +def main() -> int: |
| 32 | + dockerfile = pathlib.Path(sys.argv[1] if len(sys.argv) > 1 else "src/simulators/lean/Dockerfile") |
| 33 | + content = dockerfile.read_text() |
| 34 | + |
| 35 | + missing = [needle for needle in REPLACEMENTS if needle not in content] |
| 36 | + if missing: |
| 37 | + print("Hive Lean Dockerfile did not contain expected metadata ADD line(s):", file=sys.stderr) |
| 38 | + for needle in missing: |
| 39 | + print(f"- {needle}", file=sys.stderr) |
| 40 | + return 1 |
| 41 | + |
| 42 | + for needle, replacement in REPLACEMENTS.items(): |
| 43 | + content = content.replace(needle, replacement) |
| 44 | + |
| 45 | + if "ADD ${LEAN_SPEC_" in content: |
| 46 | + print("Hive Lean Dockerfile still contains a remote Lean metadata ADD", file=sys.stderr) |
| 47 | + return 1 |
| 48 | + |
| 49 | + dockerfile.write_text(content) |
| 50 | + print(f"Patched {dockerfile} to avoid unauthenticated GitHub API metadata fetches") |
| 51 | + return 0 |
| 52 | + |
| 53 | + |
| 54 | +if __name__ == "__main__": |
| 55 | + raise SystemExit(main()) |
0 commit comments