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/components): improve push subcommand #216

Merged
merged 6 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
16 changes: 12 additions & 4 deletions crates/cli/src/commands/components/build.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
use crate::components::manifest::Manifest;

#[derive(Debug, clap::Parser)]
pub struct Options {}

pub async fn run(_opts: Options) -> anyhow::Result<()> {
use std::process::Command;

use crate::components::manifest::{self, Manifest};
use crate::components::manifest;

let Some(manifest_path) = manifest::find_manifest_path() else {
anyhow::bail!("Edgee Manifest not found. Please run `edgee component new` and start from a template or `edgee component init` to create a new empty manifest in this folder.");
};
let manifest = Manifest::load(&manifest_path).map_err(|err| anyhow::anyhow!(err))?;

do_build(&manifest).await?;

Ok(())
}

pub async fn do_build(manifest: &Manifest) -> anyhow::Result<()> {
use std::process::Command;

tracing::info!("Running: {}", manifest.component.build.command);
let mut cmd = Command::new("sh");
cmd.arg("-c").arg(manifest.component.build.command);
cmd.arg("-c").arg(&manifest.component.build.command);
let status = cmd.status()?;

if status.success() {
Expand Down
58 changes: 54 additions & 4 deletions crates/cli/src/commands/components/push.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::components::manifest::Manifest;
use edgee_api_client::types as api_types;
use slug;

use crate::components::manifest::Manifest;

#[derive(Debug, clap::Parser)]
pub struct Options {
/// The organization name used to create or update your component
Expand Down Expand Up @@ -41,7 +42,13 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
.api_context("Could not get user organization")?
.into_inner(),
};

let component_url = format!(
"https://www.edgee.cloud/~/registry/{}/{}",
organization.slug, manifest.component.name,
);
let component_slug = slug::slugify(&manifest.component.name);

match client
.get_component_by_slug()
.org_slug(&organization.slug)
Expand Down Expand Up @@ -100,12 +107,43 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
.await
.api_context("Could not create component")?;
tracing::info!(
"Component `{}/{}` created successfully!",
"Component `{}/{}` has been created successfully, you check it out here: {component_url}",
organization.slug,
component_slug
);
}
Ok(_) | Err(_) => {}
Ok(_) | Err(_) => {
client
.update_component_by_slug()
.org_slug(&organization.slug)
.component_slug(&manifest.component.name)
.body(
api_types::ComponentUpdateParams::builder()
.description(manifest.component.description.clone())
.documentation_link(
manifest
.component
.documentation
.as_ref()
.map(|url| url.to_string()),
)
.repo_link(
manifest
.component
.repository
.as_ref()
.map(|url| url.to_string()),
),
)
.send()
.await
.api_context("Could not update component infos")?;
tracing::info!(
"Component `{}/{}` has been updated and is accessible here: {component_url}",
organization.slug,
component_slug,
);
}
}

let changelog =
Expand All @@ -121,6 +159,18 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
return Ok(());
}

let output_path = &manifest.component.build.output_path;
if !output_path.exists() {
let confirm = Confirm::new("Component have not been built yet, do you want to build it?")
.with_default(true)
.prompt()?;
if !confirm {
return Ok(());
}

super::build::do_build(&manifest).await?;
}

tracing::info!("Uploading WASM file...");
let asset_url = client
.upload_file(&manifest.component.build.output_path)
Expand Down