Skip to content

Improved package init and publish flow #269

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

Merged
merged 14 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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,145 changes: 23 additions & 1,122 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ p256 = { workspace = true }
rand_core = { workspace = true }
url = { workspace = true }
# TODO: remove these demo-related dependencies
wasmtime = "10.0"
wasmtime-wasi = "10.0"
reqwest.workspace = true
warg-api.workspace = true
ptree.workspace = true
Expand All @@ -56,9 +54,10 @@ wit-parser = "0.13.1"
testresult = "0.3.0"

[features]
default = []
default = ["cli-interactive"]
postgres = ["warg-server/postgres"]
not-cli = ["warg-client/not-cli"]
cli-interactive = ["warg-client/cli-interactive"]
not-interactive-cli = []

[workspace]
members = ["crates/server"]
Expand All @@ -67,7 +66,7 @@ members = ["crates/server"]
version = "0.5.0-dev"
authors = ["The Warg Registry Project Developers"]
edition = "2021"
rust-version = "1.66.0"
rust-version = "1.76.0"
license = "Apache-2.0 WITH LLVM-exception"
homepage = "https://warg.io/"
repository = "https://github.com/bytecodealliance/registry"
Expand Down
3 changes: 2 additions & 1 deletion crates/api/src/v1/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::Status;
use indexmap::IndexMap;
use serde::{de::Unexpected, Deserialize, Serialize, Serializer};
use std::borrow::Cow;
use std::str::FromStr;
use thiserror::Error;
use warg_crypto::hash::AnyHash;

Expand Down Expand Up @@ -95,7 +96,7 @@ impl<'de> Deserialize<'de> for ContentError {
match RawError::<String>::deserialize(deserializer)? {
RawError::NotFound { status: _, ty, id } => match ty {
EntityType::ContentDigest => Ok(Self::ContentDigestNotFound(
id.parse::<AnyHash>().map_err(|_| {
AnyHash::from_str(&id).map_err(|_| {
serde::de::Error::invalid_value(Unexpected::Str(&id), &"a valid digest")
})?,
)),
Expand Down
3 changes: 2 additions & 1 deletion crates/api/src/v1/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::Status;
use indexmap::IndexMap;
use serde::{de::Unexpected, Deserialize, Serialize, Serializer};
use std::borrow::Cow;
use std::str::FromStr;
use thiserror::Error;
use warg_crypto::hash::AnyHash;
use warg_protocol::{
Expand Down Expand Up @@ -187,7 +188,7 @@ impl<'de> Deserialize<'de> for FetchError {
RawError::CheckpointNotFound { id, .. } => Ok(Self::CheckpointNotFound(id)),
RawError::NotFound { status: _, ty, id } => match ty {
EntityType::Log => Ok(Self::LogNotFound(
id.parse::<AnyHash>()
AnyHash::from_str(&id)
.map_err(|_| {
serde::de::Error::invalid_value(Unexpected::Str(&id), &"a valid log id")
})?
Expand Down
7 changes: 4 additions & 3 deletions crates/api/src/v1/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::Status;
use indexmap::IndexMap;
use serde::{de::Unexpected, Deserialize, Serialize, Serializer};
use std::borrow::Cow;
use std::str::FromStr;
use thiserror::Error;
use warg_crypto::hash::AnyHash;
use warg_protocol::{
Expand Down Expand Up @@ -286,14 +287,14 @@ impl<'de> Deserialize<'de> for PackageError {
}
RawError::NotFound { status: _, ty, id } => match ty {
EntityType::Log => Ok(Self::LogNotFound(
id.parse::<AnyHash>()
AnyHash::from_str(&id)
.map_err(|_| {
serde::de::Error::invalid_value(Unexpected::Str(&id), &"a valid log id")
})?
.into(),
)),
EntityType::Record => Ok(Self::RecordNotFound(
id.parse::<AnyHash>()
AnyHash::from_str(&id)
.map_err(|_| {
serde::de::Error::invalid_value(
Unexpected::Str(&id),
Expand All @@ -311,7 +312,7 @@ impl<'de> Deserialize<'de> for PackageError {
RawError::Conflict { status: _, ty, id } => match ty {
EntityType::NamespaceImport => Ok(Self::NamespaceImported(id.into_owned())),
EntityType::Record => Ok(Self::ConflictPendingPublish(
id.parse::<AnyHash>()
AnyHash::from_str(&id)
.map_err(|_| {
serde::de::Error::invalid_value(
Unexpected::Str(&id),
Expand Down
5 changes: 3 additions & 2 deletions crates/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ homepage = { workspace = true }
repository = { workspace = true}

[features]
default = ["dialoguer"]
default = ["cli-interactive"]
native-tls-vendored = ["reqwest/native-tls-vendored"]
not-cli = []
cli-interactive = ["dialoguer"]
not-interactive-cli = []

[dependencies]
warg-crypto = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions crates/client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ pub struct Config {
#[serde(default)]
pub auto_accept_federation_hints: bool,

/// Disable dialoguer prompts.
/// Disable interactive prompts.
#[serde(default)]
pub disable_dialoguer: bool,
pub disable_interactive: bool,
}

impl Config {
Expand Down Expand Up @@ -206,7 +206,7 @@ impl Config {
keyring_auth: self.keyring_auth,
ignore_federation_hints: self.ignore_federation_hints,
auto_accept_federation_hints: self.auto_accept_federation_hints,
disable_dialoguer: self.disable_dialoguer,
disable_interactive: self.disable_interactive,
};

serde_json::to_writer_pretty(
Expand Down
18 changes: 14 additions & 4 deletions crates/client/src/depsolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,16 @@ impl LockListBuilder {
}

#[async_recursion]
async fn parse_package<R: RegistryStorage, C: ContentStorage, N: NamespaceMapStorage>(
async fn parse_package<R, C, N>(
&mut self,
client: &Client<R, C, N>,
mut bytes: &[u8],
) -> Result<()> {
) -> Result<()>
where
R: RegistryStorage,
C: ContentStorage,
N: NamespaceMapStorage,
{
let mut parser = Parser::new(0);
let mut imports: Vec<String> = Vec::new();
loop {
Expand Down Expand Up @@ -157,11 +162,16 @@ impl LockListBuilder {

/// List of deps for building
#[async_recursion]
pub async fn build_list<R: RegistryStorage, C: ContentStorage, N: NamespaceMapStorage>(
pub async fn build_list<R, C, N>(
&mut self,
client: &Client<R, C, N>,
info: &PackageInfo,
) -> Result<()> {
) -> Result<()>
where
R: RegistryStorage,
C: ContentStorage,
N: NamespaceMapStorage,
{
let release = info.state.releases().last();
if let Some(r) = release {
let state = &r.state;
Expand Down
66 changes: 33 additions & 33 deletions crates/client/src/lib.rs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I completely missed these changes in my first pass: "Large diffs are not rendered by default." 🙄

Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#![deny(missing_docs)]
use crate::storage::PackageInfo;

#[cfg(not(feature = "not-cli"))]
#[cfg(feature = "cli-interactive")]
use crate::storage::PublishEntry;

use anyhow::{anyhow, Context, Result};

#[cfg(not(feature = "not-cli"))]
#[cfg(feature = "cli-interactive")]
use dialoguer::{theme::ColorfulTheme, Confirm};

use indexmap::IndexMap;
Expand Down Expand Up @@ -69,12 +69,12 @@ where
content: C,
namespace_map: N,
api: api::Client,
#[cfg(not(feature = "not-cli"))]
#[cfg(feature = "cli-interactive")]
ignore_federation_hints: bool,
#[cfg(not(feature = "not-cli"))]
#[cfg(feature = "cli-interactive")]
auto_accept_federation_hints: bool,
#[cfg(not(feature = "not-cli"))]
disable_dialoguer: bool,
#[cfg(feature = "cli-interactive")]
disable_interactive: bool,
}

impl<R: RegistryStorage, C: ContentStorage, N: NamespaceMapStorage> Client<R, C, N> {
Expand All @@ -87,22 +87,22 @@ impl<R: RegistryStorage, C: ContentStorage, N: NamespaceMapStorage> Client<R, C,
content: C,
namespace_map: N,
auth_token: Option<Secret<String>>,
#[cfg(not(feature = "not-cli"))] ignore_federation_hints: bool,
#[cfg(not(feature = "not-cli"))] auto_accept_federation_hints: bool,
#[cfg(not(feature = "not-cli"))] disable_dialoguer: bool,
#[cfg(feature = "cli-interactive")] ignore_federation_hints: bool,
#[cfg(feature = "cli-interactive")] auto_accept_federation_hints: bool,
#[cfg(feature = "cli-interactive")] disable_interactive: bool,
) -> ClientResult<Self> {
let api = api::Client::new(url, auth_token)?;
Ok(Self {
registry,
content,
namespace_map,
api,
#[cfg(not(feature = "not-cli"))]
#[cfg(feature = "cli-interactive")]
ignore_federation_hints,
#[cfg(not(feature = "not-cli"))]
#[cfg(feature = "cli-interactive")]
auto_accept_federation_hints,
#[cfg(not(feature = "not-cli"))]
disable_dialoguer,
#[cfg(feature = "cli-interactive")]
disable_interactive,
})
}

Expand Down Expand Up @@ -347,18 +347,18 @@ impl<R: RegistryStorage, C: ContentStorage, N: NamespaceMapStorage> Client<R, C,
);
tracing::debug!("entries: {:?}", publish_info.entries);

#[cfg(not(feature = "not-cli"))]
#[cfg(feature = "cli-interactive")]
let mut accepted_prompt_to_initialize = false;

let mut init_record_id: Option<RecordId> = None;

let (package, record) = loop {
let mut info = publish_info.clone();

#[cfg(not(feature = "not-cli"))]
#[cfg(feature = "cli-interactive")]
let mut initializing = info.initializing();

#[cfg(feature = "not-cli")]
#[cfg(not(feature = "cli-interactive"))]
let initializing = info.initializing();

let package = match self.fetch_package(&info.name).await {
Expand All @@ -379,15 +379,15 @@ impl<R: RegistryStorage, C: ContentStorage, N: NamespaceMapStorage> Client<R, C,
name,
has_auth_token,
}) => {
if !initializing && cfg!(feature = "not-cli") {
if !initializing && cfg!(not(feature = "cli-interactive")) {
return Err(ClientError::MustInitializePackage {
name,
has_auth_token,
});
} else if !initializing {
#[cfg(not(feature = "not-cli"))]
#[cfg(feature = "cli-interactive")]
{
if self.disable_dialoguer {
if self.disable_interactive {
return Err(ClientError::MustInitializePackage {
name,
has_auth_token,
Expand Down Expand Up @@ -728,12 +728,12 @@ Attempt to create `{package_name}` and publish the release y/N\n",
}

// federated packages in other registries
#[cfg(not(feature = "not-cli"))]
#[cfg(feature = "cli-interactive")]
let mut federated_packages: IndexMap<
Option<RegistryDomain>,
Vec<&mut PackageInfo>,
> = IndexMap::with_capacity(packages.len());
#[cfg(feature = "not-cli")]
#[cfg(not(feature = "cli-interactive"))]
let federated_packages: IndexMap<Option<RegistryDomain>, Vec<&mut PackageInfo>> =
IndexMap::with_capacity(packages.len());

Expand Down Expand Up @@ -780,7 +780,7 @@ Attempt to create `{package_name}` and publish the release y/N\n",
}
}

#[cfg(feature = "not-cli")]
#[cfg(not(feature = "cli-interactive"))]
api::ClientError::LogNotFoundWithHint(log_id, hint) => {
let name = packages.get(log_id).unwrap().name.clone();

Expand All @@ -800,11 +800,11 @@ Attempt to create `{package_name}` and publish the release y/N\n",
}
}

#[cfg(not(feature = "not-cli"))]
#[cfg(feature = "cli-interactive")]
api::ClientError::LogNotFoundWithHint(log_id, hint) => {
match hint.to_str().ok().map(|s| s.split_once('=')) {
Some(Some((namespace, registry)))
if self.disable_dialoguer && packages.contains_key(log_id) =>
if self.disable_interactive && packages.contains_key(log_id) =>
{
let name = packages.get(log_id).unwrap().name.clone();
Err(ClientError::PackageDoesNotExistWithHintHeader {
Expand All @@ -815,7 +815,7 @@ Attempt to create `{package_name}` and publish the release y/N\n",
})
}
Some(Some((namespace, registry)))
if !self.disable_dialoguer
if !self.disable_interactive
&& !self.ignore_federation_hints
&& packages.contains_key(log_id) =>
{
Expand Down Expand Up @@ -1259,12 +1259,12 @@ impl FileSystemClient {
content,
namespace_map,
auth_token,
#[cfg(not(feature = "not-cli"))]
#[cfg(feature = "cli-interactive")]
config.ignore_federation_hints,
#[cfg(not(feature = "not-cli"))]
#[cfg(feature = "cli-interactive")]
config.auto_accept_federation_hints,
#[cfg(not(feature = "not-cli"))]
config.disable_dialoguer,
#[cfg(feature = "cli-interactive")]
config.disable_interactive,
)?))
}

Expand All @@ -1291,12 +1291,12 @@ impl FileSystemClient {
FileSystemContentStorage::lock(content_dir)?,
FileSystemNamespaceMapStorage::new(namespace_map_path),
auth_token,
#[cfg(not(feature = "not-cli"))]
#[cfg(feature = "cli-interactive")]
config.ignore_federation_hints,
#[cfg(not(feature = "not-cli"))]
#[cfg(feature = "cli-interactive")]
config.auto_accept_federation_hints,
#[cfg(not(feature = "not-cli"))]
config.disable_dialoguer,
#[cfg(feature = "cli-interactive")]
config.disable_interactive,
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl ConfigCommand {
keyring_auth: false,
ignore_federation_hints: self.ignore_federation_hints,
auto_accept_federation_hints: self.auto_accept_federation_hints,
disable_dialoguer: false,
disable_interactive: false,
};

config.write_to_file(&path)?;
Expand Down
Loading
Loading