Repository: axodotdev/cargo-dist
Pull request #410 (2023-09-07 18:13:00)

fix(check): analysis uses --artifacts=all
Fixes an issue where the preflight config check would use whichever artifact options the user had passed. If --artifacts=local was passed, we would be inappropriately flagging GitHub CI as out of date because we'd try to omit the global artifacts.

Gankra: ugh whoops

Patch:
diff --git a/cargo-dist/src/lib.rs b/cargo-dist/src/lib.rs
index 539afc7e..88bf718c 100644
--- a/cargo-dist/src/lib.rs
+++ b/cargo-dist/src/lib.rs
@@ -23,7 +23,9 @@ use backend::{
 };
 use camino::{Utf8Path, Utf8PathBuf};
 use cargo_dist_schema::{Asset, AssetKind, DistManifest, ExecutableAsset};
-use config::{ChecksumStyle, CompressionImpl, Config, DirtyMode, GenerateMode, ZipStyle};
+use config::{
+    ArtifactMode, ChecksumStyle, CompressionImpl, Config, DirtyMode, GenerateMode, ZipStyle,
+};
 use semver::Version;
 use tracing::{info, warn};
 
@@ -42,8 +44,9 @@ mod tests;
 
 /// cargo dist build -- actually build binaries and installers!
 pub fn do_build(cfg: &Config) -> Result<DistManifest> {
+    check_integrity(cfg)?;
+
     let dist = tasks::gather_work(cfg)?;
-    check_integrity(&dist)?;
 
     // FIXME: parallelize this by working this like a dependency graph, so we can start
     // bundling up an executable the moment it's built! Note however that you shouldn't
@@ -75,8 +78,8 @@ pub fn do_build(cfg: &Config) -> Result<DistManifest> {
 
 /// Just generate the manifest produced by `cargo dist build` without building
 pub fn do_manifest(cfg: &Config) -> Result<DistManifest> {
+    check_integrity(cfg)?;
     let dist = gather_work(cfg)?;
-    check_integrity(&dist)?;
 
     Ok(build_manifest(cfg, &dist))
 }
@@ -661,9 +664,23 @@ pub fn run_generate(dist: &DistGraph, args: &GenerateArgs) -> Result<()> {
 /// Run any necessary integrity checks for "primary" commands like build/plan
 ///
 /// (This is currently equivalent to `cargo dist generate --check`)
-pub fn check_integrity(dist: &DistGraph) -> Result<()> {
+pub fn check_integrity(cfg: &Config) -> Result<()> {
+    // We need to avoid overwriting any parts of configuration from CLI here,
+    // so construct a clean copy of config to run the check generate
+    let check_config = Config {
+        needs_coherent_announcement_tag: false,
+        artifact_mode: ArtifactMode::All,
+        no_local_paths: false,
+        allow_all_dirty: cfg.allow_all_dirty,
+        targets: vec![],
+        ci: vec![],
+        installers: vec![],
+        announcement_tag: None,
+    };
+    let dist = tasks::gather_work(&check_config)?;
+
     run_generate(
-        dist,
+        &dist,
         &GenerateArgs {
             modes: vec![],
             check: true,
diff --git a/cargo-dist/src/tasks.rs b/cargo-dist/src/tasks.rs
index f23701ad..d0dda7fd 100644
--- a/cargo-dist/src/tasks.rs
+++ b/cargo-dist/src/tasks.rs
@@ -2009,7 +2009,7 @@ impl DistGraph {
 
 /// Precompute all the work this invocation will need to do
 pub fn gather_work(cfg: &Config) -> Result<DistGraph> {
-    eprintln!("analyzing workspace:");
+    info!("analyzing workspace:");
     let tools = tool_info()?;
     let workspace = crate::config::get_project()?;
     let mut graph =
@@ -2405,16 +2405,16 @@ pub(crate) fn parse_tag(
         let sty;
         if let Some(reason) = &disabled_reason {
             sty = &disabled_sty;
-            eprintln!("  {}", sty.apply_to(format!("{pkg_name} ({reason})")));
+            info!("  {}", sty.apply_to(format!("{pkg_name} ({reason})")));
         } else {
             sty = &enabled_sty;
-            eprintln!("  {}", sty.apply_to(pkg_name));
+            info!("  {}", sty.apply_to(pkg_name));
         }
 
         // Report each binary and potentially add it to the Release for this package
         let mut rust_binaries = vec![];
         for binary in &pkg.binaries {
-            eprintln!("    {}", sty.apply_to(format!("[bin] {}", binary)));
+            info!("    {}", sty.apply_to(format!("[bin] {}", binary)));
             // In the future might want to allow this to be granular for each binary
             if disabled_reason.is_none() {
                 rust_binaries.push(binary.to_owned());
@@ -2426,7 +2426,6 @@ pub(crate) fn parse_tag(
             rust_releases.push((pkg_id, rust_binaries));
         }
     }
-    eprintln!();
 
     // Don't proceed if this doesn't make sense
     if rust_releases.is_empty() {


Test patch:
diff --git a/cargo-dist/tests/snapshots/error_manifest.snap b/cargo-dist/tests/snapshots/error_manifest.snap
index cdf91101..629a7e6c 100644
--- a/cargo-dist/tests/snapshots/error_manifest.snap
+++ b/cargo-dist/tests/snapshots/error_manifest.snap
@@ -6,11 +6,6 @@ stdout:
 {"diagnostic": {"message": "This workspace doesn't have anything for cargo-dist to Release!","severity": "error","causes": [],"labels": [],"related": []}}
 
 stderr:
-analyzing workspace:
-  cargo-dist (didn't match tag v1.0.0-FAKEVERSION)
-    [bin] cargo-dist
-  cargo-dist-schema (no binaries)
-
   × This workspace doesn't have anything for cargo-dist to Release!
 
 
diff --git a/cargo-dist/tests/snapshots/lib_manifest.snap b/cargo-dist/tests/snapshots/lib_manifest.snap
index 171046fe..573563f1 100644
--- a/cargo-dist/tests/snapshots/lib_manifest.snap
+++ b/cargo-dist/tests/snapshots/lib_manifest.snap
@@ -23,10 +23,5 @@ stdout:
 }
 
 stderr:
-analyzing workspace:
-  cargo-dist (didn't match tag cargo-dist-schema-v1.0.0-FAKEVERSION)
-    [bin] cargo-dist
-  cargo-dist-schema (no binaries)
-
  WARN You're trying to explicitly Release a library, only minimal functionality will work
 
diff --git a/cargo-dist/tests/snapshots/lib_manifest_slash.snap b/cargo-dist/tests/snapshots/lib_manifest_slash.snap
index 01d51a22..573563f1 100644
--- a/cargo-dist/tests/snapshots/lib_manifest_slash.snap
+++ b/cargo-dist/tests/snapshots/lib_manifest_slash.snap
@@ -23,10 +23,5 @@ stdout:
 }
 
 stderr:
-analyzing workspace:
-  cargo-dist (didn't match tag cargo-dist-schema/v1.0.0-FAKEVERSION)
-    [bin] cargo-dist
-  cargo-dist-schema (no binaries)
-
  WARN You're trying to explicitly Release a library, only minimal functionality will work
 
diff --git a/cargo-dist/tests/snapshots/manifest.snap b/cargo-dist/tests/snapshots/manifest.snap
index 792bd1aa..13f735ca 100644
--- a/cargo-dist/tests/snapshots/manifest.snap
+++ b/cargo-dist/tests/snapshots/manifest.snap
@@ -265,9 +265,4 @@ stdout:
 }
 
 stderr:
-analyzing workspace:
-  cargo-dist
-    [bin] cargo-dist
-  cargo-dist-schema (no binaries)
-