Browse Source

Fix WinGet automatic PR creation

pull/694/head
Dmitry Nefedov 3 months ago
parent
commit
c113c93548
  1. 4
      .github/workflows/Chocolatey.yml
  2. 2
      .github/workflows/Sophia.yml
  3. 47
      .github/workflows/winget.yml
  4. 51
      Scripts/WinGet.ps1

4
.github/workflows/Chocolatey.yml

@ -14,7 +14,9 @@ jobs:
- name: Preparation - name: Preparation
run: | run: |
$Parameters = @{ $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 $Latest_Release = Invoke-RestMethod @Parameters

2
.github/workflows/Sophia.yml

@ -96,5 +96,5 @@ jobs:
# Use "/" in path to files # Use "/" in path to files
files: | files: |
Sophia_Script/Sophia*.zip Sophia_Script/Sophia*.zip
Sophia.Script.for.Windows*WinGet.exe Sophia_Script/Sophia*.exe
body_path: ${{ steps.read_release.outputs.ReleaseBody }} body_path: ${{ steps.read_release.outputs.ReleaseBody }}

47
.github/workflows/winget.yml

@ -12,56 +12,17 @@ jobs:
uses: actions/checkout@main uses: actions/checkout@main
- name: Preparation - name: Preparation
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: | run: |
# Get local uploaded manifest version of the package . "Scripts\WinGet.ps1"
$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
}
- name: Publish to WinGet - name: Publish to WinGet
run: | run: |
# %LOCALAPPDATA%\Microsoft\WinGet\Packages # %LOCALAPPDATA%\Microsoft\WinGet\Packages
# Get the latest wingetcreate # Get the latest wingetcreate
# https://github.com/microsoft/winget-create # https://github.com/microsoft/winget-create
# https://github.com/microsoft/winget-pkgs/blob/master/Tools/YamlCreate.ps1
$Parameters = @{ $Parameters = @{
Uri = "https://aka.ms/wingetcreate/latest" Uri = "https://aka.ms/wingetcreate/latest"
OutFile = "wingetcreate.exe" OutFile = "wingetcreate.exe"

51
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
}
Loading…
Cancel
Save