|
7 | 7 | extern crate tracing; |
8 | 8 |
|
9 | 9 | use crate::api::ApiClient; |
10 | | -use anyhow::{anyhow, Context}; |
| 10 | +use anyhow::{anyhow, bail, Context}; |
11 | 11 | use clap::Parser; |
12 | 12 | use secrecy::SecretString; |
13 | 13 | use std::path::{Path, PathBuf}; |
@@ -65,13 +65,28 @@ async fn main() -> anyhow::Result<()> { |
65 | 65 | .await |
66 | 66 | .context("Failed to create project")?; |
67 | 67 |
|
| 68 | + info!("Checking publish with invalid authentication…"); |
| 69 | + let invalid_token = "invalid-token".into(); |
| 70 | + let output = cargo::publish_with_output(&project_path, &invalid_token).await?; |
| 71 | + if output.status.success() { |
| 72 | + bail!("Expected `cargo publish` to fail with invalid token"); |
| 73 | + } else { |
| 74 | + let stderr = String::from_utf8_lossy(&output.stderr); |
| 75 | + if !stderr.contains("401 Unauthorized") |
| 76 | + || !stderr.contains("The given API token does not match the format used by crates.io") |
| 77 | + { |
| 78 | + bail!("Expected `cargo publish` to fail with an `401 Unauthorized` error, but got: {stderr}"); |
| 79 | + } |
| 80 | + } |
| 81 | + |
68 | 82 | if options.skip_publish { |
69 | 83 | info!("Packaging crate file…"); |
70 | 84 | cargo::package(&project_path) |
71 | 85 | .await |
72 | 86 | .context("Failed to run `cargo package`")?; |
73 | 87 |
|
74 | 88 | info!("Skipping publish step"); |
| 89 | + new_version = old_version; |
75 | 90 | } else { |
76 | 91 | info!("Publishing to staging.crates.io…"); |
77 | 92 | cargo::publish(&project_path, &options.token) |
|
0 commit comments