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

feat(cli/push): Push with name if available (+ CLI flag) #4912

Merged
merged 2 commits into from
Jul 3, 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
1 change: 1 addition & 0 deletions lib/cli/src/commands/package/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ impl PackagePublish {
env: self.env.clone(),
dry_run: self.dry_run,
quiet: self.quiet,
package_name: self.package_name.clone(),
package_namespace: self.package_namespace.clone(),
timeout: self.timeout,
non_interactive: self.non_interactive,
Expand Down
29 changes: 26 additions & 3 deletions lib/cli/src/commands/package/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ pub struct PackagePush {
#[clap(long = "namespace")]
pub package_namespace: Option<String>,

/// Override the name of the package to upload. If a name is specified,
/// no version will be attached to the package.
#[clap(long = "name")]
pub package_name: Option<String>,

/// Timeout (in seconds) for the publish query to the registry.
///
/// Note that this is not the timeout for the entire publish process, but
Expand Down Expand Up @@ -86,6 +91,22 @@ impl PackagePush {
Ok(owner.clone())
}

async fn get_name(&self, manifest: &Manifest) -> anyhow::Result<Option<String>> {
if let Some(name) = &self.package_name {
return Ok(Some(name.clone()));
}

if let Some(pkg) = &manifest.package {
if let Some(ns) = &pkg.name {
if let Some(name) = ns.split('/').nth(1) {
return Ok(Some(name.to_string()));
}
}
}

Ok(None)
}

fn get_privacy(&self, manifest: &Manifest) -> bool {
match &manifest.package {
Some(pkg) => pkg.private,
Expand All @@ -103,6 +124,7 @@ impl PackagePush {
&self,
client: &WasmerClient,
namespace: &str,
name: Option<String>,
package: &Package,
package_hash: &PackageHash,
private: bool,
Expand All @@ -115,7 +137,7 @@ impl PackagePush {
let pb = make_spinner!(self.quiet, "Waiting for package to become available...");
match wasmer_api::query::push_package_release(
client,
None,
name.as_deref(),
namespace,
&signed_url,
Some(private),
Expand Down Expand Up @@ -154,9 +176,10 @@ impl PackagePush {
tracing::info!("Package has hash: {hash}");

let namespace = self.get_namespace(client, manifest).await?;
let name = self.get_name(manifest).await?;

let private = self.get_privacy(manifest);
tracing::info!("If published, package privacy is {private}");
tracing::info!("If published, package privacy is {private}, namespace is {namespace} and name is {name:?}");

let pb = make_spinner!(
self.quiet,
Expand All @@ -168,7 +191,7 @@ impl PackagePush {
pb.finish_and_clear();
// spinner_ok!(pb, "Package not in the registry yet!");

self.do_push(client, &namespace, &package, &hash, private)
self.do_push(client, &namespace, name, &package, &hash, private)
.await
.map_err(on_error)?;
} else {
Expand Down
Loading