Add documentation metadata for Orbit packages

This commit is contained in:
nandi committed 2026-11-26 20:38:29 -08:00
1 parent 49739fc9f9
commit 28b13e7a96
6 files changed
+84 -4

No files matched your search

+57 -2
View File
@@ -121,7 +121,61 @@ fn fetch_into_store(
}
///|
/// Pack `<dir>/files` and push it with `<dir>/orbit.json` as the config blob.
/// Gitea reads package-page metadata from OCI image config labels, not
/// manifest annotations. Keep the Orbit manifest at the top level for pulls.
fn package_config(text : String, m : Manifest) -> String raise OrbitError {
if m.description == "" && m.documentation == "" {
return text
}
let config = parse_object(text, "orbit.json")
let image = match config.get("config") {
Some(Json::Object(image)) => image
None => Map([])
_ => raise OrbitError("orbit.json: config must be an object")
}
let labels = match image.get("Labels") {
Some(Json::Object(labels)) => labels
None => Map([])
_ => raise OrbitError("orbit.json: config.Labels must be an object")
}
if m.description != "" {
labels["org.opencontainers.image.description"] = Json::string(m.description)
}
if m.documentation != "" {
labels["org.opencontainers.image.documentation"] = Json::string(
m.documentation,
)
}
image["Labels"] = Json::object(labels)
config["config"] = Json::object(image)
Json::object(config).stringify(indent=2) + "\n"
}
///|
test "package config exposes Gitea labels and preserves Orbit metadata" {
let text =
#|{"name":"greet","version":"1.0.1","description":"A greeting","documentation":"https://example.com/greet","depends":{"hello":"^1"},"config":{"Labels":{"custom":"keep"}}}
let published = package_config(text, parse_manifest(text))
let m = parse_manifest(published)
assert_eq(m.name, "greet")
assert_eq(m.depends.get("hello"), Some("^1"))
let config = parse_object(published, "orbit.json")
guard config.get("config") is Some(Json::Object(image)) else {
fail("missing OCI config")
}
guard image.get("Labels") is Some(Json::Object(labels)) else {
fail("missing OCI labels")
}
assert_eq(jstr(labels, "custom", ""), "keep")
assert_eq(jstr(labels, "org.opencontainers.image.description", ""), "A greeting")
assert_eq(
jstr(labels, "org.opencontainers.image.documentation", ""),
"https://example.com/greet",
)
}
///|
/// Pack `<dir>/files` and push it with the enriched Orbit config blob.
fn publish(
ch : Channel,
dir : String,
@@ -132,6 +186,7 @@ fn publish(
None => raise OrbitError("\{dir}/orbit.json not found")
}
let m = parse_manifest(text)
let config = package_config(text, m)
let files = dir + "/files"
if !exists(files) {
raise OrbitError("\{files} not found (package contents go in files/)")
@@ -149,7 +204,7 @@ fn publish(
sq(files) +
" .",
)
sh_ok("cp " + sq(dir + "/orbit.json") + " " + sq(tmp + "/orbit.json"))
write_text_atomic(tmp + "/orbit.json", config)
let tags = if also_latest { m.version + ",latest" } else { m.version }
let push = oras(
ch,