Now runs both appimage and deb tests

pull/1991/head
jLynx 9 months ago
parent 7346ade132
commit 5a95db813b

@ -211,206 +211,213 @@ fn update_app() {
Updater::String(V1Compatible::V1Compatible) Updater::String(V1Compatible::V1Compatible)
); );
// bundle app update #[cfg(target_os = "linux")]
build_app(&manifest_dir, &config, true, Default::default()); let bundle_targets = vec![BundleTarget::AppImage, BundleTarget::Deb];
#[cfg(not(target_os = "linux"))]
let updater_zip_ext = if v1_compatible { let bundle_targets = vec![BundleTarget::default()];
if cfg!(windows) {
Some("zip") for bundle_target in bundle_targets {
} else { // bundle app update
build_app(&manifest_dir, &config, true, bundle_target);
let updater_zip_ext = if v1_compatible {
if cfg!(windows) {
Some("zip")
} else {
Some("tar.gz")
}
} else if cfg!(target_os = "macos") {
Some("tar.gz") Some("tar.gz")
}
} else if cfg!(target_os = "macos") {
Some("tar.gz")
} else {
None
};
for (bundle_target, out_bundle_path) in bundle_paths(&root_dir, "1.0.0") {
let bundle_updater_ext = if v1_compatible {
out_bundle_path
.extension()
.unwrap()
.to_str()
.unwrap()
.replace("exe", "nsis")
} else { } else {
out_bundle_path None
.extension()
.unwrap()
.to_str()
.unwrap()
.to_string()
}; };
let updater_extension = if let Some(updater_zip_ext) = updater_zip_ext {
format!("{bundle_updater_ext}.{updater_zip_ext}") for (bundle_target, out_bundle_path) in bundle_paths(&root_dir, "1.0.0") {
} else { let bundle_updater_ext = if v1_compatible {
bundle_updater_ext out_bundle_path
}; .extension()
let signature_extension = format!("{updater_extension}.sig"); .unwrap()
let signature_path = out_bundle_path.with_extension(signature_extension); .to_str()
let signature = std::fs::read_to_string(&signature_path).unwrap_or_else(|_| { .unwrap()
panic!("failed to read signature file {}", signature_path.display()) .replace("exe", "nsis")
}); } else {
let out_updater_path = out_bundle_path.with_extension(updater_extension); out_bundle_path
let updater_path = root_dir.join(format!( .extension()
"target/debug/{}", .unwrap()
out_updater_path.file_name().unwrap().to_str().unwrap() .to_str()
)); .unwrap()
std::fs::rename(&out_updater_path, &updater_path).expect("failed to rename bundle"); .to_string()
};
let target = target.clone(); let updater_extension = if let Some(updater_zip_ext) = updater_zip_ext {
format!("{bundle_updater_ext}.{updater_zip_ext}")
// start the updater server } else {
let server = Arc::new( bundle_updater_ext
tiny_http::Server::http("localhost:3007") };
.expect("failed to start updater server"), let signature_extension = format!("{updater_extension}.sig");
); let signature_path = out_bundle_path.with_extension(signature_extension);
let signature = std::fs::read_to_string(&signature_path).unwrap_or_else(|_| {
let server_ = server.clone(); panic!("failed to read signature file {}", signature_path.display())
std::thread::spawn(move || { });
for request in server_.incoming_requests() { let out_updater_path = out_bundle_path.with_extension(updater_extension);
match request.url() { let updater_path = root_dir.join(format!(
"/" => { "target/debug/{}",
let mut platforms = HashMap::new(); out_updater_path.file_name().unwrap().to_str().unwrap()
));
platforms.insert( std::fs::rename(&out_updater_path, &updater_path)
target.clone(), .expect("failed to rename bundle");
PlatformUpdate {
signature: signature.clone(), let target = target.clone();
url: "http://localhost:3007/download",
with_elevated_task: false, // start the updater server
}, let server = Arc::new(
); tiny_http::Server::http("localhost:3007")
let body = serde_json::to_vec(&Update { .expect("failed to start updater server"),
version: "1.0.0", );
date: time::OffsetDateTime::now_utc()
.format(&time::format_description::well_known::Rfc3339) let server_ = server.clone();
.unwrap(), std::thread::spawn(move || {
platforms, for request in server_.incoming_requests() {
}) match request.url() {
.unwrap(); "/" => {
let len = body.len(); let mut platforms = HashMap::new();
let response = tiny_http::Response::new(
tiny_http::StatusCode(200), platforms.insert(
Vec::new(), target.clone(),
std::io::Cursor::new(body), PlatformUpdate {
Some(len), signature: signature.clone(),
None, url: "http://localhost:3007/download",
); with_elevated_task: false,
let _ = request.respond(response); },
} );
"/download" => { let body = serde_json::to_vec(&Update {
let _ = request.respond(tiny_http::Response::from_file( version: "1.0.0",
File::open(&updater_path).unwrap_or_else(|_| { date: time::OffsetDateTime::now_utc()
panic!( .format(&time::format_description::well_known::Rfc3339)
"failed to open updater bundle {}", .unwrap(),
updater_path.display() platforms,
) })
}), .unwrap();
)); let len = body.len();
let response = tiny_http::Response::new(
tiny_http::StatusCode(200),
Vec::new(),
std::io::Cursor::new(body),
Some(len),
None,
);
let _ = request.respond(response);
}
"/download" => {
let _ = request.respond(tiny_http::Response::from_file(
File::open(&updater_path).unwrap_or_else(|_| {
panic!(
"failed to open updater bundle {}",
updater_path.display()
)
}),
));
}
_ => (),
} }
_ => (),
} }
} });
});
config.version = "0.1.0";
config.version = "0.1.0";
// bundle initial app version
// bundle initial app version build_app(&manifest_dir, &config, false, bundle_target);
build_app(&manifest_dir, &config, false, bundle_target);
// Set appropriate permissions and install package if needed
// Set appropriate permissions and install package if needed #[cfg(target_os = "linux")]
#[cfg(target_os = "linux")] {
{ let bundle_path = &out_bundle_path;
let paths = bundle_paths(&root_dir, "0.1.0");
let bundle_path = &paths.first().unwrap().1; if bundle_target == BundleTarget::AppImage {
std::process::Command::new("sudo")
if bundle_target == BundleTarget::AppImage { .arg("chmod")
std::process::Command::new("sudo") .arg("+x")
.arg("chmod") .arg(bundle_path)
.arg("+x") .status()
.arg(bundle_path) .expect("failed to change permissions");
.status() } else if bundle_target == BundleTarget::Deb {
.expect("failed to change permissions"); // Install the .deb package
} else if bundle_target == BundleTarget::Deb { let install_status = std::process::Command::new("sudo")
// Install the .deb package .arg("dpkg")
let install_status = std::process::Command::new("sudo") .arg("-i")
.arg("dpkg") .arg(bundle_path)
.arg("-i") .status()
.arg(bundle_path) .expect("failed to install .deb package");
.status()
.expect("failed to install .deb package"); if !install_status.success() {
panic!("Failed to install .deb package");
if !install_status.success() { }
panic!("Failed to install .deb package");
} }
} }
}
let status_checks = if matches!(bundle_target, BundleTarget::Msi) {
vec![UPDATED_EXIT_CODE]
} else {
vec![UPDATED_EXIT_CODE, UP_TO_DATE_EXIT_CODE]
};
for expected_exit_code in status_checks { let status_checks = if matches!(bundle_target, BundleTarget::Msi) {
let mut binary_cmd = if cfg!(windows) { vec![UPDATED_EXIT_CODE]
Command::new(root_dir.join("target/debug/app-updater.exe"))
} else if cfg!(target_os = "macos") {
Command::new(
bundle_paths(&root_dir, "0.1.0")
.first()
.unwrap()
.1
.join("Contents/MacOS/app-updater"),
)
} else if std::env::var("CI").map(|v| v == "true").unwrap_or_default() {
let mut c = Command::new("xvfb-run");
c.arg("--auto-servernum");
#[cfg(target_os = "linux")]
if bundle_target == BundleTarget::Deb {
c.arg("/usr/bin/app-updater");
} else {
c.arg(&bundle_paths(&root_dir, "0.1.0").first().unwrap().1);
}
c
} else { } else {
#[cfg(target_os = "linux")] vec![UPDATED_EXIT_CODE, UP_TO_DATE_EXIT_CODE]
{ };
let mut c = Command::new("sudo");
for expected_exit_code in status_checks {
let mut binary_cmd = if cfg!(windows) {
Command::new(root_dir.join("target/debug/app-updater.exe"))
} else if cfg!(target_os = "macos") {
Command::new(
bundle_paths(&root_dir, "0.1.0")
.first()
.unwrap()
.1
.join("Contents/MacOS/app-updater"),
)
} else if std::env::var("CI").map(|v| v == "true").unwrap_or_default() {
let mut c = Command::new("xvfb-run");
c.arg("--auto-servernum");
#[cfg(target_os = "linux")]
if bundle_target == BundleTarget::Deb { if bundle_target == BundleTarget::Deb {
c.arg("/usr/bin/app-updater"); c.arg("/usr/bin/app-updater");
} else { } else {
c.arg(&bundle_paths(&root_dir, "0.1.0").first().unwrap().1); c.arg(&bundle_paths(&root_dir, "0.1.0").first().unwrap().1);
} }
c c
} } else {
#[cfg(not(target_os = "linux"))] #[cfg(target_os = "linux")]
{ {
Command::new(&bundle_paths(&root_dir, "0.1.0").first().unwrap().1) let mut c = Command::new("sudo");
} if bundle_target == BundleTarget::Deb {
}; c.arg("/usr/bin/app-updater");
} else {
c.arg(&bundle_paths(&root_dir, "0.1.0").first().unwrap().1);
}
c
}
#[cfg(not(target_os = "linux"))]
{
Command::new(&bundle_paths(&root_dir, "0.1.0").first().unwrap().1)
}
};
binary_cmd.env("TARGET", bundle_target.name()); binary_cmd.env("TARGET", bundle_target.name());
let status = binary_cmd.status().expect("failed to run app"); let status = binary_cmd.status().expect("failed to run app");
let code = status.code().unwrap_or(-1); let code = status.code().unwrap_or(-1);
if code != expected_exit_code { if code != expected_exit_code {
panic!( panic!(
"failed to run app, expected exit code {expected_exit_code}, got {code}" "failed to run app, expected exit code {expected_exit_code}, got {code}"
); );
} }
#[cfg(windows)] #[cfg(windows)]
if code == UPDATED_EXIT_CODE { if code == UPDATED_EXIT_CODE {
// wait for the update to finish // wait for the update to finish
std::thread::sleep(std::time::Duration::from_secs(5)); std::thread::sleep(std::time::Duration::from_secs(5));
}
} }
}
// graceful shutdown // graceful shutdown
server.unblock(); server.unblock();
}
} }
} }
}); });

Loading…
Cancel
Save