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

Try to build the package before publishing it #4428

Merged
merged 1 commit into from
Feb 1, 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
20 changes: 20 additions & 0 deletions lib/cli/src/commands/package/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ pub struct PackageBuild {
///
/// Defaults to current directory.
package: Option<PathBuf>,

/// Only checks whether the package could be built successfully
#[clap(long)]
check: bool,
}

static READING_MANIFEST_EMOJI: Emoji<'_, '_> = Emoji("📖 ", "");
Expand All @@ -28,6 +32,15 @@ static WRITING_PACKAGE_EMOJI: Emoji<'_, '_> = Emoji("📦 ", "");
static SPARKLE: Emoji<'_, '_> = Emoji("✨ ", ":-)");

impl PackageBuild {
pub(crate) fn check(package_path: PathBuf) -> Self {
PackageBuild {
out: None,
quiet: true,
package: Some(package_path),
check: true,
}
}

pub(crate) fn execute(&self) -> Result<(), anyhow::Error> {
let manifest_path = self.manifest_path()?;
let pkg = webc::wasmer_package::Package::from_manifest(manifest_path)?;
Expand All @@ -51,6 +64,12 @@ impl PackageBuild {
.context("could not load package manifest")?
.context("package does not contain a Wasmer manifest")?;

// rest of the code writes the package to disk and is irrelevant
// to checking.
if self.check {
return Ok(());
}

let pkgname = manifest.name.replace('/', "-");
let name = format!("{}-{}.webc", pkgname, manifest.version,);

Expand Down Expand Up @@ -169,6 +188,7 @@ description = "hello"
package: Some(path.to_owned()),
out: Some(path.to_owned()),
quiet: true,
check: false,
};

cmd.execute().unwrap();
Expand Down
9 changes: 9 additions & 0 deletions lib/cli/src/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use anyhow::Context as _;
use clap::Parser;
use wasmer_registry::{publish::PublishWait, wasmer_env::WasmerEnv};

use super::PackageBuild;

/// Publish a package to the package registry.
#[derive(Debug, Parser)]
pub struct Publish {
Expand Down Expand Up @@ -47,6 +49,13 @@ pub struct Publish {
impl Publish {
/// Executes `wasmer publish`
pub fn execute(&self) -> Result<(), anyhow::Error> {
// first check if the package could be built successfuly
let package_path = match self.package_path.as_ref() {
Some(s) => std::env::current_dir()?.join(s),
None => std::env::current_dir()?,
};
PackageBuild::check(package_path).execute()?;

let token = self
.env
.token()
Expand Down
Loading