From ad55e860ff20eb8ea73eab3a520874619a9f61fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Misty=20De=20M=C3=A9o?= Date: Wed, 13 Nov 2024 12:57:22 -0800 Subject: [PATCH] fix: remove sudo when not necessary --- cargo-dist/src/backend/ci/github.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cargo-dist/src/backend/ci/github.rs b/cargo-dist/src/backend/ci/github.rs index bd568f47b..095146c02 100644 --- a/cargo-dist/src/backend/ci/github.rs +++ b/cargo-dist/src/backend/ci/github.rs @@ -751,8 +751,11 @@ fn system_deps_install_script( lines.push(brew_bundle_command(brew_packages.iter())) } + // If we're crossing, we'll most likely be running from a container with + // no sudo. We should avoid calling sudo in that case. + let sudo = if rc.container.is_some() { "" } else { "sudo " }; if !apt_packages.is_empty() { - lines.push("sudo apt-get update".to_owned()); + lines.push(format!("{sudo}apt-get update")); let args = apt_packages .iter() .map(|(pkg, version)| { @@ -763,7 +766,7 @@ fn system_deps_install_script( } }) .join(" "); - lines.push(format!("sudo apt-get install {args}")); + lines.push(format!("{sudo}apt-get install {args}")); } for (pkg, version) in &chocolatey_packages {