From c6befe943ff8276f68aaef3e9da25072fa9ec5c8 Mon Sep 17 00:00:00 2001 From: Nils <52573120+niStee@users.noreply.github.com> Date: Sat, 2 Nov 2024 14:46:56 +0100 Subject: [PATCH 1/6] feat: add workflow steps to fetch latest release info and update WinGet package --- .github/workflows/release_to_winget.yml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release_to_winget.yml b/.github/workflows/release_to_winget.yml index f81cf1f5..bf96c7cb 100644 --- a/.github/workflows/release_to_winget.yml +++ b/.github/workflows/release_to_winget.yml @@ -10,4 +10,23 @@ jobs: with: identifier: topgrade-rs.topgrade max-versions-to-keep: 5 # keep only latest 5 versions - token: ${{ secrets.WINGET_TOKEN }} \ No newline at end of file + token: ${{ secrets.WINGET_TOKEN }} + - name: Get latest release information + id: get_release_info + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + $ReleaseInfo = Invoke-RestMethod ` + -Uri 'https://api.github.com/repos/topgrade-rs/topgrade/releases/latest' ` + -Headers @{ Authorization = "token $env:GITHUB_TOKEN" } + Write-Output "Release Info: $ReleaseInfo" + echo "::set-output name=version::$(echo $ReleaseInfo.tag_name -replace '^v')" + echo "::set-output name=urls::$(echo $ReleaseInfo.assets.Where({ $_.name -match '.(exe|msi|msix|appx)(bundle){0,1}$' }).browser_download_url -join ' ')" + - name: Update WinGet package + env: + KOMAC_FORK_OWNER: topgrade-rs + KOMAC_CREATED_WITH: WinGet Releaser + KOMAC_CREATED_WITH_URL: https://github.com/vedantmgoyal2009/winget-releaser + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + komac update 'topgrade-rs.topgrade' --version '${{ steps.get_release_info.outputs.version }}' --submit --urls '${{ steps.get_release_info.outputs.urls }}' \ No newline at end of file From af66f2440009f9120aa64a98bbcfb164a7e2af08 Mon Sep 17 00:00:00 2001 From: Nils <52573120+niStee@users.noreply.github.com> Date: Sat, 2 Nov 2024 15:14:17 +0100 Subject: [PATCH 2/6] feat: enhance Powershell module update process with unload and reload steps --- src/steps/powershell.rs | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/steps/powershell.rs b/src/steps/powershell.rs index bf81b3ef..bd75ead5 100644 --- a/src/steps/powershell.rs +++ b/src/steps/powershell.rs @@ -64,24 +64,37 @@ impl Powershell { pub fn update_modules(&self, ctx: &ExecutionContext) -> Result<()> { let powershell = require_option(self.path.as_ref(), t!("Powershell is not installed").to_string())?; - + print_separator(t!("Powershell Modules Update")); - - let mut cmd = vec!["Update-Module"]; - + + let mut unload_cmd = vec!["Get-Module | Remove-Module -Force"]; + let mut update_cmd = vec!["Update-Module"]; + let mut reload_cmd = vec!["Get-Module -ListAvailable | Import-Module"]; + if ctx.config().verbose() { - cmd.push("-Verbose") + update_cmd.push("-Verbose"); } - + if ctx.config().yes(Step::Powershell) { - cmd.push("-Force") + update_cmd.push("-Force"); } - + + println!("{}", t!("Unloading modules...")); + ctx.run_type() + .execute(powershell) + .args(["-NoProfile", "-Command", &unload_cmd.join(" ")]) + .status_checked()?; + println!("{}", t!("Updating modules...")); ctx.run_type() .execute(powershell) - // This probably doesn't need `shell_words::join`. - .args(["-NoProfile", "-Command", &cmd.join(" ")]) + .args(["-NoProfile", "-Command", &update_cmd.join(" ")]) + .status_checked()?; + + println!("{}", t!("Reloading modules...")); + ctx.run_type() + .execute(powershell) + .args(["-NoProfile", "-Command", &reload_cmd.join(" ")]) .status_checked() } @@ -158,4 +171,4 @@ impl Powershell { }) .map(|_| ()) } -} +} \ No newline at end of file From 8a48a1d986b479056d868094dc10f8704bc64c2c Mon Sep 17 00:00:00 2001 From: Nils <52573120+niStee@users.noreply.github.com> Date: Sat, 2 Nov 2024 15:20:50 +0100 Subject: [PATCH 3/6] run cargo fmt --- src/steps/powershell.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/steps/powershell.rs b/src/steps/powershell.rs index bd75ead5..5320a09e 100644 --- a/src/steps/powershell.rs +++ b/src/steps/powershell.rs @@ -64,33 +64,33 @@ impl Powershell { pub fn update_modules(&self, ctx: &ExecutionContext) -> Result<()> { let powershell = require_option(self.path.as_ref(), t!("Powershell is not installed").to_string())?; - + print_separator(t!("Powershell Modules Update")); - + let mut unload_cmd = vec!["Get-Module | Remove-Module -Force"]; let mut update_cmd = vec!["Update-Module"]; let mut reload_cmd = vec!["Get-Module -ListAvailable | Import-Module"]; - + if ctx.config().verbose() { update_cmd.push("-Verbose"); } - + if ctx.config().yes(Step::Powershell) { update_cmd.push("-Force"); } - + println!("{}", t!("Unloading modules...")); ctx.run_type() .execute(powershell) .args(["-NoProfile", "-Command", &unload_cmd.join(" ")]) .status_checked()?; - + println!("{}", t!("Updating modules...")); ctx.run_type() .execute(powershell) .args(["-NoProfile", "-Command", &update_cmd.join(" ")]) .status_checked()?; - + println!("{}", t!("Reloading modules...")); ctx.run_type() .execute(powershell) @@ -171,4 +171,4 @@ impl Powershell { }) .map(|_| ()) } -} \ No newline at end of file +} From 5ac1a2de49982b2fc29527ad1713765daee70f78 Mon Sep 17 00:00:00 2001 From: Nils <52573120+niStee@users.noreply.github.com> Date: Sat, 2 Nov 2024 15:57:51 +0100 Subject: [PATCH 4/6] refactor: simplify command variable declarations in Powershell module update --- src/steps/powershell.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/steps/powershell.rs b/src/steps/powershell.rs index 5320a09e..4227bfd6 100644 --- a/src/steps/powershell.rs +++ b/src/steps/powershell.rs @@ -67,9 +67,9 @@ impl Powershell { print_separator(t!("Powershell Modules Update")); - let mut unload_cmd = vec!["Get-Module | Remove-Module -Force"]; + let unload_cmd = ["Get-Module | Remove-Module -Force"]; let mut update_cmd = vec!["Update-Module"]; - let mut reload_cmd = vec!["Get-Module -ListAvailable | Import-Module"]; + let reload_cmd = ["Get-Module -ListAvailable | Import-Module"]; if ctx.config().verbose() { update_cmd.push("-Verbose"); From 0acbf0ad5aa8d0df3475e5638370223e3db4ea86 Mon Sep 17 00:00:00 2001 From: Nils <52573120+niStee@users.noreply.github.com> Date: Sat, 2 Nov 2024 16:17:39 +0100 Subject: [PATCH 5/6] refactor: remove modified WinGet workflow --- .github/workflows/release_to_winget.yml | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/.github/workflows/release_to_winget.yml b/.github/workflows/release_to_winget.yml index bf96c7cb..f81cf1f5 100644 --- a/.github/workflows/release_to_winget.yml +++ b/.github/workflows/release_to_winget.yml @@ -10,23 +10,4 @@ jobs: with: identifier: topgrade-rs.topgrade max-versions-to-keep: 5 # keep only latest 5 versions - token: ${{ secrets.WINGET_TOKEN }} - - name: Get latest release information - id: get_release_info - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - $ReleaseInfo = Invoke-RestMethod ` - -Uri 'https://api.github.com/repos/topgrade-rs/topgrade/releases/latest' ` - -Headers @{ Authorization = "token $env:GITHUB_TOKEN" } - Write-Output "Release Info: $ReleaseInfo" - echo "::set-output name=version::$(echo $ReleaseInfo.tag_name -replace '^v')" - echo "::set-output name=urls::$(echo $ReleaseInfo.assets.Where({ $_.name -match '.(exe|msi|msix|appx)(bundle){0,1}$' }).browser_download_url -join ' ')" - - name: Update WinGet package - env: - KOMAC_FORK_OWNER: topgrade-rs - KOMAC_CREATED_WITH: WinGet Releaser - KOMAC_CREATED_WITH_URL: https://github.com/vedantmgoyal2009/winget-releaser - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - komac update 'topgrade-rs.topgrade' --version '${{ steps.get_release_info.outputs.version }}' --submit --urls '${{ steps.get_release_info.outputs.urls }}' \ No newline at end of file + token: ${{ secrets.WINGET_TOKEN }} \ No newline at end of file From 4d20d04810d82b33f7396fea5f6e05820edf1c66 Mon Sep 17 00:00:00 2001 From: Nils <52573120+niStee@users.noreply.github.com> Date: Sat, 9 Nov 2024 18:28:45 +0100 Subject: [PATCH 6/6] feat: add localization for unloading and reloading modules in app.yml --- locales/app.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/locales/app.yml b/locales/app.yml index 838a525d..41c2197a 100644 --- a/locales/app.yml +++ b/locales/app.yml @@ -65,6 +65,16 @@ _version: 2 es: "Actualizando módulos..." fr: "Mise à jour des modules..." zh_TW: "正在更新模組..." +"Unloading modules...": + en: "Unloading modules..." + es: "Descarga de módulos..." + fr: "Déchargement des modules..." + zh_TW: "正在卸載模組..." +"Reloading modules...": + en: "Reloading modules..." + es: "Módulos de recarga..." + fr: "Modules de rechargement..." + zh_TW: "正在重裝模組..." "Powershell Modules Update": en: "Powershell Modules Update" es: "Actualización de módulos Powershell"