From 5dffa2c6cca7639387dcb74386399f6dea9661fb Mon Sep 17 00:00:00 2001 From: DottoDev <37108907+DottoDev@users.noreply.github.com> Date: Mon, 10 Oct 2022 18:03:34 +0000 Subject: [PATCH 01/20] Add new step: GNU Guix by JamesClarke7283 (#1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added new step: guix (basic support) * Fixed clippy errors and better practice, Thanks To guidence from @enchant97 * Removed accidental swp file, as pointed out by @strangelittlemonkey in pull request #982 Authored-by: James Clarke Approved-by: Thomas Schönauer --- src/config.rs | 1 + src/main.rs | 2 ++ src/steps/os/unix.rs | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/config.rs b/src/config.rs index 9eec74c7..4e69b0b9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -94,6 +94,7 @@ pub enum Step { GithubCliExtensions, GitRepos, Go, + Guix, Haxelib, GnomeShellExtensions, HomeManager, diff --git a/src/main.rs b/src/main.rs index 88d0f605..e47b1770 100644 --- a/src/main.rs +++ b/src/main.rs @@ -191,6 +191,8 @@ fn run() -> Result<()> { { runner.execute(Step::Yadm, "yadm", || unix::run_yadm(&ctx))?; runner.execute(Step::Nix, "nix", || unix::run_nix(&ctx))?; + runner.execute(Step::Guix, "guix", || unix::run_guix(&ctx))?; + runner.execute(Step::HomeManager, "home-manager", || unix::run_home_manager(run_type))?; runner.execute(Step::Asdf, "asdf", || unix::run_asdf(run_type))?; runner.execute(Step::Pkgin, "pkgin", || unix::run_pkgin(&ctx))?; diff --git a/src/steps/os/unix.rs b/src/steps/os/unix.rs index dd90b2d0..a6c1468a 100644 --- a/src/steps/os/unix.rs +++ b/src/steps/os/unix.rs @@ -251,6 +251,24 @@ pub fn run_brew_cask(ctx: &ExecutionContext, variant: BrewVariant) -> Result<()> Ok(()) } +pub fn run_guix(ctx: &ExecutionContext) -> Result<()> { + let guix = require("guix")?; + + let run_type = ctx.run_type(); + + let output = Command::new(&guix).arg("pull").check_output(); + debug!("guix pull output: {:?}", output); + let should_upgrade = output.is_ok(); + debug!("Can Upgrade Guix: {:?}", should_upgrade); + + print_separator("Guix"); + + if should_upgrade { + return run_type.execute(&guix).args(&["package", "-u"]).check_run(); + } + Err(SkipStep(String::from("Guix Pull Failed, Skipping")).into()) +} + pub fn run_nix(ctx: &ExecutionContext) -> Result<()> { let nix = require("nix")?; let nix_channel = require("nix-channel")?; From 057fc3b5338434627fb5a3be8308d765b5ebea99 Mon Sep 17 00:00:00 2001 From: DottoDev <37108907+DottoDev@users.noreply.github.com> Date: Mon, 10 Oct 2022 18:29:56 +0000 Subject: [PATCH 02/20] Add step for updating Julia packages (#2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add step for updating julia packages * Appease clippy Authored-by: Jules Bertholet Approved-by: Thomas Schönauer --- src/config.rs | 3 ++- src/error.rs | 2 +- src/main.rs | 1 + src/steps/generic.rs | 11 +++++++++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 4e69b0b9..8078c45d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -62,7 +62,7 @@ macro_rules! get_deprecated { type Commands = BTreeMap; -#[derive(ArgEnum, EnumString, EnumVariantNames, Debug, Clone, PartialEq, Deserialize, EnumIter, Copy)] +#[derive(ArgEnum, EnumString, EnumVariantNames, Debug, Clone, PartialEq, Eq, Deserialize, EnumIter, Copy)] #[clap(rename_all = "snake_case")] #[serde(rename_all = "snake_case")] #[strum(serialize_all = "snake_case")] @@ -99,6 +99,7 @@ pub enum Step { GnomeShellExtensions, HomeManager, Jetpack, + Julia, Kakoune, Krew, Macports, diff --git a/src/error.rs b/src/error.rs index 34605806..5ec6ce75 100644 --- a/src/error.rs +++ b/src/error.rs @@ -2,7 +2,7 @@ use std::process::ExitStatus; use thiserror::Error; -#[derive(Error, Debug, PartialEq)] +#[derive(Error, Debug, PartialEq, Eq)] pub enum TopgradeError { #[error("{0}")] ProcessFailed(ExitStatus), diff --git a/src/main.rs b/src/main.rs index e47b1770..f6eea263 100644 --- a/src/main.rs +++ b/src/main.rs @@ -342,6 +342,7 @@ fn run() -> Result<()> { runner.execute(Step::Composer, "composer", || generic::run_composer_update(&ctx))?; runner.execute(Step::Krew, "krew", || generic::run_krew_upgrade(run_type))?; runner.execute(Step::Gem, "gem", || generic::run_gem(&base_dirs, run_type))?; + runner.execute(Step::Julia, "julia", || generic::update_julia_packages(&ctx))?; runner.execute(Step::Haxelib, "haxelib", || generic::run_haxelib_update(&ctx))?; runner.execute(Step::Sheldon, "sheldon", || generic::run_sheldon(&ctx))?; runner.execute(Step::Rtcl, "rtcl", || generic::run_rtcl(&ctx))?; diff --git a/src/steps/generic.rs b/src/steps/generic.rs index 698f10d8..485bd7d5 100644 --- a/src/steps/generic.rs +++ b/src/steps/generic.rs @@ -496,3 +496,14 @@ pub fn run_ghcli_extensions_upgrade(ctx: &ExecutionContext) -> Result<()> { .args(&["extension", "upgrade", "--all"]) .check_run() } + +pub fn update_julia_packages(ctx: &ExecutionContext) -> Result<()> { + let julia = utils::require("julia")?; + + print_separator("Julia Packages"); + + ctx.run_type() + .execute(&julia) + .args(&["-e", "using Pkg; Pkg.update()"]) + .check_run() +} From 6bfdc4974b5399d5cb472226b00d49aa68783909 Mon Sep 17 00:00:00 2001 From: DottoDev <37108907+DottoDev@users.noreply.github.com> Date: Mon, 10 Oct 2022 20:08:11 +0000 Subject: [PATCH 03/20] Add yarn support. Fix #958 (#15) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Authored-by: 0xMRTT <0xMRTT@tuta.io> Approved-by: Thomas Schönauer --- src/config.rs | 17 ++++++++++ src/main.rs | 1 + src/steps/node.rs | 83 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) diff --git a/src/config.rs b/src/config.rs index 8078c45d..5b6d150f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -168,6 +168,13 @@ pub struct Windows { enable_winget: Option, } +#[derive(Deserialize, Default, Debug)] +#[serde(deny_unknown_fields)] +#[allow(clippy::upper_case_acronyms)] +pub struct Yarn { + use_sudo: Option, +} + #[derive(Deserialize, Default, Debug)] #[serde(deny_unknown_fields)] #[allow(clippy::upper_case_acronyms)] @@ -270,6 +277,7 @@ pub struct ConfigFile { git: Option, windows: Option, npm: Option, + yarn: Option, vim: Option, firmware: Option, vagrant: Option, @@ -841,6 +849,15 @@ impl Config { .and_then(|npm| npm.use_sudo) .unwrap_or(false) } + #[cfg(target_os = "linux")] + pub fn yarn_use_sudo(&self) -> bool { + self.config_file + .yarn + .as_ref() + .and_then(|yarn| yarn.use_sudo) + .unwrap_or(false) + } + #[cfg(target_os = "linux")] pub fn firmware_upgrade(&self) -> bool { diff --git a/src/main.rs b/src/main.rs index f6eea263..a4231dc7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -337,6 +337,7 @@ fn run() -> Result<()> { runner.execute(Step::Vim, "voom", || vim::run_voom(&base_dirs, run_type))?; runner.execute(Step::Kakoune, "Kakoune", || kakoune::upgrade_kak_plug(&ctx))?; runner.execute(Step::Node, "npm", || node::run_npm_upgrade(&ctx))?; + runner.execute(Step::Node, "yarn", || node::run_yarn_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))?; diff --git a/src/steps/node.rs b/src/steps/node.rs index 2541e7cd..c27b4b45 100644 --- a/src/steps/node.rs +++ b/src/steps/node.rs @@ -88,6 +88,59 @@ impl NPM { } } +struct Yarn { + command: PathBuf, + yarn: Option, +} + +impl Yarn { + fn new(command: PathBuf) -> Self { + Self { + command, + yarn: require("yarn").ok(), + } + } + + #[cfg(target_os = "linux")] + fn root(&self) -> Result { + let args = ["global", "dir"]; + Command::new(&self.command) + .args(args) + .check_output() + .map(|s| PathBuf::from(s.trim())) + } + + fn upgrade(&self, run_type: RunType, use_sudo: bool) -> Result<()> { + print_separator("Yarn Package Manager"); + let args = ["global", "upgrade"]; + + if use_sudo { + run_type + .execute("sudo") + .arg(self.yarn.as_ref().unwrap_or(&self.command)) + .args(args) + .check_run()?; + } else { + run_type.execute(&self.command).args(args).check_run()?; + } + + Ok(()) + } + + #[cfg(target_os = "linux")] + pub fn should_use_sudo(&self) -> Result { + let yarn_root = self.root()?; + if !yarn_root.exists() { + return Err(SkipStep(format!("NPM root at {} doesn't exist", yarn_root.display(),)).into()); + } + + let metadata = std::fs::metadata(&yarn_root)?; + let uid = Uid::effective(); + + Ok(metadata.uid() != uid.as_raw() && metadata.uid() == 0) + } +} + #[cfg(target_os = "linux")] fn should_use_sudo(npm: &NPM, ctx: &ExecutionContext) -> Result { if npm.should_use_sudo()? { @@ -102,6 +155,20 @@ fn should_use_sudo(npm: &NPM, ctx: &ExecutionContext) -> Result { } } +#[cfg(target_os = "linux")] +fn should_use_sudo_yarn(yarn: &Yarn, ctx: &ExecutionContext) -> Result { + if yarn.should_use_sudo()? { + if ctx.config().yarn_use_sudo() { + Ok(true) + } else { + Err(SkipStep("NPM root is owned by another user which is not the current user. Set use_sudo = true under the NPM section in your configuration to run NPM as sudo".to_string()) + .into()) + } + } else { + Ok(false) + } +} + pub fn run_npm_upgrade(ctx: &ExecutionContext) -> Result<()> { let npm = require("npm").map(NPM::new)?; @@ -116,6 +183,22 @@ pub fn run_npm_upgrade(ctx: &ExecutionContext) -> Result<()> { } } +pub fn run_yarn_upgrade(ctx: &ExecutionContext) -> Result<()> { + let yarn = require("yarn").map(Yarn::new)?; + + #[cfg(target_os = "linux")] + { + yarn.upgrade(ctx.run_type(), should_use_sudo_yarn(&yarn, ctx)?) + } + + #[cfg(not(target_os = "linux"))] + { + yarn.upgrade(ctx.run_type(), false) + } +} + + + pub fn deno_upgrade(ctx: &ExecutionContext) -> Result<()> { let deno = require("deno")?; let deno_dir = ctx.base_dirs().home_dir().join(".deno"); From ffe8613b2ed955d9415748aa92d2af502942e23f Mon Sep 17 00:00:00 2001 From: DottoDev <37108907+DottoDev@users.noreply.github.com> Date: Mon, 10 Oct 2022 20:09:24 +0000 Subject: [PATCH 04/20] add pacdef support (#4) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Authored-by: arctic-penguin Approved-by: Thomas Schönauer --- src/config.rs | 1 + src/main.rs | 1 + src/steps/os/linux.rs | 11 +++++++++++ 3 files changed, 13 insertions(+) diff --git a/src/config.rs b/src/config.rs index 5b6d150f..d7c45696 100644 --- a/src/config.rs +++ b/src/config.rs @@ -109,6 +109,7 @@ pub enum Step { Nix, Node, Opam, + Pacdef, Pacstall, Pearl, Pipx, diff --git a/src/main.rs b/src/main.rs index a4231dc7..b1c29e28 100644 --- a/src/main.rs +++ b/src/main.rs @@ -365,6 +365,7 @@ fn run() -> Result<()> { runner.execute(Step::Flatpak, "Flatpak", || linux::flatpak_update(&ctx))?; runner.execute(Step::Snap, "snap", || linux::run_snap(sudo.as_ref(), run_type))?; runner.execute(Step::Pacstall, "pacstall", || linux::run_pacstall(&ctx))?; + runner.execute(Step::Pacdef, "pacdef", || linux::run_pacdef(&ctx))?; } if let Some(commands) = config.commands() { diff --git a/src/steps/os/linux.rs b/src/steps/os/linux.rs index 16171038..2b19600e 100644 --- a/src/steps/os/linux.rs +++ b/src/steps/os/linux.rs @@ -348,6 +348,17 @@ fn upgrade_solus(ctx: &ExecutionContext) -> Result<()> { Ok(()) } +pub fn run_pacdef(ctx: &ExecutionContext) -> Result<()> { + let pacdef = require("pacdef")?; + + print_separator("pacdef"); + + ctx.run_type().execute(&pacdef).arg("sync").check_run()?; + + println!(); + ctx.run_type().execute(&pacdef).arg("review").check_run() +} + pub fn run_pacstall(ctx: &ExecutionContext) -> Result<()> { let pacstall = require("pacstall")?; From aebf3f159442009c27e2d34b2397b840ef001a7a Mon Sep 17 00:00:00 2001 From: DottoDev <37108907+DottoDev@users.noreply.github.com> Date: Mon, 10 Oct 2022 20:15:30 +0000 Subject: [PATCH 05/20] Fix typo (to -> or) (#8) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Authored-by: Sohum Approved-by: Thomas Schönauer --- config.example.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.example.toml b/config.example.toml index 231a6e60..8ed8bdbe 100644 --- a/config.example.toml +++ b/config.example.toml @@ -87,7 +87,7 @@ # Causes Topgrade to rename itself during the run to allow package managers # to upgrade it. Use this only if you installed Topgrade by using a package -# manager such as Scoop to Cargo +# manager such as Scoop or Cargo #self_rename = true [npm] From 3f7614b8855c849843965bec92ae9b8719e8b0c1 Mon Sep 17 00:00:00 2001 From: DottoDev <37108907+DottoDev@users.noreply.github.com> Date: Mon, 10 Oct 2022 20:16:13 +0000 Subject: [PATCH 06/20] feat: add support for bun (#7) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Authored-by: Matthieu Vion Approved-by: Thomas Schönauer --- src/config.rs | 1 + src/main.rs | 1 + src/steps/bun.rs | 0 src/steps/os/unix.rs | 8 ++++++++ 4 files changed, 10 insertions(+) create mode 100644 src/steps/bun.rs diff --git a/src/config.rs b/src/config.rs index d7c45696..79fc9c33 100644 --- a/src/config.rs +++ b/src/config.rs @@ -71,6 +71,7 @@ pub enum Step { Atom, BrewCask, BrewFormula, + Bun, Bin, Cargo, Chezmoi, diff --git a/src/main.rs b/src/main.rs index b1c29e28..1757cdaa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -196,6 +196,7 @@ fn run() -> Result<()> { runner.execute(Step::HomeManager, "home-manager", || unix::run_home_manager(run_type))?; runner.execute(Step::Asdf, "asdf", || unix::run_asdf(run_type))?; runner.execute(Step::Pkgin, "pkgin", || unix::run_pkgin(&ctx))?; + runner.execute(Step::Bun, "bun", || unix::run_bun(&ctx))?; } #[cfg(target_os = "dragonfly")] diff --git a/src/steps/bun.rs b/src/steps/bun.rs new file mode 100644 index 00000000..e69de29b diff --git a/src/steps/os/unix.rs b/src/steps/os/unix.rs index a6c1468a..377d9ae8 100644 --- a/src/steps/os/unix.rs +++ b/src/steps/os/unix.rs @@ -409,6 +409,14 @@ pub fn run_sdkman(base_dirs: &BaseDirs, cleanup: bool, run_type: RunType) -> Res Ok(()) } +pub fn run_bun(ctx: &ExecutionContext) -> Result<()> { + let bun = require("bun")?; + + print_separator("Bun"); + + ctx.run_type().execute(&bun).arg("upgrade").check_run() +} + pub fn reboot() { print!("Rebooting..."); Command::new("sudo").arg("reboot").spawn().unwrap().wait().unwrap(); From 8472467d003f3efffafa9ac5d5851afdd2199b05 Mon Sep 17 00:00:00 2001 From: DottoDev <37108907+DottoDev@users.noreply.github.com> Date: Mon, 10 Oct 2022 20:17:50 +0000 Subject: [PATCH 07/20] brew autoremove (#6) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Authored-by: Kilian Tyler Approved-by: Thomas Schönauer --- config.example.toml | 1 + src/config.rs | 10 ++++++++++ src/steps/os/unix.rs | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/config.example.toml b/config.example.toml index 8ed8bdbe..5cc7eaea 100644 --- a/config.example.toml +++ b/config.example.toml @@ -64,6 +64,7 @@ [brew] #greedy_cask = true +#autoremove = true [linux] # Arch Package Manager to use. Allowed values: autodetect, trizen, paru, yay, pikaur, pacman, pamac. diff --git a/src/config.rs b/src/config.rs index 79fc9c33..fcfdcdee 100644 --- a/src/config.rs +++ b/src/config.rs @@ -202,6 +202,7 @@ pub struct Flatpak { #[serde(deny_unknown_fields)] pub struct Brew { greedy_cask: Option, + autoremove: Option, } #[derive(Debug, Deserialize, Clone, Copy)] @@ -668,6 +669,15 @@ impl Config { .unwrap_or(false) } + /// Whether Brew should autoremove + pub fn brew_autoremove(&self) -> bool { + self.config_file + .brew + .as_ref() + .and_then(|c| c.autoremove) + .unwrap_or(false) + } + /// Whether Composer should update itself pub fn composer_self_update(&self) -> bool { self.config_file diff --git a/src/steps/os/unix.rs b/src/steps/os/unix.rs index 377d9ae8..540d2ad3 100644 --- a/src/steps/os/unix.rs +++ b/src/steps/os/unix.rs @@ -210,6 +210,10 @@ pub fn run_brew_formula(ctx: &ExecutionContext, variant: BrewVariant) -> Result< variant.execute(run_type).arg("cleanup").check_run()?; } + if ctx.config().brew_autoremove() { + variant.execute(run_type).arg("autoremove").check_run()?; + } + Ok(()) } From dc1c5d64907330ebcdecf19d43edd0c915e318b5 Mon Sep 17 00:00:00 2001 From: DottoDev <37108907+DottoDev@users.noreply.github.com> Date: Mon, 10 Oct 2022 20:19:14 +0000 Subject: [PATCH 08/20] steps/linux/flatpak: Respect `-y` flag (#9) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit when deciding whether the `-y` argument should be added to an operation. Previously the `-y` was implicitly assumed for regular updates but was ignored for the cleanup steps. Now, it is added as defined in the topgrade runtime configuration. Authored-by: Andreas Hartmann Approved-by: Thomas Schönauer --- src/steps/os/linux.rs | 58 ++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/src/steps/os/linux.rs b/src/steps/os/linux.rs index 2b19600e..aa820095 100644 --- a/src/steps/os/linux.rs +++ b/src/steps/os/linux.rs @@ -502,44 +502,50 @@ pub fn flatpak_update(ctx: &ExecutionContext) -> Result<()> { let flatpak = require("flatpak")?; let sudo = require_option(ctx.sudo().as_ref(), String::from("sudo is not installed"))?; let cleanup = ctx.config().cleanup(); + let yes = ctx.config().yes(Step::Flatpak); let run_type = ctx.run_type(); print_separator("Flatpak User Packages"); - run_type - .execute(&flatpak) - .args(&["update", "--user", "-y"]) - .check_run()?; + let mut update_args = vec!["update", "--user"]; + if yes { + update_args.push("-y"); + } + run_type.execute(&flatpak).args(&update_args).check_run()?; + if cleanup { - run_type - .execute(&flatpak) - .args(&["uninstall", "--user", "--unused"]) - .check_run()?; + let mut cleanup_args = vec!["uninstall", "--user", "--unused"]; + if yes { + cleanup_args.push("-y"); + } + run_type.execute(&flatpak).args(&cleanup_args).check_run()?; } print_separator("Flatpak System Packages"); if ctx.config().flatpak_use_sudo() || std::env::var("SSH_CLIENT").is_ok() { - run_type - .execute(&sudo) - .arg(&flatpak) - .args(&["update", "--system", "-y"]) - .check_run()?; + let mut update_args = vec!["update", "--system"]; + if yes { + update_args.push("-y"); + } + run_type.execute(&sudo).arg(&flatpak).args(&update_args).check_run()?; if cleanup { - run_type - .execute(sudo) - .arg(flatpak) - .args(&["uninstall", "--system", "--unused"]) - .check_run()?; + let mut cleanup_args = vec!["uninstall", "--system", "--unused"]; + if yes { + cleanup_args.push("-y"); + } + run_type.execute(sudo).arg(flatpak).args(&cleanup_args).check_run()?; } } else { - run_type - .execute(&flatpak) - .args(&["update", "--system", "-y"]) - .check_run()?; + let mut update_args = vec!["update", "--system"]; + if yes { + update_args.push("-y"); + } + run_type.execute(&flatpak).args(&update_args).check_run()?; if cleanup { - run_type - .execute(flatpak) - .args(&["uninstall", "--system", "--unused"]) - .check_run()?; + let mut cleanup_args = vec!["uninstall", "--system", "--unused"]; + if yes { + cleanup_args.push("-y"); + } + run_type.execute(flatpak).args(&cleanup_args).check_run()?; } } From 2d94eb974f0f536883642a9547d5e5a5e5a1311a Mon Sep 17 00:00:00 2001 From: DottoDev <37108907+DottoDev@users.noreply.github.com> Date: Mon, 10 Oct 2022 20:21:20 +0000 Subject: [PATCH 09/20] feat: flag and config to skip notifications by jlucktay (#5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: flag and config to skip notifications At the end of a run, topgrade normally sends a system notification. This change adds a command-line flag and a config-file option to disable this behaviour. * fix: clippy issues Also derive Eq where PartialEq is being derived. https://rust-lang.github.io/rust-clippy/master/index.html#derive_partial_eq_without_eq Authored-by: James Lucktaylor Approved-by: Thomas Schönauer --- Cargo.lock | 2 +- Cargo.toml | 2 +- config.example.toml | 3 +++ src/config.rs | 14 ++++++++++++++ src/main.rs | 18 +++++++++++------- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d91d01ae..dcde0ca0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1834,7 +1834,7 @@ dependencies = [ [[package]] name = "topgrade" -version = "9.0.1" +version = "9.1.0" dependencies = [ "anyhow", "cfg-if", diff --git a/Cargo.toml b/Cargo.toml index 1c63663a..2a00c1ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ categories = ["os"] keywords = ["upgrade", "update"] license-file = "LICENSE" repository = "https://github.com/r-darwish/topgrade" -version = "9.0.1" +version = "9.1.0" authors = ["Roey Darwish Dror "] exclude = ["doc/screenshot.gif"] edition = "2018" diff --git a/config.example.toml b/config.example.toml index 5cc7eaea..df506e86 100644 --- a/config.example.toml +++ b/config.example.toml @@ -37,6 +37,9 @@ # Cleanup temporary or old files #cleanup = true +# Skip sending a notification at the end of a run +#skip_notify = true + [git] #max_concurrency = 5 # Additional git repositories to pull diff --git a/src/config.rs b/src/config.rs index fcfdcdee..001c242a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -272,6 +272,7 @@ pub struct ConfigFile { cleanup: Option, notify_each_step: Option, accept_all_windows_updates: Option, + skip_notify: Option, bashit_branch: Option, only: Option>, composer: Option, @@ -428,6 +429,10 @@ pub struct CommandLineArgs { #[clap(short = 'k', long = "keep")] keep_at_end: bool, + /// Skip sending a notification at the end of a run + #[clap(long = "skip-notify")] + skip_notify: bool, + /// Say yes to package manager's prompt #[clap(short = 'y', long = "yes", arg_enum, multiple_values = true, min_values = 0)] yes: Option>, @@ -613,6 +618,15 @@ impl Config { self.opt.keep_at_end || env::var("TOPGRADE_KEEP_END").is_ok() } + /// Skip sending a notification at the end of a run + pub fn skip_notify(&self) -> bool { + if let Some(yes) = self.config_file.skip_notify { + return yes; + } + + self.opt.skip_notify + } + /// Whether to set the terminal title pub fn set_title(&self) -> bool { self.config_file.set_title.unwrap_or(true) diff --git a/src/main.rs b/src/main.rs index 1757cdaa..ea591742 100644 --- a/src/main.rs +++ b/src/main.rs @@ -466,13 +466,17 @@ fn run() -> Result<()> { } let failed = post_command_failed || runner.report().data().iter().any(|(_, result)| result.failed()); - terminal::notify_desktop( - format!( - "Topgrade finished {}", - if failed { "with errors" } else { "successfully" } - ), - None, - ); + + if !config.skip_notify() { + terminal::notify_desktop( + format!( + "Topgrade finished {}", + if failed { "with errors" } else { "successfully" } + ), + None, + ); + } + if failed { Err(StepFailed.into()) } else { From ae544cdaae94f12b2804e1a5b2007a1073f108b5 Mon Sep 17 00:00:00 2001 From: DottoDev <37108907+DottoDev@users.noreply.github.com> Date: Mon, 10 Oct 2022 20:22:06 +0000 Subject: [PATCH 10/20] fix: skip nix on darwin only when nix-darwin is installed (#14) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Authored-by: XYenon Approved-by: Thomas Schönauer --- src/steps/os/unix.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/steps/os/unix.rs b/src/steps/os/unix.rs index 540d2ad3..5ee4687c 100644 --- a/src/steps/os/unix.rs +++ b/src/steps/os/unix.rs @@ -296,6 +296,16 @@ pub fn run_nix(ctx: &ExecutionContext) -> Result<()> { } } + #[cfg(target_os = "macos")] + { + if let Ok(..) = require("darwin-rebuild") { + return Err(SkipStep(String::from( + "Nix-darwin on macOS must be upgraded via darwin-rebuild switch", + )) + .into()); + } + } + let run_type = ctx.run_type(); if should_self_upgrade { From 27349b1571b0765ac428c8e428afec636c531553 Mon Sep 17 00:00:00 2001 From: DottoDev <37108907+DottoDev@users.noreply.github.com> Date: Mon, 10 Oct 2022 20:23:51 +0000 Subject: [PATCH 11/20] fix-pnpm (#3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Authored-by: Ved Kothavade Approved-by: Thomas Schönauer --- src/steps/node.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/steps/node.rs b/src/steps/node.rs index c27b4b45..91837673 100644 --- a/src/steps/node.rs +++ b/src/steps/node.rs @@ -20,15 +20,11 @@ use crate::{error::SkipStep, execution_context::ExecutionContext}; #[allow(clippy::upper_case_acronyms)] struct NPM { command: PathBuf, - pnpm: Option, } impl NPM { fn new(command: PathBuf) -> Self { - Self { - command, - pnpm: require("pnpm").ok(), - } + Self { command } } #[cfg(target_os = "linux")] @@ -56,17 +52,13 @@ impl NPM { fn upgrade(&self, run_type: RunType, use_sudo: bool) -> Result<()> { print_separator("Node Package Manager"); let version = self.version()?; - let args = if version < Version::new(8, 11, 0) || self.pnpm.is_some() { + let args = if version < Version::new(8, 11, 0) { ["update", "-g"] } else { ["update", "--location=global"] }; if use_sudo { - run_type - .execute("sudo") - .arg(self.pnpm.as_ref().unwrap_or(&self.command)) - .args(args) - .check_run()?; + run_type.execute("sudo").args(args).check_run()?; } else { run_type.execute(&self.command).args(args).check_run()?; } @@ -170,7 +162,7 @@ fn should_use_sudo_yarn(yarn: &Yarn, ctx: &ExecutionContext) -> Result { } pub fn run_npm_upgrade(ctx: &ExecutionContext) -> Result<()> { - let npm = require("npm").map(NPM::new)?; + let npm = require("pnpm").or_else(|_| require("npm")).map(NPM::new)?; #[cfg(target_os = "linux")] { From a9d5d24a358e4f82cdb38d7a30ad659870791f85 Mon Sep 17 00:00:00 2001 From: DottoDev <37108907+DottoDev@users.noreply.github.com> Date: Mon, 10 Oct 2022 20:24:41 +0000 Subject: [PATCH 12/20] Clean up OPAM if requested (#12) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OPAM has a built-in `clean` command that automatically removes download caches, logs, and cleans the current OPAM switch. We should call `opam clean` when the cleanup flag is set. Authored-by: Victor Song Approved-by: Thomas Schönauer --- src/main.rs | 2 +- src/steps/generic.rs | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index ea591742..5d8ac775 100644 --- a/src/main.rs +++ b/src/main.rs @@ -318,7 +318,7 @@ fn run() -> Result<()> { runner.execute(Step::Flutter, "Flutter", || generic::run_flutter_upgrade(run_type))?; runner.execute(Step::Go, "Go", || generic::run_go(run_type))?; runner.execute(Step::Emacs, "Emacs", || emacs.upgrade(&ctx))?; - runner.execute(Step::Opam, "opam", || generic::run_opam_update(run_type))?; + runner.execute(Step::Opam, "opam", || generic::run_opam_update(&ctx))?; runner.execute(Step::Vcpkg, "vcpkg", || generic::run_vcpkg_update(run_type))?; runner.execute(Step::Pipx, "pipx", || generic::run_pipx_update(run_type))?; runner.execute(Step::Conda, "conda", || generic::run_conda_update(&ctx))?; diff --git a/src/steps/generic.rs b/src/steps/generic.rs index 485bd7d5..9f7dae43 100644 --- a/src/steps/generic.rs +++ b/src/steps/generic.rs @@ -220,13 +220,19 @@ pub fn run_rtcl(ctx: &ExecutionContext) -> Result<()> { ctx.run_type().execute(&rupdate).check_run() } -pub fn run_opam_update(run_type: RunType) -> Result<()> { +pub fn run_opam_update(ctx: &ExecutionContext) -> Result<()> { let opam = utils::require("opam")?; print_separator("OCaml Package Manager"); - run_type.execute(&opam).arg("update").check_run()?; - run_type.execute(&opam).arg("upgrade").check_run() + ctx.run_type().execute(&opam).arg("update").check_run()?; + ctx.run_type().execute(&opam).arg("upgrade").check_run()?; + + if ctx.config().cleanup() { + ctx.run_type().execute(&opam).arg("clean").check_run()?; + } + + Ok(()) } pub fn run_vcpkg_update(run_type: RunType) -> Result<()> { From f063afe536ae54ed2cc209938d3d2a5642bf4085 Mon Sep 17 00:00:00 2001 From: DottoDev <37108907+DottoDev@users.noreply.github.com> Date: Mon, 10 Oct 2022 20:26:20 +0000 Subject: [PATCH 13/20] Fix doom emacs upgrading (fix #961) (#13) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Authored-by: Rotem Yaari Approved-by: Thomas Schönauer --- src/steps/emacs.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/steps/emacs.rs b/src/steps/emacs.rs index 862ff16d..75ab817b 100644 --- a/src/steps/emacs.rs +++ b/src/steps/emacs.rs @@ -67,25 +67,24 @@ impl Emacs { print_separator("Doom Emacs"); let mut command = ctx.run_type().execute(doom); - command.args(&["-y", "upgrade"]); - if ctx.config().yes(Step::Emacs) { command.arg("--force"); } + command.args(&["upgrade"]); + command.check_run() } pub fn upgrade(&self, ctx: &ExecutionContext) -> Result<()> { let emacs = require("emacs")?; + if let Some(doom) = &self.doom { + Emacs::update_doom(doom, ctx)?; + } let init_file = require_option(self.directory.as_ref(), String::from("Emacs directory does not exist"))? .join("init.el") .require()?; - if let Some(doom) = &self.doom { - return Emacs::update_doom(doom, ctx); - } - print_separator("Emacs"); let mut command = ctx.run_type().execute(&emacs); From 77db29f299173d735e0cabe352bf3ae2a21d2c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sch=C3=B6nauer?= Date: Mon, 10 Oct 2022 22:41:39 +0200 Subject: [PATCH 14/20] Cleanup --- src/config.rs | 1 - src/steps/node.rs | 4 +--- src/steps/os/unix.rs | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index 001c242a..09aab522 100644 --- a/src/config.rs +++ b/src/config.rs @@ -883,7 +883,6 @@ impl Config { .and_then(|yarn| yarn.use_sudo) .unwrap_or(false) } - #[cfg(target_os = "linux")] pub fn firmware_upgrade(&self) -> bool { diff --git a/src/steps/node.rs b/src/steps/node.rs index 91837673..6d22d07e 100644 --- a/src/steps/node.rs +++ b/src/steps/node.rs @@ -105,7 +105,7 @@ impl Yarn { fn upgrade(&self, run_type: RunType, use_sudo: bool) -> Result<()> { print_separator("Yarn Package Manager"); let args = ["global", "upgrade"]; - + if use_sudo { run_type .execute("sudo") @@ -189,8 +189,6 @@ pub fn run_yarn_upgrade(ctx: &ExecutionContext) -> Result<()> { } } - - pub fn deno_upgrade(ctx: &ExecutionContext) -> Result<()> { let deno = require("deno")?; let deno_dir = ctx.base_dirs().home_dir().join(".deno"); diff --git a/src/steps/os/unix.rs b/src/steps/os/unix.rs index 5ee4687c..cdbc9ad3 100644 --- a/src/steps/os/unix.rs +++ b/src/steps/os/unix.rs @@ -270,7 +270,7 @@ pub fn run_guix(ctx: &ExecutionContext) -> Result<()> { if should_upgrade { return run_type.execute(&guix).args(&["package", "-u"]).check_run(); } - Err(SkipStep(String::from("Guix Pull Failed, Skipping")).into()) + Err(SkipStep(String::from("Guix Pull Failed, Skipping")).into()) } pub fn run_nix(ctx: &ExecutionContext) -> Result<()> { From 646b56dc9d29f1286db665fecb40fb111041cf46 Mon Sep 17 00:00:00 2001 From: DottoDev <37108907+DottoDev@users.noreply.github.com> Date: Mon, 10 Oct 2022 20:59:07 +0000 Subject: [PATCH 15/20] Add rust ubuntu runner (#16) * Update issue templates * Create rust-ubuntu.yml Added plain Github Action Runner for ubuntu --- .github/ISSUE_TEMPLATE/bug_report.md | 5 ++++- .github/ISSUE_TEMPLATE/feature_request.md | 5 ++++- .github/workflows/rust-ubuntu.yml | 24 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/rust-ubuntu.yml diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index da49501a..1ea4de5a 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,7 +1,10 @@ --- name: Bug report about: Topgrade is misbehaving -labels: is:bug +title: '' +labels: '' +assignees: '' + --- diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 6bbd46d6..94f39e57 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,7 +1,10 @@ --- name: Feature request about: Can you please support...? -labels: is:new +title: '' +labels: '' +assignees: '' + --- ## I want to suggest a new step diff --git a/.github/workflows/rust-ubuntu.yml b/.github/workflows/rust-ubuntu.yml new file mode 100644 index 00000000..18bcd0ae --- /dev/null +++ b/.github/workflows/rust-ubuntu.yml @@ -0,0 +1,24 @@ +name: Rust + +on: + push: + branches: [ "master", "dev" ] + pull_request: + branches: [ "master", "dev" ] + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Build + run: cargo build --verbose + - name: Fmt + run: cargo fmt --check --all + - name: Run tests + run: cargo test --verbose From ce5211e0b4e8f7c2406b69e4733234419115bba8 Mon Sep 17 00:00:00 2001 From: DottoDev <37108907+DottoDev@users.noreply.github.com> Date: Tue, 11 Oct 2022 16:10:52 +0000 Subject: [PATCH 16/20] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index f339f966..cf90eaa5 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,10 @@ ![Demo](doc/screenshot.gif) +##Fork +This is a fork of [topgrade by r-darwish](https://github.com/r-darwish/topgrade) to keep it maintained. + + Keeping your system up to date usually involves invoking multiple package managers. This results in big, non-portable shell one-liners saved in your shell. To remedy this, _topgrade_ detects which tools you use and runs the appropriate commands to update them. From de6590440fbe23aed0006433d7a832c3591614d6 Mon Sep 17 00:00:00 2001 From: DottoDev <37108907+DottoDev@users.noreply.github.com> Date: Tue, 11 Oct 2022 16:11:12 +0000 Subject: [PATCH 17/20] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cf90eaa5..d88299e6 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ ![Demo](doc/screenshot.gif) -##Fork +## Fork This is a fork of [topgrade by r-darwish](https://github.com/r-darwish/topgrade) to keep it maintained. From f50c26cc97f8beef06d4c3573de396fe0631807a Mon Sep 17 00:00:00 2001 From: DottoDev <37108907+DottoDev@users.noreply.github.com> Date: Tue, 11 Oct 2022 18:01:09 +0000 Subject: [PATCH 18/20] Create build-and-test.yml --- .github/workflows/build-and-test.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/build-and-test.yml diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 00000000..f520b42e --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,24 @@ +name: Cargo Build & Test + +on: + push: + pull_request: + +env: + CARGO_TERM_COLOR: always + +jobs: + build_and_test: + name: Rust project - latest + runs-on: ubuntu-latest + strategy: + matrix: + toolchain: + - stable + - beta + - nightly + steps: + - uses: actions/checkout@v3 + - run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} + - run: cargo build --verbose + - run: cargo test --verbose From 366a742d408ac9ad03855e215a121b88291e8b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sch=C3=B6nauer?= Date: Fri, 14 Oct 2022 16:46:21 +0200 Subject: [PATCH 19/20] Added Protonup support --- src/config.rs | 1 + src/main.rs | 1 + src/steps/os/linux.rs | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/src/config.rs b/src/config.rs index 09aab522..1428be5b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -118,6 +118,7 @@ pub enum Step { Pkg, Pkgin, Powershell, + Protonup, Raco, Remotes, Restarts, diff --git a/src/main.rs b/src/main.rs index 5d8ac775..cdcfe9e2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -367,6 +367,7 @@ fn run() -> Result<()> { runner.execute(Step::Snap, "snap", || linux::run_snap(sudo.as_ref(), run_type))?; runner.execute(Step::Pacstall, "pacstall", || linux::run_pacstall(&ctx))?; runner.execute(Step::Pacdef, "pacdef", || linux::run_pacdef(&ctx))?; + runner.execute(Step::Protonup, "protonup", || linux::run_protonup_update(&ctx))?; } if let Some(commands) = config.commands() { diff --git a/src/steps/os/linux.rs b/src/steps/os/linux.rs index aa820095..6854a0b9 100644 --- a/src/steps/os/linux.rs +++ b/src/steps/os/linux.rs @@ -574,6 +574,10 @@ pub fn run_pihole_update(sudo: Option<&PathBuf>, run_type: RunType) -> Result<() run_type.execute(sudo).arg(pihole).arg("-up").check_run() } +pub fn run_protonup_update(ctx: &ExecutionContext) -> Result<()> { + todo!(); +} + pub fn run_config_update(ctx: &ExecutionContext) -> Result<()> { let sudo = require_option(ctx.sudo().as_ref(), String::from("sudo is not installed"))?; if ctx.config().yes(Step::ConfigUpdate) { From b2c9c746a548ac5547ed79828325dfc22b6c4f7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sch=C3=B6nauer?= Date: Fri, 14 Oct 2022 16:56:03 +0200 Subject: [PATCH 20/20] Added Protonup update code --- src/steps/os/linux.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/steps/os/linux.rs b/src/steps/os/linux.rs index 6854a0b9..96d3e7c2 100644 --- a/src/steps/os/linux.rs +++ b/src/steps/os/linux.rs @@ -575,7 +575,12 @@ pub fn run_pihole_update(sudo: Option<&PathBuf>, run_type: RunType) -> Result<() } pub fn run_protonup_update(ctx: &ExecutionContext) -> Result<()> { - todo!(); + let protonup = require("protonup")?; + + print_separator("protonup"); + + ctx.run_type().execute(protonup).check_run()?; + Ok(()) } pub fn run_config_update(ctx: &ExecutionContext) -> Result<()> {