Updates to hello world.
This commit is contained in:
1 parent
6a02494ac8
commit
785569abdd
7 files changed
+177
-20
No files matched your search
+21
-1
@@ -3,11 +3,13 @@
|
||||
"""Check the repository and the built Tentacle without running a reader."""
|
||||
|
||||
import json
|
||||
import hashlib
|
||||
import os
|
||||
from pathlib import Path
|
||||
import select
|
||||
import subprocess
|
||||
import tomllib
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
||||
def require(condition, message):
|
||||
@@ -27,7 +29,8 @@ def check_metadata(repoRoot):
|
||||
"Unsupported metadata format")
|
||||
require(repository["id"] == "storm.cthulhu-tentacles" and repository["name"],
|
||||
"Repository identity is missing")
|
||||
require(catalog["tentacles"] == [{"id": "hello-world", "manifest": "hello-world/tentacle.toml"}],
|
||||
require(len(catalog["tentacles"]) == 1 and catalog["tentacles"][0]["id"] == "hello-world"
|
||||
and catalog["tentacles"][0]["manifest"] == "hello-world/tentacle.toml",
|
||||
"Catalog must list exactly Hello World")
|
||||
manifest = read_toml(repoRoot / catalog["tentacles"][0]["manifest"])
|
||||
require(manifest["format-version"] == 1 and manifest["id"] == "hello-world"
|
||||
@@ -38,6 +41,23 @@ def check_metadata(repoRoot):
|
||||
require((repoRoot / "LICENSE").is_file() and (repoRoot / "hello-world/LICENSE").is_file(),
|
||||
"Repository and Tentacle licenses are required")
|
||||
|
||||
seen = set()
|
||||
for release in catalog["tentacles"][0].get("releases", []):
|
||||
key = (release["platform"], release["architecture"])
|
||||
require(key not in seen and key[0] == "linux" and key[1] in ("amd64", "arm64"),
|
||||
"Invalid or duplicate release target")
|
||||
seen.add(key)
|
||||
parsed = urlparse(release["url"])
|
||||
require(parsed.scheme == "https" and parsed.hostname and not parsed.username
|
||||
and not parsed.fragment, "Release URL must be HTTPS without credentials")
|
||||
digest = release["sha256"]
|
||||
require(len(digest) == 64 and all(character in "0123456789abcdef" for character in digest),
|
||||
"Invalid SHA-256 digest")
|
||||
artifactPath = repoRoot / "dist" / parsed.path.rsplit("/", 1)[-1]
|
||||
if artifactPath.exists():
|
||||
require(hashlib.sha256(artifactPath.read_bytes()).hexdigest() == digest,
|
||||
"Prepared package does not match its catalog digest")
|
||||
|
||||
|
||||
def check_registration(programPath):
|
||||
with subprocess.Popen([str(programPath)], stdin=subprocess.PIPE,
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
# Copyright (c) 2026 Storm Dragon
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Build reproducible Hello World release artifacts and a catalog for review."""
|
||||
|
||||
import argparse
|
||||
import gzip
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tarfile
|
||||
import tomllib
|
||||
|
||||
|
||||
def build_package(repoRoot, architecture, version):
|
||||
distRoot = repoRoot / "dist"
|
||||
distRoot.mkdir(exist_ok=True)
|
||||
programPath = distRoot / f"hello-world-linux-{architecture}"
|
||||
environment = dict(os.environ, CGO_ENABLED="0", GOOS="linux", GOARCH=architecture)
|
||||
environment.setdefault("GOCACHE", "/tmp/cthulhu-go-cache")
|
||||
subprocess.run(["go", "build", "-buildvcs=false", "-mod=readonly", "-trimpath",
|
||||
"-ldflags=-s -w", "-o", str(programPath), "./hello-world/src"],
|
||||
cwd=repoRoot, env=environment, check=True)
|
||||
artifactPath = distRoot / f"hello-world-{version}-linux-{architecture}.tar.gz"
|
||||
with artifactPath.open("wb") as output:
|
||||
with gzip.GzipFile(filename="", mode="wb", fileobj=output, mtime=0) as compressed:
|
||||
with tarfile.open(fileobj=compressed, mode="w", format=tarfile.USTAR_FORMAT) as archive:
|
||||
for name, data, mode in [
|
||||
("tentacle.toml", (repoRoot / "hello-world/tentacle.toml").read_bytes(), 0o644),
|
||||
("README.md", (repoRoot / "hello-world/README.md").read_bytes(), 0o644),
|
||||
("LICENSE", (repoRoot / "hello-world/LICENSE").read_bytes(), 0o644),
|
||||
("bin/hello-world", programPath.read_bytes(), 0o755),
|
||||
]:
|
||||
member = tarfile.TarInfo(name)
|
||||
member.size, member.mode, member.mtime = len(data), mode, 0
|
||||
archive.addfile(member, io.BytesIO(data))
|
||||
digest = hashlib.sha256(artifactPath.read_bytes()).hexdigest()
|
||||
return artifactPath, digest
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--architecture", nargs="+", choices=["amd64", "arm64"], default=["amd64", "arm64"])
|
||||
args = parser.parse_args()
|
||||
if len(set(args.architecture)) != len(args.architecture):
|
||||
parser.error("Architectures must not be repeated")
|
||||
repoRoot = Path(__file__).resolve().parents[1]
|
||||
manifest = tomllib.loads((repoRoot / "hello-world/tentacle.toml").read_text())
|
||||
version = manifest["version"]
|
||||
if not version or any(character not in "0123456789abcdefghijklmnopqrstuvwxyz.-" for character in version):
|
||||
raise ValueError("Version must be safe for release filenames")
|
||||
lines = ["format-version = 1", "", "[[tentacles]]", 'id = "hello-world"',
|
||||
'manifest = "hello-world/tentacle.toml"']
|
||||
checksums = []
|
||||
for architecture in args.architecture:
|
||||
artifactPath, digest = build_package(repoRoot, architecture, version)
|
||||
releaseURL = f"https://git.stormux.org/storm/cthulhu-tentacles/releases/download/hello-world-v{version}/{artifactPath.name}"
|
||||
lines += ["", "[[tentacles.releases]]", 'platform = "linux"',
|
||||
f"architecture = {json.dumps(architecture)}", f"url = {json.dumps(releaseURL)}",
|
||||
f"sha256 = {json.dumps(digest)}"]
|
||||
checksums.append(f"{digest} {artifactPath.name}")
|
||||
print(f"Prepared {artifactPath.name}: {digest}")
|
||||
(repoRoot / "dist/catalog.toml").write_text("\n".join(lines) + "\n")
|
||||
(repoRoot / "dist/SHA256SUMS").write_text("\n".join(checksums) + "\n")
|
||||
print("Prepared dist/catalog.toml and dist/SHA256SUMS for review. Nothing was published.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user