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(cargo-shuttle): beta deploy.deny_dirty config, allow dirty deploys by default #1894

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 21 additions & 0 deletions cargo-shuttle/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ pub struct ProjectConfig {
// unused in cargo-shuttle, used in new platform builder.
// is used here to validate the type if used.
pub build_assets: Option<Vec<String>>,

pub deploy: Option<ProjectDeployConfig>,
}
/// Deployment command config
#[derive(Deserialize, Serialize, Default)]
pub struct ProjectDeployConfig {
/// set to true to deny deployments with uncommited changes. (can use `--allow-dirty`)
pub deny_dirty: Option<bool>,
}

/// .shuttle/config.toml schema (internal project-local config)
Expand Down Expand Up @@ -487,6 +495,19 @@ impl RequestContext {
.as_ref()
}

/// # Panics
/// Panics if the project configuration has not been loaded.
pub fn deny_dirty(&self) -> Option<bool> {
self.project
.as_ref()
.unwrap()
.as_ref()
.unwrap()
.deploy
.as_ref()
.and_then(|d| d.deny_dirty)
}

/// Check if the current project id has been loaded.
pub fn project_id_found(&self) -> bool {
self.project_internal
Expand Down
8 changes: 5 additions & 3 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2404,10 +2404,12 @@ impl Shuttle {
trace!(?repo_path, "found git repository");

let dirty = is_dirty(&repo);
if !args.allow_dirty && dirty.is_err() {
deployment_req.git_dirty = Some(dirty.is_err());

let check_dirty = !self.beta || self.ctx.deny_dirty().is_some_and(|d| d);
if check_dirty && !args.allow_dirty && dirty.is_err() {
bail!(dirty.unwrap_err());
}
deployment_req.git_dirty = Some(dirty.is_err());

if let Ok(head) = repo.head() {
// This is typically the name of the current branch
Expand Down Expand Up @@ -3167,7 +3169,7 @@ fn is_dirty(repo: &Repository) -> Result<()> {
}

writeln!(error).expect("to append error");
writeln!(error, "To proceed despite this and include the uncommitted changes, pass the `--allow-dirty` or `--ad` flag").expect("to append error");
writeln!(error, "To proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag (alias `--ad`)").expect("to append error");

bail!(error);
}
Expand Down