Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support partial manifest fields #4630

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 27 additions & 22 deletions lib/cli/src/commands/app/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,31 +559,36 @@ impl AppCreator {
),
};

let full = format!("{}@{}", pkg.name, pkg.version);
let mut pkg_ident = NamedPackageIdent::from_str(&pkg.name)
.with_context(|| format!("local package manifest has invalid name: '{full}'"))?;

// Pin the version.
pkg_ident.tag = Some(Tag::from_str(&pkg.version.to_string()).unwrap());

if self.interactive {
eprintln!("Found local package: '{}'", full.green());

let msg = format!("Use package '{pkg_ident}'");

let theme = dialoguer::theme::ColorfulTheme::default();
let should_use = Confirm::with_theme(&theme)
.with_prompt(&msg)
.interact_opt()?
.unwrap_or_default();

if should_use {
Some(pkg_ident)
if let (Some(name), Some(version)) = (pkg.name, pkg.version) {
let full = format!("{}@{}", name, version);
let mut pkg_ident = NamedPackageIdent::from_str(&name).with_context(|| {
format!("local package manifest has invalid name: '{full}'")
})?;

// Pin the version.
pkg_ident.tag = Some(Tag::from_str(&version.to_string()).unwrap());

if self.interactive {
eprintln!("Found local package: '{}'", full.green());

let msg = format!("Use package '{pkg_ident}'");

let theme = dialoguer::theme::ColorfulTheme::default();
let should_use = Confirm::with_theme(&theme)
.with_prompt(&msg)
.interact_opt()?
.unwrap_or_default();

if should_use {
Some(pkg_ident)
} else {
None
}
} else {
None
Some(pkg_ident)
}
} else {
Some(pkg_ident)
None
}
} else {
None
Expand Down
109 changes: 62 additions & 47 deletions lib/cli/src/commands/app/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,58 +327,73 @@ impl AsyncCliCommand for CmdAppDeploy {

if let Ok(Some((manifest_path, manifest))) = load_package_manifest(&base_dir_path) {
if let Some(package) = &manifest.package {
if package.name == n.full_name() {
eprintln!(
"Found local package (manifest path: {}).",
manifest_path.display()
);
eprintln!("The `package` field in `app.yaml` specified the same named package ({}).", package.name);
eprintln!("This behaviour is deprecated.");
let theme = dialoguer::theme::ColorfulTheme::default();
if self.non_interactive {
eprintln!("Hint: replace `package: {}` with `package: .` to replicate the intended behaviour.", n);
anyhow::bail!("deprecated deploy behaviour")
} else if Confirm::with_theme(&theme)
.with_prompt("Change package to '.' in app.yaml?")
.interact()?
{
app_config.package = PackageSource::Path(String::from("."));
// We have to write it right now.
let new_config_raw = serde_yaml::to_string(&app_config)?;
std::fs::write(&app_config_path, new_config_raw).with_context(
|| {
format!(
"Could not write file: '{}'",
app_config_path.display()
)
},
)?;

log::info!(
"Using package {} ({})",
app_config.package,
n.full_name()
if let Some(name) = &package.name {
if name == &n.full_name() {
eprintln!(
"Found local package (manifest path: {}).",
manifest_path.display()
);
eprintln!("The `package` field in `app.yaml` specified the same named package ({}).", name);
eprintln!("This behaviour is deprecated.");

let theme = dialoguer::theme::ColorfulTheme::default();
if self.non_interactive {
eprintln!("Hint: replace `package: {}` with `package: .` to replicate the intended behaviour.", n);
anyhow::bail!("deprecated deploy behaviour")
} else if Confirm::with_theme(&theme)
.with_prompt("Change package to '.' in app.yaml?")
.interact()?
{
app_config.package = PackageSource::Path(String::from("."));
// We have to write it right now.
let new_config_raw = serde_yaml::to_string(&app_config)?;
std::fs::write(&app_config_path, new_config_raw).with_context(
|| {
format!(
"Could not write file: '{}'",
app_config_path.display()
)
},
)?;

log::info!(
"Using package {} ({})",
app_config.package,
n.full_name()
);

let package_id = self.publish(owner.clone(), manifest_path).await?;

app_config.package = package_id.into();

DeployAppOpts {
app: &app_config,
original_config: Some(
app_config.clone().to_yaml_value().unwrap(),
),
allow_create: true,
make_default: !self.no_default,
owner: Some(owner),
wait,
}
} else {
eprintln!(
let package_id =
self.publish(owner.clone(), manifest_path).await?;

app_config.package = package_id.into();

DeployAppOpts {
app: &app_config,
original_config: Some(
app_config.clone().to_yaml_value().unwrap(),
),
allow_create: true,
make_default: !self.no_default,
owner: Some(owner),
wait,
}
} else {
eprintln!(
"{}: the package will not be published and the deployment will fail if the package does not already exist.",
"Warning".yellow().bold()
);
DeployAppOpts {
app: &app_config,
original_config: Some(
app_config.clone().to_yaml_value().unwrap(),
),
allow_create: true,
make_default: !self.no_default,
owner: Some(owner),
wait,
}
}
} else {
DeployAppOpts {
app: &app_config,
original_config: Some(
Expand Down
14 changes: 9 additions & 5 deletions lib/cli/src/commands/package/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ impl PackageBuild {
let pkg = webc::wasmer_package::Package::from_manifest(manifest_path)?;
let pkg_hash = PackageHash::from_sha256_bytes(pkg.webc_hash());
let name = if let Some(manifest_pkg) = manifest.package {
format!(
"{}-{}.webc",
manifest_pkg.name.replace('/', "-"),
manifest_pkg.version
)
if let Some(name) = manifest_pkg.name {
if let Some(version) = manifest_pkg.version {
format!("{}-{}.webc", name.replace('/', "-"), version)
} else {
format!("{}-{}.webc", name.replace('/', "-"), pkg_hash)
}
} else {
format!("{}.webc", pkg_hash)
}
} else {
format!("{}.webc", pkg_hash)
};
Expand Down
83 changes: 43 additions & 40 deletions lib/cli/src/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,51 +123,54 @@ impl AsyncCliCommand for Publish {
let mut version = self.version.clone();

if let Some(ref mut pkg) = manifest.package {
let mut latest_version = {
let v = wasmer_api::query::get_package_version(
&client,
pkg.name.clone(),
"latest".into(),
)
.await?;
if let Some(v) = v {
semver::Version::parse(&v.version)
.with_context(|| "While parsing registry version of package")?
} else {
pkg.version.clone()
}
};

if pkg.version < latest_version {
if self.bump {
latest_version.patch += 1;
version = Some(latest_version);
} else if interactive {
latest_version.patch += 1;
let theme = dialoguer::theme::ColorfulTheme::default();
if Confirm::with_theme(&theme)
.with_prompt(format!(
"Do you want to bump the package to a new version? ({} -> {})",
pkg.version, latest_version
))
.interact()
.unwrap_or_default()
{
if let (Some(pkg_name), Some(pkg_version)) = (&pkg.name, &pkg.version) {
let pkg_name = pkg_name.clone();
let pkg_version = pkg_version.clone();

let mut latest_version = {
let v = wasmer_api::query::get_package_version(
&client,
pkg_name.clone(),
"latest".into(),
)
.await?;
if let Some(v) = v {
semver::Version::parse(&v.version)
.with_context(|| "While parsing registry version of package")?
} else {
pkg_version.clone()
}
};

if pkg_version < latest_version {
if self.bump {
latest_version.patch += 1;
version = Some(latest_version);
} else if interactive {
latest_version.patch += 1;
let theme = dialoguer::theme::ColorfulTheme::default();
if Confirm::with_theme(&theme)
.with_prompt(format!(
"Do you want to bump the package to a new version? ({} -> {})",
pkg_version, latest_version
))
.interact()
.unwrap_or_default()
{
pkg.version = Some(latest_version);
}
} else if latest_version > pkg_version {
eprintln!("Registry has a newer version of this package.");
eprintln!(
"If a package with version {} already exists, publishing will fail.",
pkg_version
);
}
} else if latest_version > pkg.version {
eprintln!("Registry has a newer version of this package.");
eprintln!(
"If a package with version {} already exists, publishing will fail.",
pkg.version
);
}
}

// If necessary, update the manifest.
if let Some(version) = version.clone() {
// If necessary, update the manifest.
if version != pkg.version {
pkg.version = version;
pkg.version = version.clone();

let contents = toml::to_string(&manifest).with_context(|| {
format!(
Expand Down
17 changes: 9 additions & 8 deletions lib/config/src/package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ const LICENSE_PATHS: &[&str; 3] = &["LICENSE", "LICENSE.md", "COPYING"];
#[non_exhaustive]
pub struct Package {
/// The package's name in the form `namespace/name`.
#[builder(setter(into))]
pub name: String,
#[builder(setter(into, strip_option), default)]
pub name: Option<String>,
/// The package's version number.
pub version: Version,
#[builder(setter(into, strip_option), default)]
pub version: Option<Version>,
/// A brief description of the package.
#[builder(setter(into))]
pub description: String,
#[builder(setter(into, strip_option), default)]
pub description: Option<String>,
/// A SPDX license specifier for this package.
#[builder(setter(into, strip_option), default)]
pub license: Option<String>,
Expand Down Expand Up @@ -975,9 +976,9 @@ mod tests {
fn test_to_string() {
Manifest {
package: Some(Package {
name: "package/name".to_string(),
version: Version::parse("1.0.0").unwrap(),
description: "test".to_string(),
name: Some("package/name".to_string()),
version: Some(Version::parse("1.0.0").unwrap()),
description: Some("test".to_string()),
license: None,
license_file: None,
readme: None,
Expand Down
26 changes: 15 additions & 11 deletions lib/registry/src/package/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ impl Publish {

if let Some(package_name) = self.package_name.as_ref() {
if let Some(ref mut package) = manifest.package {
package.name = package_name.clone();
package.name = Some(package_name.clone());
}
}

if let Some(version) = self.version.as_ref() {
if let Some(ref mut package) = manifest.package {
package.version = version.clone();
package.version = Some(version.clone());
}
}

Expand Down Expand Up @@ -673,16 +673,20 @@ mod validate {
) -> Result<bool, ValidationError> {
match &manifest.package {
Some(pkg) => {
let result =
crate::query_package_from_registry(registry, &pkg.name, None, Some(auth_token));

match result {
Ok(package_version) => Ok(package_version.is_private != pkg.private),
Err(QueryPackageError::NoPackageFound { .. }) => {
// The package hasn't been published yet
Ok(false)
if let Some(ref name) = pkg.name {
let result =
crate::query_package_from_registry(registry, name, None, Some(auth_token));

match result {
Ok(package_version) => Ok(package_version.is_private != pkg.private),
Err(QueryPackageError::NoPackageFound { .. }) => {
// The package hasn't been published yet
Ok(false)
}
Err(e) => Err(e.into()),
}
Err(e) => Err(e.into()),
} else {
Ok(false)
}
}

Expand Down
Loading
Loading