|
|
|
@ -79,11 +79,12 @@ fn build_app(cwd: &Path, config: &Config, bundle_updater: bool, target: BundleTa
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, PartialEq)]
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
|
enum BundleTarget {
|
|
|
|
|
AppImage,
|
|
|
|
|
Deb,
|
|
|
|
|
|
|
|
|
|
App,
|
|
|
|
|
|
|
|
|
|
Msi,
|
|
|
|
|
Nsis,
|
|
|
|
|
}
|
|
|
|
@ -92,7 +93,6 @@ impl BundleTarget {
|
|
|
|
|
fn name(self) -> &'static str {
|
|
|
|
|
match self {
|
|
|
|
|
Self::AppImage => "appimage",
|
|
|
|
|
Self::Deb => "deb",
|
|
|
|
|
Self::App => "app",
|
|
|
|
|
Self::Msi => "msi",
|
|
|
|
|
Self::Nsis => "nsis",
|
|
|
|
@ -105,7 +105,7 @@ impl Default for BundleTarget {
|
|
|
|
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
|
|
|
|
return Self::App;
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
return Self::Deb;
|
|
|
|
|
return Self::AppImage;
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
|
return Self::Nsis;
|
|
|
|
|
}
|
|
|
|
@ -113,21 +113,12 @@ impl Default for BundleTarget {
|
|
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
fn bundle_paths(root_dir: &Path, version: &str) -> Vec<(BundleTarget, PathBuf)> {
|
|
|
|
|
// Return both AppImage and Deb paths
|
|
|
|
|
vec![
|
|
|
|
|
(
|
|
|
|
|
vec![(
|
|
|
|
|
BundleTarget::AppImage,
|
|
|
|
|
root_dir.join(format!(
|
|
|
|
|
"target/debug/bundle/appimage/app-updater_{version}_amd64.AppImage"
|
|
|
|
|
)),
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
BundleTarget::Deb,
|
|
|
|
|
root_dir.join(format!(
|
|
|
|
|
"target/debug/bundle/deb/app-updater_{version}_amd64.deb"
|
|
|
|
|
)),
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
)]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
@ -177,19 +168,6 @@ fn update_app() {
|
|
|
|
|
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
|
|
|
|
let root_dir = manifest_dir.join("../../../..");
|
|
|
|
|
|
|
|
|
|
// Set up cleanup on panic
|
|
|
|
|
let cleanup = std::panic::AssertUnwindSafe(|| {
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
{
|
|
|
|
|
let _ = std::process::Command::new("sudo")
|
|
|
|
|
.arg("dpkg")
|
|
|
|
|
.arg("-r")
|
|
|
|
|
.arg("app-updater")
|
|
|
|
|
.status();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let test_result = std::panic::catch_unwind(|| {
|
|
|
|
|
for mut config in [
|
|
|
|
|
Config {
|
|
|
|
|
version: "1.0.0",
|
|
|
|
@ -209,19 +187,8 @@ fn update_app() {
|
|
|
|
|
Updater::String(V1Compatible::V1Compatible)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
let bundle_targets = vec![BundleTarget::AppImage, BundleTarget::Deb];
|
|
|
|
|
#[cfg(not(target_os = "linux"))]
|
|
|
|
|
let bundle_targets = vec![BundleTarget::default()];
|
|
|
|
|
|
|
|
|
|
for bundle_target in bundle_targets {
|
|
|
|
|
// Skip test for Linux .deb with v1 compatibility
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
if v1_compatible && bundle_target == BundleTarget::Deb {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// bundle app update
|
|
|
|
|
build_app(&manifest_dir, &config, true, bundle_target);
|
|
|
|
|
build_app(&manifest_dir, &config, true, Default::default());
|
|
|
|
|
|
|
|
|
|
let updater_zip_ext = if v1_compatible {
|
|
|
|
|
if cfg!(windows) {
|
|
|
|
@ -235,10 +202,7 @@ fn update_app() {
|
|
|
|
|
None
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (bundle_target, out_bundle_path) in bundle_paths(&root_dir, "1.0.0")
|
|
|
|
|
.into_iter()
|
|
|
|
|
.filter(|(t, _)| *t == bundle_target)
|
|
|
|
|
{
|
|
|
|
|
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()
|
|
|
|
@ -261,9 +225,6 @@ fn update_app() {
|
|
|
|
|
};
|
|
|
|
|
let signature_extension = format!("{updater_extension}.sig");
|
|
|
|
|
let signature_path = out_bundle_path.with_extension(signature_extension);
|
|
|
|
|
|
|
|
|
|
println!("SIG PATH {:?} | {}", signature_path, updater_extension);
|
|
|
|
|
|
|
|
|
|
let signature = std::fs::read_to_string(&signature_path).unwrap_or_else(|_| {
|
|
|
|
|
panic!("failed to read signature file {}", signature_path.display())
|
|
|
|
|
});
|
|
|
|
@ -272,15 +233,13 @@ fn update_app() {
|
|
|
|
|
"target/debug/{}",
|
|
|
|
|
out_updater_path.file_name().unwrap().to_str().unwrap()
|
|
|
|
|
));
|
|
|
|
|
std::fs::rename(&out_updater_path, &updater_path)
|
|
|
|
|
.expect("failed to rename bundle");
|
|
|
|
|
std::fs::rename(&out_updater_path, &updater_path).expect("failed to rename bundle");
|
|
|
|
|
|
|
|
|
|
let target = target.clone();
|
|
|
|
|
|
|
|
|
|
// start the updater server
|
|
|
|
|
let server = Arc::new(
|
|
|
|
|
tiny_http::Server::http("localhost:3007")
|
|
|
|
|
.expect("failed to start updater server"),
|
|
|
|
|
tiny_http::Server::http("localhost:3007").expect("failed to start updater server"),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let server_ = server.clone();
|
|
|
|
@ -336,38 +295,8 @@ fn update_app() {
|
|
|
|
|
// bundle initial app version
|
|
|
|
|
build_app(&manifest_dir, &config, false, bundle_target);
|
|
|
|
|
|
|
|
|
|
// Set appropriate permissions and install package if needed
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
{
|
|
|
|
|
let initial_bundle_path = bundle_paths(&root_dir, "0.1.0")
|
|
|
|
|
.iter()
|
|
|
|
|
.find(|(t, _)| *t == bundle_target)
|
|
|
|
|
.map(|(_, path)| path.clone())
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
if bundle_target == BundleTarget::AppImage {
|
|
|
|
|
std::process::Command::new("sudo")
|
|
|
|
|
.arg("chmod")
|
|
|
|
|
.arg("+x")
|
|
|
|
|
.arg(initial_bundle_path)
|
|
|
|
|
.status()
|
|
|
|
|
.expect("failed to change permissions");
|
|
|
|
|
} else if bundle_target == BundleTarget::Deb {
|
|
|
|
|
// Install the .deb package
|
|
|
|
|
let install_status = std::process::Command::new("sudo")
|
|
|
|
|
.arg("dpkg")
|
|
|
|
|
.arg("-i")
|
|
|
|
|
.arg(initial_bundle_path)
|
|
|
|
|
.status()
|
|
|
|
|
.expect("failed to install .deb package");
|
|
|
|
|
|
|
|
|
|
if !install_status.success() {
|
|
|
|
|
panic!("Failed to install .deb package");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let status_checks = if matches!(bundle_target, BundleTarget::Msi) {
|
|
|
|
|
// for msi we can't really check if the app was updated, because we can't change the install path
|
|
|
|
|
vec![UPDATED_EXIT_CODE]
|
|
|
|
|
} else {
|
|
|
|
|
vec![UPDATED_EXIT_CODE, UP_TO_DATE_EXIT_CODE]
|
|
|
|
@ -386,29 +315,11 @@ fn update_app() {
|
|
|
|
|
)
|
|
|
|
|
} 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.arg("--auto-servernum")
|
|
|
|
|
.arg(&bundle_paths(&root_dir, "0.1.0").first().unwrap().1);
|
|
|
|
|
c
|
|
|
|
|
} else {
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
{
|
|
|
|
|
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());
|
|
|
|
@ -432,14 +343,4 @@ fn update_app() {
|
|
|
|
|
server.unblock();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Always run cleanup
|
|
|
|
|
cleanup();
|
|
|
|
|
|
|
|
|
|
// Re-panic if there was an error
|
|
|
|
|
if let Err(e) = test_result {
|
|
|
|
|
std::panic::resume_unwind(e);
|
|
|
|
|
}
|
|
|
|
|
}
|