Skip to content

Commit 4acb920

Browse files
authored
Merge pull request #210 from mkatychev/feat/publish-dry-run
feat: added `--dry-run` to `wkg publish`
2 parents 902db9e + feba4ca commit 4acb920

13 files changed

Lines changed: 610 additions & 490 deletions

File tree

Cargo.lock

Lines changed: 559 additions & 480 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/wasm-pkg-client/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ pub struct PublishOpts {
8585
pub package: Option<(PackageRef, Version)>,
8686
/// Override the registry to publish to.
8787
pub registry: Option<Registry>,
88+
/// If true, resolve the package, version, and registry but do not call the
89+
/// backend to publish.
90+
pub dry_run: bool,
8891
}
8992

9093
/// A read-only registry client.
@@ -181,8 +184,9 @@ impl Client {
181184
let source = self
182185
.resolve_source(&package, additional_options.registry)
183186
.await?;
187+
184188
source
185-
.publish(&package, &version, data)
189+
.publish(&package, &version, data, additional_options.dry_run)
186190
.await
187191
.map(|_| (package, version))
188192
}

crates/wasm-pkg-client/src/local.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,15 @@ impl PackagePublisher for LocalBackend {
112112
package: &PackageRef,
113113
version: &Version,
114114
mut data: PublishingSource,
115+
dry_run: bool,
115116
) -> Result<(), Error> {
116117
let package_dir = self.package_dir(package);
117118
// Ensure the package directory exists.
118119
tokio::fs::create_dir_all(package_dir).await?;
119120
let path = self.version_path(package, version);
121+
if dry_run {
122+
return Ok(());
123+
}
120124
let mut out = tokio::fs::File::create(path).await?;
121125
tokio::io::copy(&mut data, &mut out)
122126
.await

crates/wasm-pkg-client/src/oci/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ impl OciBackend {
101101
Ok(auth)
102102
})
103103
.await
104+
.map_err(|e| {
105+
if let Error::RegistryError(anyhow_err) = e {
106+
Error::RegistryError(anyhow_err.context(reference.repository().to_owned()))
107+
} else {
108+
e
109+
}
110+
})
104111
.cloned()
105112
}
106113

crates/wasm-pkg-client/src/oci/publisher.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ impl PackagePublisher for OciBackend {
1515
package: &PackageRef,
1616
version: &Version,
1717
mut data: PublishingSource,
18+
dry_run: bool,
1819
) -> Result<(), crate::Error> {
1920
// NOTE(thomastaylor312): oci-client doesn't support publishing from a stream or reader, so
2021
// we have to read all the data in for now. Once we can address that upstream, we'll be able
@@ -64,10 +65,12 @@ impl PackagePublisher for OciBackend {
6465

6566
let reference: Reference = self.make_reference(package, Some(version));
6667
let auth = self.auth(&reference, RegistryOperation::Push).await?;
67-
self.client
68-
.push(&reference, &auth, layer, config, Some(annotations))
69-
.await
70-
.map_err(crate::Error::RegistryError)?;
68+
if !dry_run {
69+
self.client
70+
.push(&reference, &auth, layer, config, Some(annotations))
71+
.await
72+
.map_err(crate::Error::RegistryError)?;
73+
}
7174
Ok(())
7275
}
7376
}

crates/wasm-pkg-client/src/publisher.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ pub trait PackagePublisher: Send + Sync {
1010
package: &PackageRef,
1111
version: &Version,
1212
data: PublishingSource,
13+
dry_run: bool,
1314
) -> Result<(), crate::Error>;
1415
}

crates/wasm-pkg-client/src/warg/publisher.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ impl PackagePublisher for WargBackend {
1818
package: &PackageRef,
1919
version: &Version,
2020
data: PublishingSource,
21+
dry_run: bool,
2122
) -> Result<(), crate::Error> {
2223
// store the Wasm in Warg cache, so that it is available to Warg client for uploading
2324
let content = self
@@ -37,6 +38,10 @@ impl PackagePublisher for WargBackend {
3738
// convert package name to Warg package name
3839
let name = super::package_ref_to_name(package)?;
3940

41+
if dry_run {
42+
return Ok(());
43+
}
44+
4045
// start Warg publish, using the keyring to sign
4146
let version = version.clone();
4247
let info = PublishInfo {

crates/wasm-pkg-common/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ sha2 = { workspace = true }
3030
tokio = { workspace = true, optional = true, features = ["fs"] }
3131
toml = { workspace = true, optional = true }
3232
thiserror = { workspace = true }
33+
tracing.workspace = true
3334

3435
[dev-dependencies]
3536
tokio = { workspace = true, features = ["macros", "rt"] }

crates/wasm-pkg-common/src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ impl Config {
118118
Some(path) => path,
119119
None => return Ok(None),
120120
};
121+
122+
tracing::debug!(path = %path.display(), "using global config");
121123
let contents = match tokio::fs::read_to_string(&path).await {
122124
Ok(contents) => contents,
123125
Err(err) if err.kind() == ErrorKind::NotFound => return Ok(None),

crates/wasm-pkg-core/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub struct Config {
3030
impl Config {
3131
/// Loads a configuration file from the given path.
3232
pub async fn load_from_path(path: impl AsRef<Path>) -> Result<Config> {
33+
tracing::info!(path = %path.as_ref().display(), "loading wkg config file");
3334
let contents = tokio::fs::read_to_string(path)
3435
.await
3536
.context("unable to load config from file")?;

0 commit comments

Comments
 (0)