Repository: axodotdev/cargo-dist (rust)

Issue:
Installing dependencies using apt fails because of outdated info
I've seen a build fail because `apt-get install` fails, seemingly due to outdated package information:

> Run sudo apt-get install libudev-dev
> Reading package lists...
> Building dependency tree...
> Reading state information...
> The following NEW packages will be installed:
>   libudev-dev
> 0 upgraded, 1 newly installed, 0 to remove and 10 not upgraded.
> Need to get 20.7 kB of archives.
> After this operation, 271 kB of additional disk space will be used.
> Err:1 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 libudev-dev arm64 249.11-0ubuntu3.10
>   404  Not Found [IP: 185.125.190.39 80]
> E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/pool/main/s/systemd/libudev-dev_249.11-0ubuntu3.10_arm64.deb  404  Not Found [IP: 185.125.190.39 80]
> E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

See https://github.com/probe-rs/probe-rs/actions/runs/8425489394/job/23071714150#step:8:466

This is on a buildjet runner (buildjet-2vcpu-ubuntu-2204-arm), with cargo-dist v0.12.

Manually running `sudo apt-get update` before the dependency install step fixes this, but it would be great if cargo-dist could do that automatically.

Pull request description:
fix: run apt-get update before install
Not doing this was an oversight. There shouldn't be any harm to it.

Fixes #876.

Patch:
diff --git a/cargo-dist/src/backend/ci/github.rs b/cargo-dist/src/backend/ci/github.rs
index f683c8ed..d00288c5 100644
--- a/cargo-dist/src/backend/ci/github.rs
+++ b/cargo-dist/src/backend/ci/github.rs
@@ -409,7 +409,9 @@ fn package_install_for_targets(
                 }
 
                 let apts = packages.join(" ");
-                return Some(format!("sudo apt-get install {apts}").to_owned());
+                return Some(
+                    format!("sudo apt-get update && sudo apt-get install {apts}").to_owned(),
+                );
             }
             "i686-pc-windows-msvc" | "x86_64-pc-windows-msvc" | "aarch64-pc-windows-msvc" => {
                 let commands: Vec<String> = packages


Test patch:
diff --git a/cargo-dist/tests/snapshots/akaikatana_musl.snap b/cargo-dist/tests/snapshots/akaikatana_musl.snap
index bbdd76c4..a06f2d00 100644
--- a/cargo-dist/tests/snapshots/akaikatana_musl.snap
+++ b/cargo-dist/tests/snapshots/akaikatana_musl.snap
@@ -1112,7 +1112,7 @@ download_binary_and_run_installer "$@" || exit 1
             "runner": "ubuntu-20.04",
             "install_dist": "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/vSOME_VERSION/cargo-dist-installer.sh | sh",
             "dist_args": "--artifacts=local --target=x86_64-unknown-linux-musl",
-            "packages_install": "sudo apt-get install musl-tools"
+            "packages_install": "sudo apt-get update && sudo apt-get install musl-tools"
           }
         ]
       },
diff --git a/cargo-dist/tests/snapshots/axolotlsay_custom_github_runners.snap b/cargo-dist/tests/snapshots/axolotlsay_custom_github_runners.snap
index ea07a46d..23f4801c 100644
--- a/cargo-dist/tests/snapshots/axolotlsay_custom_github_runners.snap
+++ b/cargo-dist/tests/snapshots/axolotlsay_custom_github_runners.snap
@@ -236,7 +236,7 @@ expression: self.payload
             "runner": "buildjet-8vcpu-ubuntu-2204-arm",
             "install_dist": "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/vSOME_VERSION/cargo-dist-installer.sh | sh",
             "dist_args": "--artifacts=local --target=aarch64-unknown-linux-musl",
-            "packages_install": "sudo apt-get install musl-tools"
+            "packages_install": "sudo apt-get update && sudo apt-get install musl-tools"
           },
           {
             "targets": [
@@ -253,7 +253,7 @@ expression: self.payload
             "runner": "buildjet-8vcpu-ubuntu-2204",
             "install_dist": "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/vSOME_VERSION/cargo-dist-installer.sh | sh",
             "dist_args": "--artifacts=local --target=x86_64-unknown-linux-musl",
-            "packages_install": "sudo apt-get install musl-tools"
+            "packages_install": "sudo apt-get update && sudo apt-get install musl-tools"
           }
         ]
       },
diff --git a/cargo-dist/tests/snapshots/axolotlsay_musl.snap b/cargo-dist/tests/snapshots/axolotlsay_musl.snap
index b30eb061..d6d72202 100644
--- a/cargo-dist/tests/snapshots/axolotlsay_musl.snap
+++ b/cargo-dist/tests/snapshots/axolotlsay_musl.snap
@@ -2015,7 +2015,7 @@ maybeInstall(true).then(run);
             "runner": "ubuntu-20.04",
             "install_dist": "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/vSOME_VERSION/cargo-dist-installer.sh | sh",
             "dist_args": "--artifacts=local --target=x86_64-unknown-linux-musl",
-            "packages_install": "sudo apt-get install musl-tools"
+            "packages_install": "sudo apt-get update && sudo apt-get install musl-tools"
           }
         ]
       },
diff --git a/cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap b/cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap
index 0ace95e5..123336d2 100644
--- a/cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap
+++ b/cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap
@@ -1961,7 +1961,7 @@ maybeInstall(true).then(run);
             "runner": "ubuntu-20.04",
             "install_dist": "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/vSOME_VERSION/cargo-dist-installer.sh | sh",
             "dist_args": "--artifacts=local --target=x86_64-unknown-linux-musl",
-            "packages_install": "sudo apt-get install musl-tools"
+            "packages_install": "sudo apt-get update && sudo apt-get install musl-tools"
           }
         ]
       },
diff --git a/cargo-dist/tests/snapshots/manifest.snap b/cargo-dist/tests/snapshots/manifest.snap
index e42ece1f..cb9b06bd 100644
--- a/cargo-dist/tests/snapshots/manifest.snap
+++ b/cargo-dist/tests/snapshots/manifest.snap
@@ -429,7 +429,7 @@ stdout:
             "runner": "buildjet-8vcpu-ubuntu-2204-arm",
             "install_dist": "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v1.0.0-FAKEVERSION/cargo-dist-installer.sh | sh",
             "dist_args": "--artifacts=local --target=aarch64-unknown-linux-musl",
-            "packages_install": "sudo apt-get install musl-tools"
+            "packages_install": "sudo apt-get update && sudo apt-get install musl-tools"
           },
           {
             "targets": [
@@ -462,7 +462,7 @@ stdout:
             "runner": "ubuntu-20.04",
             "install_dist": "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v1.0.0-FAKEVERSION/cargo-dist-installer.sh | sh",
             "dist_args": "--artifacts=local --target=x86_64-unknown-linux-musl",
-            "packages_install": "sudo apt-get install musl-tools"
+            "packages_install": "sudo apt-get update && sudo apt-get install musl-tools"
           }
         ]
       },
@@ -476,5 +476,3 @@ stderr:
 INFO: You've enabled Axo Releases, which is currently in Closed Beta.
 If you haven't yet signed up, please join our discord
 (https://discord.gg/ECnWuUUXQk) or message hello@axo.dev to get started!
-
-