diff --git a/.github/workflows/Chocolatey.yml b/.github/workflows/Chocolatey.yml index b73eb748..470c5b9f 100644 --- a/.github/workflows/Chocolatey.yml +++ b/.github/workflows/Chocolatey.yml @@ -14,7 +14,9 @@ jobs: - name: Preparation run: | $Parameters = @{ - Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json" + Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json" + UseBasicParsing = $true + Verbose = $true } $Latest_Release = Invoke-RestMethod @Parameters diff --git a/.github/workflows/Sophia.yml b/.github/workflows/Sophia.yml index f90f173a..8a03e0d9 100644 --- a/.github/workflows/Sophia.yml +++ b/.github/workflows/Sophia.yml @@ -96,5 +96,5 @@ jobs: # Use "/" in path to files files: | Sophia_Script/Sophia*.zip - Sophia.Script.for.Windows*WinGet.exe + Sophia_Script/Sophia*.exe body_path: ${{ steps.read_release.outputs.ReleaseBody }} diff --git a/.github/workflows/winget.yml b/.github/workflows/winget.yml index d4be9f5d..f8d4a427 100644 --- a/.github/workflows/winget.yml +++ b/.github/workflows/winget.yml @@ -12,56 +12,17 @@ jobs: uses: actions/checkout@main - name: Preparation + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - # Get local uploaded manifest version of the package - $String = Get-Content -Path "Scripts\WinGet_Manifests\TeamSophia.SophiaScript.yaml" | Where-Object -FilterScript {$_ -match "ManifestVersion"} - $LocalManifest = $String -split " " | Select-Object -Last 1 - - # Get latest supported manifest version provided - # https://github.com/microsoft/winget-cli/tree/master/schemas/JSON/manifests - $Parameters = @{ - Uri = "https://api.github.com/repos/microsoft/winget-cli/contents/schemas/JSON/manifests" - UseBasicParsing = $true - Verbose = $true - } - $LatestManifest = ((Invoke-RestMethod @Parameters).name | Where-Object {($_ -ne "preview") -and ($_ -ne "latest")}) -replace ("v", "") | Sort-Object -Property {[System.Version]$_} | Select-Object -Last 1 - - if ([System.Version]$LocalManifest -lt [System.Version]$LatestManifest) - { - Write-Warning -Message "A new manifest $($LatestManifest) available. Edit manifests in Scripts\WinGet_Manifests." - exit - } - - # Get latest version tag for Windows 11 - $Parameters = @{ - Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/refs/heads/master/sophia_script_versions.json" - UseBasicParsing = $true - } - $Version = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_11_PowerShell_5_1 - - # Get archive hash - $Parameters = @{ - Uri = "https://github.com/farag2/Sophia-Script-for-Windows/releases/download/$($Version)/Sophia.Script.for.Windows.11.v$($Version)_WinGet.exe" - UseBasicParsing = $true - } - $Request = (Invoke-WebRequest @Parameters).RawContentStream - $Hash = (Get-FileHash -InputStream $Request).Hash - - # Update the metadata for the files - Get-ChildItem -Path Scripts\WinGet_Manifests | ForEach-Object -Process { - (Get-Content -Path $_.FullName -Encoding UTF8 -Raw) | Foreach-Object -Process { - $_ -replace "SophiaScriptVersion", $Version ` - -replace "SophiaScriptHash", $Hash ` - -replace "SophiaScriptDate", $(Get-Date -Format "yyyy-MM-dd") - } | Set-Content -Path $_.FullName -Encoding utf8 -Force - } + . "Scripts\WinGet.ps1" - name: Publish to WinGet run: | # %LOCALAPPDATA%\Microsoft\WinGet\Packages - # Get the latest wingetcreate # https://github.com/microsoft/winget-create + # https://github.com/microsoft/winget-pkgs/blob/master/Tools/YamlCreate.ps1 $Parameters = @{ Uri = "https://aka.ms/wingetcreate/latest" OutFile = "wingetcreate.exe" diff --git a/Scripts/WinGet.ps1 b/Scripts/WinGet.ps1 new file mode 100644 index 00000000..38048f35 --- /dev/null +++ b/Scripts/WinGet.ps1 @@ -0,0 +1,51 @@ +# Get local uploaded manifest version of the package +$String = Get-Content -Path "Scripts\WinGet_Manifests\TeamSophia.SophiaScript.yaml" | Where-Object -FilterScript {$_ -match "ManifestVersion"} +$LocalManifest = $String -split " " | Select-Object -Last 1 + +# Get latest supported manifest version provided +# https://github.com/microsoft/winget-cli/tree/master/schemas/JSON/manifests +$Token = $env:GITHUB_TOKEN +$Headers = @{ + Accept = "application/vnd.github+json" + Authorization = "Bearer $Token" +} +$Parameters = @{ + Uri = "https://api.github.com/repos/microsoft/winget-cli/contents/schemas/JSON/manifests" + Headers = $Headers + UseBasicParsing = $true + Verbose = $true +} +$LatestManifest = ((Invoke-RestMethod @Parameters).name | Where-Object {($_ -ne "preview") -and ($_ -ne "latest")}) -replace ("v", "") | Sort-Object -Property {[System.Version]$_} | Select-Object -Last 1 + +if ([System.Version]$LocalManifest -lt [System.Version]$LatestManifest) +{ + Write-Warning -Message "A new manifest $($LatestManifest) available. Edit manifests in Scripts\WinGet_Manifests." +} + +# Get latest version tag for Windows 11 +$Parameters = @{ + Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/refs/heads/master/sophia_script_versions.json" + Headers = $Headers + UseBasicParsing = $true + Verbose = $true +} +$Version = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_11_PowerShell_5_1 + +# Get archive hash +$Parameters = @{ + Uri = "https://github.com/farag2/Sophia-Script-for-Windows/releases/download/$($Version)/Sophia.Script.for.Windows.11.v$($Version)_WinGet.exe" + Headers = $Headers + UseBasicParsing = $true + Verbose = $true +} +$Request = (Invoke-WebRequest @Parameters).RawContentStream +$Hash = (Get-FileHash -InputStream $Request).Hash + +# Update the metadata for the files +Get-ChildItem -Path Scripts\WinGet_Manifests | ForEach-Object -Process { + (Get-Content -Path $_.FullName -Encoding UTF8 -Raw) | Foreach-Object -Process { + $_ -replace "SophiaScriptVersion", $Version ` + -replace "SophiaScriptHash", $Hash ` + -replace "SophiaScriptDate", $(Get-Date -Format "yyyy-MM-dd") + } | Set-Content -Path $_.FullName -Encoding utf8 -Force +}