From 2343425ea8e6276c5c3918baf7492e80e2a763d0 Mon Sep 17 00:00:00 2001 From: Christoph Herzog Date: Sun, 25 Feb 2024 16:18:31 +0100 Subject: [PATCH] fix(cli): Fix auto-package version bumping in 'wasmer deploy' THe backend does not return reliable version information, so we have to introduce a loop that checks for the next available version. --- lib/cli/src/commands/create_exe.rs | 6 ++--- lib/cli/src/utils/mod.rs | 36 +++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index eabac1ee532..d95154b29f7 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -1958,16 +1958,14 @@ pub(super) mod utils { #[test] fn test_filter_tarball() { use std::str::FromStr; - let test_paths = vec![ - "/test/wasmer-darwin-amd64.tar.gz", + let test_paths = ["/test/wasmer-darwin-amd64.tar.gz", "/test/wasmer-darwin-arm64.tar.gz", "/test/wasmer-linux-aarch64.tar.gz", "/test/wasmer-linux-amd64.tar.gz", "/test/wasmer-linux-musl-amd64.tar.gz", "/test/wasmer-windows-amd64.tar.gz", "/test/wasmer-windows-gnu64.tar.gz", - "/test/wasmer-windows.exe", - ]; + "/test/wasmer-windows.exe"]; let paths = test_paths.iter().map(Path::new).collect::>(); assert_eq!( diff --git a/lib/cli/src/utils/mod.rs b/lib/cli/src/utils/mod.rs index fbf448ebd68..f733e0c0e98 100644 --- a/lib/cli/src/utils/mod.rs +++ b/lib/cli/src/utils/mod.rs @@ -190,15 +190,35 @@ pub async fn republish_package_with_bumped_version( // If it does not exist yet, we don't need to increment. let current_opt = wasmer_api::query::get_package(client, manifest.package.name.clone()) - .await - .context("could not load package info from backend")? - .and_then(|x| x.last_version); + .await + .context("could not load package info from backend")? + .and_then(|x| x.last_version); - let new_version = if let Some(current) = current_opt { + let new_version = if let Some(current) = ¤t_opt { let mut v = semver::Version::parse(¤t.version) .with_context(|| format!("Could not parse package version: '{}'", current.version))?; v.patch += 1; + + // The backend does not have a reliable way to return the latest version, + // so we have to check each version in a loop. + loop { + let version = format!("={}", v); + let version = wasmer_api::query::get_package_version( + client, + manifest.package.name.clone(), + version.clone(), + ) + .await + .context("could not load package info from backend")?; + + if version.is_some() { + v.patch += 1; + } else { + break; + } + } + v } else { manifest.package.version @@ -246,7 +266,13 @@ pub async fn republish_package_with_bumped_version( // large packages. timeout: std::time::Duration::from_secs(60 * 60 * 12), }; - publish.execute()?; + + // Publish uses a blocking http client internally, which leads to a + // "can't drop a runtime within an async context" error, so this has + // to be run in a separate thread. + std::thread::spawn(move || publish.execute()) + .join() + .map_err(|e| anyhow::format_err!("failed to publish package: {:?}", e))??; Ok(manifest) }