Skip to content

Commit

Permalink
Merge branch 'topgrade-rs:main' into patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
niStee authored Aug 15, 2024
2 parents e3ef4b8 + a1f3c86 commit a0615ed
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ pub enum Step {
Vagrant,
Vcpkg,
Vim,
VoltaPackages,
Vscode,
Waydroid,
Winget,
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ fn run() -> Result<()> {
runner.execute(Step::Node, "npm", || node::run_npm_upgrade(&ctx))?;
runner.execute(Step::Yarn, "yarn", || node::run_yarn_upgrade(&ctx))?;
runner.execute(Step::Pnpm, "pnpm", || node::run_pnpm_upgrade(&ctx))?;
runner.execute(Step::VoltaPackages, "volta packages", || {
node::run_volta_packages_upgrade(&ctx)
})?;
runner.execute(Step::Containers, "Containers", || containers::run_containers(&ctx))?;
runner.execute(Step::Deno, "deno", || node::deno_upgrade(&ctx))?;
runner.execute(Step::Composer, "composer", || generic::run_composer_update(&ctx))?;
Expand Down
47 changes: 46 additions & 1 deletion src/steps/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use semver::Version;
use tracing::debug;

use crate::command::CommandExt;
use crate::terminal::print_separator;
use crate::terminal::{print_info, print_separator};
use crate::utils::{require, PathExt};
use crate::{error::SkipStep, execution_context::ExecutionContext};

Expand Down Expand Up @@ -276,3 +276,48 @@ pub fn deno_upgrade(ctx: &ExecutionContext) -> Result<()> {
print_separator("Deno");
ctx.run_type().execute(&deno).arg("upgrade").status_checked()
}

/// There is no `volta upgrade` command, so we need to upgrade each package
pub fn run_volta_packages_upgrade(ctx: &ExecutionContext) -> Result<()> {
let volta = require("volta")?;

print_separator("Volta");

if ctx.run_type().dry() {
print_info("Updating Volta packages...");
return Ok(());
}

let list_output = ctx
.run_type()
.execute(&volta)
.args(["list", "--format=plain"])
.output_checked_utf8()?
.stdout;

let installed_packages: Vec<&str> = list_output
.lines()
.filter_map(|line| {
// format is 'kind package@version ...'
let mut parts = line.split_whitespace();
parts.next();
let package_part = parts.next()?;
let version_index = package_part.rfind('@').unwrap_or(package_part.len());
Some(package_part[..version_index].trim())
})
.collect();

if installed_packages.is_empty() {
print_info("No packages installed with Volta");
return Ok(());
}

for package in installed_packages.iter() {
ctx.run_type()
.execute(&volta)
.args(["install", package])
.status_checked()?;
}

Ok(())
}
6 changes: 3 additions & 3 deletions src/steps/os/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,10 @@ pub fn run_nix(ctx: &ExecutionContext) -> Result<()> {

debug!("Nix version: {:?}", version);

let mut packages = "--all";
let mut packages: Vec<&str> = vec!["--all", "--impure"];

if !matches!(version, Ok(version) if version >= Version::new(2, 21, 0)) {
packages = ".*";
packages = vec![".*"];
}

if Path::new(&manifest_json_path).exists() {
Expand All @@ -425,7 +425,7 @@ pub fn run_nix(ctx: &ExecutionContext) -> Result<()> {
.args(nix_args())
.arg("profile")
.arg("upgrade")
.arg(packages)
.args(&packages)
.arg("--verbose")
.status_checked()
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/steps/os/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,12 @@ pub fn windows_update(ctx: &ExecutionContext) -> Result<()> {
print_separator("Windows Update");

if powershell.supports_windows_update() {
println!("The installer will request to run as administrator, expect a prompt.");

powershell.windows_update(ctx)
} else {
print_warning(
"Consider installing PSWindowsUpdate as the use of Windows Update via USOClient is not supported.",
"Consider installing PSWindowsUpdate Module as the use of Windows Update via USOClient is not supported.",
);

Err(SkipStep("USOClient not supported.".to_string()).into())
Expand Down
22 changes: 9 additions & 13 deletions src/steps/powershell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,16 @@ impl Powershell {
#[cfg(windows)]
pub fn windows_update(&self, ctx: &ExecutionContext) -> Result<()> {
let powershell = require_option(self.path.as_ref(), String::from("Powershell is not installed"))?;

debug_assert!(self.supports_windows_update());

let accept_all = if ctx.config().accept_all_windows_updates() {
"-AcceptAll"
} else {
""
};

let install_windowsupdate_verbose = "Install-WindowsUpdate -Verbose".to_string();

let mut command = if let Some(sudo) = ctx.sudo() {
let mut command = ctx.run_type().execute(sudo);
command.arg(powershell);
Expand All @@ -107,18 +114,7 @@ impl Powershell {
};

command
.args([
"-NoProfile",
"-Command",
&format!(
"Start-Process powershell -Verb runAs -ArgumentList 'Import-Module PSWindowsUpdate; Install-WindowsUpdate -MicrosoftUpdate {} -Verbose'",
if ctx.config().accept_all_windows_updates() {
"-AcceptAll"
} else {
""
}
),
])
.args(["-NoProfile", &install_windowsupdate_verbose, accept_all])
.status_checked()
}
}

0 comments on commit a0615ed

Please sign in to comment.