From 3d6db70cdb118de6c43a8069d3837d0725206c27 Mon Sep 17 00:00:00 2001 From: Dmitry Nefedov Date: Sat, 27 Dec 2025 18:51:19 +0300 Subject: [PATCH] Updated Chocolatey script --- .github/workflows/Chocolatey.yml | 48 +++----------------------------- Scripts/chocolatey.ps1 | 43 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 44 deletions(-) create mode 100644 Scripts/chocolatey.ps1 diff --git a/.github/workflows/Chocolatey.yml b/.github/workflows/Chocolatey.yml index 470c5b9f..85b1a4fd 100644 --- a/.github/workflows/Chocolatey.yml +++ b/.github/workflows/Chocolatey.yml @@ -13,53 +13,13 @@ jobs: - name: Preparation run: | - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json" - UseBasicParsing = $true - Verbose = $true - } - $Latest_Release = Invoke-RestMethod @Parameters - - $Parameters = @{ - Uri = "https://api.github.com/repos/farag2/Sophia-Script-for-Windows/releases/latest" - UseBasicParsing = $true - Verbose = $true - } - $assets = (Invoke-RestMethod @Parameters).assets - - # Get SHA256 hash sum of each asset - $Sophia_Script_Windows_10_PowerShell_5_1 = ($assets | Where-Object -FilterScript {$_.name -eq "Sophia.Script.for.Windows.10.v$($Latest_Release.Sophia_Script_Windows_10_PowerShell_5_1).zip"}).digest.Replace("sha256:", "") - $Sophia_Script_Windows_10_PowerShell_7 = ($assets | Where-Object -FilterScript {$_.name -eq "Sophia.Script.for.Windows.10.PowerShell.7.v$($Latest_Release.Sophia_Script_Windows_10_PowerShell_7).zip"}).digest.Replace("sha256:", "") - $Sophia_Script_Windows_10_LTSC2019 = ($assets | Where-Object -FilterScript {$_.name -eq "Sophia.Script.for.Windows.10.LTSC.2019.v$($Latest_Release.Sophia_Script_Windows_10_LTSC2019).zip"}).digest.Replace("sha256:", "") - $Sophia_Script_Windows_10_LTSC2021 = ($assets | Where-Object -FilterScript {$_.name -eq "Sophia.Script.for.Windows.10.LTSC.2021.v$($Latest_Release.Sophia_Script_Windows_10_LTSC2021).zip"}).digest.Replace("sha256:", "") - $Sophia_Script_Windows_11_PowerShell_5_1 = ($assets | Where-Object -FilterScript {$_.name -eq "Sophia.Script.for.Windows.11.v$($Latest_Release.Sophia_Script_Windows_11_PowerShell_5_1).zip"}).digest.Replace("sha256:", "") - $Sophia_Script_Windows_11_Arm_PowerShell_5_1 = ($assets | Where-Object -FilterScript {$_.name -eq "Sophia.Script.for.Windows.11.v$($Latest_Release.Sophia_Script_Windows_11_Arm_PowerShell_5_1).zip"}).digest.Replace("sha256:", "") - $Sophia_Script_Windows_11_Arm_PowerShell_7 = ($assets | Where-Object -FilterScript {$_.name -eq "Sophia.Script.for.Windows.11.v$($Latest_Release.Sophia_Script_Windows_11_Arm_PowerShell_7).zip"}).digest.Replace("sha256:", "") - $Sophia_Script_Windows_11_PowerShell_7 = ($assets | Where-Object -FilterScript {$_.name -eq "Sophia.Script.for.Windows.11.PowerShell.7.v$($Latest_Release.Sophia_Script_Windows_11_PowerShell_7).zip"}).digest.Replace("sha256:", "") - $Sophia_Script_Windows_11_LTSC2024 = ($assets | Where-Object -FilterScript {$_.name -eq "Sophia.Script.for.Windows.11.LTSC.2024.v$($Latest_Release.Sophia_Script_Windows_11_LTSC2024).zip"}).digest.Replace("sha256:", "") - $Sophia_Script_Wrapper = ($assets | Where-Object -FilterScript {$_.name -eq "Sophia.Script.Wrapper.v$($Latest_Release.Sophia_Script_Wrapper).zip"}).digest.Replace("sha256:", "") - - # Replace variables with script latest versions - (Get-Content -Path "chocolatey\tools\chocolateyinstall.ps1" -Encoding utf8 -Raw) | Foreach-Object -Process { - $_ -replace "Hash_Sophia_Script_Windows_10_PowerShell_5_1", $Sophia_Script_Windows_10_PowerShell_5_1 ` - -replace "Hash_Sophia_Script_Windows_10_PowerShell_7", $Sophia_Script_Windows_10_PowerShell_7 ` - -replace "Hash_Sophia_Script_Windows_10_LTSC2019", $Sophia_Script_Windows_10_LTSC2019 ` - -replace "Hash_Sophia_Script_Windows_10_LTSC2021", $Sophia_Script_Windows_10_LTSC2021 ` - -replace "Hash_Sophia_Script_Windows_11_PowerShell_5_1", $Sophia_Script_Windows_11_PowerShell_5_1 ` - -replace "Hash_Sophia_Script_Windows_11_Arm_PowerShell_5_1", $Sophia_Script_Windows_11_Arm_PowerShell_5_1 ` - -replace "Hash_Sophia_Script_Windows_11_Arm_PowerShell_7", $Sophia_Script_Windows_11_Arm_PowerShell_7 ` - -replace "Hash_Sophia_Script_Windows_11_PowerShell_7", $Sophia_Script_Windows_11_PowerShell_7 ` - -replace "Hash_Sophia_Script_Windows_11_LTSC2024", $Sophia_Script_Windows_11_LTSC2024 ` - -replace "Hash_Sophia_Script_Wrapper", $Sophia_Script_Wrapper - } | Set-Content -Path "chocolatey\tools\chocolateyinstall.ps1" -Encoding utf8 -Force - - # Save latest release tag for sophia.nuspec - $Latest_Release = $Latest_Release.Sophia_Script_Windows_11_PowerShell_5_1 - echo "Latest_Release=$Latest_Release" >> $env:GITHUB_ENV + . "Scripts\Chocolatey.ps1" - name: Pack and push to Chocolatey + env: + Latest_Release: ${{ secrets.Latest_Release }} run: | - Write-Verbose -Message "${{ env.Latest_Release }}" -Verbose + Write-Verbose -Message $env.Latest_Release -Verbose # Replace variables with script latest versions (Get-Content -Path "chocolatey\sophia.nuspec" -Encoding utf8NoBOM -Raw) -replace ("SophiaScriptVersion", "${{ env.Latest_Release }}") | Set-Content -Path "chocolatey\sophia.nuspec" -Encoding utf8NoBOM -Force diff --git a/Scripts/chocolatey.ps1 b/Scripts/chocolatey.ps1 new file mode 100644 index 00000000..2c4b8048 --- /dev/null +++ b/Scripts/chocolatey.ps1 @@ -0,0 +1,43 @@ +$Parameters = @{ + Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json" + UseBasicParsing = $true + Verbose = $true +} +$Latest_Release = Invoke-RestMethod @Parameters + +$Parameters = @{ + Uri = "https://api.github.com/repos/farag2/Sophia-Script-for-Windows/releases/latest" + UseBasicParsing = $true + Verbose = $true +} +$assets = (Invoke-RestMethod @Parameters).assets + +# Get SHA256 hash sum of each asset +$Sophia_Script_Windows_10_PowerShell_5_1 = ($assets | Where-Object -FilterScript {$_.name -eq "Sophia.Script.for.Windows.10.v$($Latest_Release.Sophia_Script_Windows_10_PowerShell_5_1).zip"}).digest.Replace("sha256:", "") +$Sophia_Script_Windows_10_PowerShell_7 = ($assets | Where-Object -FilterScript {$_.name -eq "Sophia.Script.for.Windows.10.PowerShell.7.v$($Latest_Release.Sophia_Script_Windows_10_PowerShell_7).zip"}).digest.Replace("sha256:", "") +$Sophia_Script_Windows_10_LTSC2019 = ($assets | Where-Object -FilterScript {$_.name -eq "Sophia.Script.for.Windows.10.LTSC.2019.v$($Latest_Release.Sophia_Script_Windows_10_LTSC2019).zip"}).digest.Replace("sha256:", "") +$Sophia_Script_Windows_10_LTSC2021 = ($assets | Where-Object -FilterScript {$_.name -eq "Sophia.Script.for.Windows.10.LTSC.2021.v$($Latest_Release.Sophia_Script_Windows_10_LTSC2021).zip"}).digest.Replace("sha256:", "") +$Sophia_Script_Windows_11_PowerShell_5_1 = ($assets | Where-Object -FilterScript {$_.name -eq "Sophia.Script.for.Windows.11.v$($Latest_Release.Sophia_Script_Windows_11_PowerShell_5_1).zip"}).digest.Replace("sha256:", "") +$Sophia_Script_Windows_11_Arm_PowerShell_5_1 = ($assets | Where-Object -FilterScript {$_.name -eq "Sophia.Script.for.Windows.11.v$($Latest_Release.Sophia_Script_Windows_11_Arm_PowerShell_5_1).zip"}).digest.Replace("sha256:", "") +$Sophia_Script_Windows_11_Arm_PowerShell_7 = ($assets | Where-Object -FilterScript {$_.name -eq "Sophia.Script.for.Windows.11.v$($Latest_Release.Sophia_Script_Windows_11_Arm_PowerShell_7).zip"}).digest.Replace("sha256:", "") +$Sophia_Script_Windows_11_PowerShell_7 = ($assets | Where-Object -FilterScript {$_.name -eq "Sophia.Script.for.Windows.11.PowerShell.7.v$($Latest_Release.Sophia_Script_Windows_11_PowerShell_7).zip"}).digest.Replace("sha256:", "") +$Sophia_Script_Windows_11_LTSC2024 = ($assets | Where-Object -FilterScript {$_.name -eq "Sophia.Script.for.Windows.11.LTSC.2024.v$($Latest_Release.Sophia_Script_Windows_11_LTSC2024).zip"}).digest.Replace("sha256:", "") +$Sophia_Script_Wrapper = ($assets | Where-Object -FilterScript {$_.name -eq "Sophia.Script.Wrapper.v$($Latest_Release.Sophia_Script_Wrapper).zip"}).digest.Replace("sha256:", "") + +# Replace variables with script latest versions +(Get-Content -Path "chocolatey\tools\chocolateyinstall.ps1" -Encoding utf8 -Raw) | Foreach-Object -Process { + $_ -replace "Hash_Sophia_Script_Windows_10_PowerShell_5_1", $Sophia_Script_Windows_10_PowerShell_5_1 ` + -replace "Hash_Sophia_Script_Windows_10_PowerShell_7", $Sophia_Script_Windows_10_PowerShell_7 ` + -replace "Hash_Sophia_Script_Windows_10_LTSC2019", $Sophia_Script_Windows_10_LTSC2019 ` + -replace "Hash_Sophia_Script_Windows_10_LTSC2021", $Sophia_Script_Windows_10_LTSC2021 ` + -replace "Hash_Sophia_Script_Windows_11_PowerShell_5_1", $Sophia_Script_Windows_11_PowerShell_5_1 ` + -replace "Hash_Sophia_Script_Windows_11_Arm_PowerShell_5_1", $Sophia_Script_Windows_11_Arm_PowerShell_5_1 ` + -replace "Hash_Sophia_Script_Windows_11_Arm_PowerShell_7", $Sophia_Script_Windows_11_Arm_PowerShell_7 ` + -replace "Hash_Sophia_Script_Windows_11_PowerShell_7", $Sophia_Script_Windows_11_PowerShell_7 ` + -replace "Hash_Sophia_Script_Windows_11_LTSC2024", $Sophia_Script_Windows_11_LTSC2024 ` + -replace "Hash_Sophia_Script_Wrapper", $Sophia_Script_Wrapper +} | Set-Content -Path "chocolatey\tools\chocolateyinstall.ps1" -Encoding utf8 -Force + +# Save latest release tag for sophia.nuspec +$Latest_Release = $Latest_Release.Sophia_Script_Windows_11_PowerShell_5_1 +echo "Latest_Release=$Latest_Release" >> $env:GITHUB_ENV