pub mod render;
use std::path::Path;
use anyhow::Context;
use wasmer_api::backend::BackendClient;
pub async fn republish_package_with_bumped_version(
client: &BackendClient,
manifest_path: &Path,
mut manifest: wasmer_toml::Manifest,
) -> Result<wasmer_toml::Manifest, anyhow::Error> {
let current_opt = wasmer_api::backend::get_package(client, manifest.package.name.clone())
.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 mut v = semver::Version::parse(¤t.version)
.with_context(|| format!("Could not parse package version: '{}'", current.version))?;
v.minor += 1;
v
} else {
manifest.package.version
};
manifest.package.version = new_version;
let contents = toml::to_string(&manifest).with_context(|| {
format!(
"could not persist manifest to '{}'",
manifest_path.display()
)
})?;
std::fs::write(&manifest_path, contents)
.with_context(|| format!("could not write manifest to '{}'", manifest_path.display()))?;
let dir = manifest_path
.parent()
.context("could not determine wasmer.toml parent directory")?
.to_owned();
std::thread::spawn({
move || {
let publish = wasmer_registry::package::builder::Publish {
registry: None,
dry_run: false,
quiet: false,
package_name: None,
version: None,
token: None,
no_validate: true,
package_path: Some(dir.to_str().unwrap().to_string()),
};
publish.execute()
}
})
.join()
.expect("thread failed")?;
Ok(manifest)
}