127 lines
6.8 KiB
Rust
127 lines
6.8 KiB
Rust
//! Assemble only the two Linux release bundles produced by the native workflow.
|
|
//! The host-specific verifier inspects payload bytes before uploading the bundle;
|
|
//! assembly rechecks its receipts, canonical metadata and every artifact digest.
|
|
use std::{collections::BTreeSet, env, fs, path::Path};
|
|
use serde_json::{Value, json};
|
|
use crate::{Options, deps, package, verify_package};
|
|
|
|
const TARGETS: [&str; 2] = ["x86_64-unknown-linux-gnu", "aarch64-unknown-linux-gnu"];
|
|
|
|
pub(crate) fn check_version(root: &Path) -> Result<(), String> {
|
|
let version = package::version(root)?;
|
|
if let Ok(reference) = env::var("GITHUB_REF") {
|
|
if let Some(tag) = reference.strip_prefix("refs/tags/") {
|
|
if tag != format!("v{version}") {
|
|
return Err(format!("release tag {tag:?} does not match workspace version v{version}"));
|
|
}
|
|
}
|
|
}
|
|
println!("Native workspace version: {version}");
|
|
Ok(())
|
|
}
|
|
|
|
pub(crate) fn prepare(root: &Path, options: &Options, publish: bool) -> Result<(), String> {
|
|
check_version(root)?;
|
|
let version = package::version(root)?;
|
|
let out = package::output_dir(root, options);
|
|
let mut merged = json!({"schema":1,"engine":"rust-slint","version":version,"artifacts":[]});
|
|
let mut uploads = Vec::new();
|
|
let mut names = BTreeSet::new();
|
|
for triple in TARGETS {
|
|
let target = deps::Target::parse(triple)?;
|
|
let bundle = out.join(format!("teamspeach-native-{triple}"));
|
|
let manifest = package::merge_manifest(package::json_file(&bundle.join("native-manifest.json"))?, &version, &[])?;
|
|
let entries = manifest["artifacts"].as_array().ok_or("missing native artifacts")?;
|
|
let kinds: BTreeSet<_> = entries.iter().filter_map(|entry| entry["kind"].as_str()).collect();
|
|
if entries.len() != 2 || kinds != BTreeSet::from(["appimage", "tar.gz"]) || entries.iter().any(|entry| entry["target"] != triple) {
|
|
return Err(format!("{triple} requires exactly its native AppImage and tar.gz"));
|
|
}
|
|
let work = bundle.join(triple);
|
|
let report = package::json_file(&work.join("package-report.json"))?;
|
|
let verification = package::json_file(&work.join("verification.json"))?;
|
|
for receipt in [&report, &verification] {
|
|
if receipt["schema"] != 1 || receipt["engine"] != "rust-slint" || receipt["version"] != version || receipt["target"] != triple {
|
|
return Err(format!("invalid {triple} package/verification identity"));
|
|
}
|
|
}
|
|
if report["testOnly"] != false || report["sourceBuild"]["testHarness"] != false || report["sourceBuild"]["version"] != version || report["sourceBuild"]["target"] != triple || verification["passed"] != true {
|
|
return Err(format!("{triple} is not a verified production build"));
|
|
}
|
|
let reported = report["artifacts"].as_array().ok_or("missing package report artifacts")?;
|
|
let verified = verification["artifacts"].as_array().ok_or("missing payload verification results")?;
|
|
if reported.len() != entries.len() || verified.len() != entries.len() {
|
|
return Err("release package/verification artifact set mismatch".into());
|
|
}
|
|
for entry in entries {
|
|
let name = entry["name"].as_str().ok_or("missing artifact name")?;
|
|
let path = bundle.join(name);
|
|
if fs::symlink_metadata(&path).map_err(|e| e.to_string())?.file_type().is_symlink() {
|
|
return Err("release artifact symlink refused".into());
|
|
}
|
|
if package::record(&path, target, entry["kind"].as_str().unwrap())? != *entry {
|
|
return Err(format!("release artifact bytes mismatch: {name}"));
|
|
}
|
|
if reported.iter().filter(|local| local["name"] == name && local["release_eligible"] == true && ["target", "kind", "name", "size", "sha512"].iter().all(|key| local[*key] == entry[*key])).count() != 1 || verified.iter().filter(|result| result["artifact"] == name).count() != 1 {
|
|
return Err(format!("artifact lacks matching packaging/inspection receipt: {name}"));
|
|
}
|
|
add_upload(&path, name, &mut names, &mut uploads)?;
|
|
}
|
|
verify_package::verify_yaml(&bundle, &version, &manifest)?;
|
|
let channel = package::update_channel(&version);
|
|
let suffix = if target.cpu == "arm64" { "-linux-arm64" } else { "-linux" };
|
|
let feed = format!("{channel}{suffix}.yml");
|
|
add_upload(&bundle.join(&feed), &feed, &mut names, &mut uploads)?;
|
|
for file in ["package-report.json", "verification.json", "native-deps.lock.json"] {
|
|
add_upload(&work.join(file), &format!("{triple}-{file}"), &mut names, &mut uploads)?;
|
|
}
|
|
merged = package::merge_manifest(merged, &version, entries)?;
|
|
}
|
|
let manifest_path = out.join("native-manifest.json");
|
|
package::save(&manifest_path, &merged)?;
|
|
add_upload(&manifest_path, "native-manifest.json", &mut names, &mut uploads)?;
|
|
let commit = deps::capture(std::process::Command::new("git").current_dir(root).args(["rev-parse", "HEAD"]))?;
|
|
let plan = json!({"schema":1,"engine":"rust-slint","version":version,"commit":commit.trim(),"assets":uploads});
|
|
let plan_path = out.join("release-assets.json");
|
|
package::save(&plan_path, &plan)?;
|
|
println!("Validated native release plan: {}", plan_path.display());
|
|
if publish {
|
|
let python = env::var_os("PYTHON").unwrap_or_else(|| "python3".into());
|
|
deps::run(std::process::Command::new(python).arg(root.join("xtask/publish_release.py")).arg(&plan_path))?;
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
fn add_upload(path: &Path, name: &str, names: &mut BTreeSet<String>, uploads: &mut Vec<Value>) -> Result<(), String> {
|
|
if !names.insert(name.to_owned()) { return Err(format!("duplicate release asset {name}")); }
|
|
let path = fs::canonicalize(path).map_err(|e| format!("{}: {e}", path.display()))?;
|
|
deps::require_file(&path)?;
|
|
uploads.push(json!({"path":path,"name":name,"size":fs::metadata(&path).map_err(|e| e.to_string())?.len(),"sha512":package::sha512(&path)?}));
|
|
Ok(())
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn native_feed_channels_follow_semver_prerelease_components() {
|
|
for (version, channel) in [
|
|
("0.1.7", "latest"),
|
|
("0.1.7-rc.2", "rc"),
|
|
("0.1.7-preview.1+build", "preview"),
|
|
("0.1.7+build-with-hyphen", "latest"),
|
|
] {
|
|
assert_eq!(package::update_channel(version), channel);
|
|
}
|
|
}
|
|
|
|
|
|
#[test]
|
|
fn release_upload_rejects_duplicate_names_before_reading_paths() {
|
|
let mut names = BTreeSet::from(["native-manifest.json".to_owned()]);
|
|
let mut uploads = Vec::new();
|
|
assert!(add_upload(Path::new("absent"), "native-manifest.json", &mut names, &mut uploads).is_err());
|
|
assert!(uploads.is_empty());
|
|
}
|
|
}
|