mirror of
https://github.com/d9pouces/id_configurator.git
synced 2026-11-09 01:47:21 +01:00
a8143b61b1
Signed-off-by: d9pouces <github@19pouces.net>
48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
"""Build a minimal, offline, hand-rolled Go module proxy tree, for
|
|
integration-testing the `go` module of id-configurator.
|
|
|
|
No network access and no Go toolchain is used: the module proxy protocol
|
|
(https://go.dev/ref/mod#module-proxy) only requires a handful of static
|
|
files, none of which embed the server's own base URL (unlike Composer/
|
|
npm/cargo), so this can be served directly by nginx with no rewriting.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
import json
|
|
import pathlib
|
|
import zipfile
|
|
|
|
MODULE = "example.invalid/idconfiguratortestpkg"
|
|
VERSION = "v0.0.1"
|
|
OUT_DIR = pathlib.Path("/srv")
|
|
MARKER = "test-only module served by the id-configurator integration tests\n"
|
|
|
|
GO_MOD = f"module {MODULE}\n\ngo 1.21\n"
|
|
|
|
|
|
def build_zip() -> bytes:
|
|
buffer = io.BytesIO()
|
|
prefix = f"{MODULE}@{VERSION}"
|
|
with zipfile.ZipFile(buffer, "w") as archive:
|
|
archive.writestr(f"{prefix}/go.mod", GO_MOD)
|
|
archive.writestr(f"{prefix}/marker.txt", MARKER)
|
|
return buffer.getvalue()
|
|
|
|
|
|
def main() -> None:
|
|
module_dir = OUT_DIR / MODULE / "@v"
|
|
module_dir.mkdir(parents=True, exist_ok=True)
|
|
(module_dir / "list").write_text(f"{VERSION}\n", encoding="utf-8")
|
|
(module_dir / f"{VERSION}.info").write_text(
|
|
json.dumps({"Version": VERSION, "Time": "2024-01-01T00:00:00Z"}),
|
|
encoding="utf-8",
|
|
)
|
|
(module_dir / f"{VERSION}.mod").write_text(GO_MOD, encoding="utf-8")
|
|
(module_dir / f"{VERSION}.zip").write_bytes(build_zip())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|