Skip to content

Commit aaf00aa

Browse files
committed
Fix WinGet automatic PR creation
1 parent fc9d648 commit aaf00aa

File tree

3 files changed

+47
-44
lines changed

3 files changed

+47
-44
lines changed

.github/workflows/Sophia.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,5 @@ jobs:
9696
# Use "/" in path to files
9797
files: |
9898
Sophia_Script/Sophia*.zip
99-
Sophia.Script.for.Windows*WinGet.exe
99+
Sophia_Script/Sophia*.exe
100100
body_path: ${{ steps.read_release.outputs.ReleaseBody }}

.github/workflows/winget.yml

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,55 +13,14 @@ jobs:
1313

1414
- name: Preparation
1515
run: |
16-
# Get local uploaded manifest version of the package
17-
$String = Get-Content -Path "Scripts\WinGet_Manifests\TeamSophia.SophiaScript.yaml" | Where-Object -FilterScript {$_ -match "ManifestVersion"}
18-
$LocalManifest = $String -split " " | Select-Object -Last 1
19-
20-
# Get latest supported manifest version provided
21-
# https://github.com/microsoft/winget-cli/tree/master/schemas/JSON/manifests
22-
$Parameters = @{
23-
Uri = "https://api.github.com/repos/microsoft/winget-cli/contents/schemas/JSON/manifests"
24-
UseBasicParsing = $true
25-
Verbose = $true
26-
}
27-
$LatestManifest = ((Invoke-RestMethod @Parameters).name | Where-Object {($_ -ne "preview") -and ($_ -ne "latest")}) -replace ("v", "") | Sort-Object -Property {[System.Version]$_} | Select-Object -Last 1
28-
29-
if ([System.Version]$LocalManifest -lt [System.Version]$LatestManifest)
30-
{
31-
Write-Warning -Message "A new manifest $($LatestManifest) available. Edit manifests in Scripts\WinGet_Manifests."
32-
exit
33-
}
34-
35-
# Get latest version tag for Windows 11
36-
$Parameters = @{
37-
Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/refs/heads/master/sophia_script_versions.json"
38-
UseBasicParsing = $true
39-
}
40-
$Version = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_11_PowerShell_5_1
41-
42-
# Get archive hash
43-
$Parameters = @{
44-
Uri = "https://github.com/farag2/Sophia-Script-for-Windows/releases/download/$($Version)/Sophia.Script.for.Windows.11.v$($Version)_WinGet.exe"
45-
UseBasicParsing = $true
46-
}
47-
$Request = (Invoke-WebRequest @Parameters).RawContentStream
48-
$Hash = (Get-FileHash -InputStream $Request).Hash
49-
50-
# Update the metadata for the files
51-
Get-ChildItem -Path Scripts\WinGet_Manifests | ForEach-Object -Process {
52-
(Get-Content -Path $_.FullName -Encoding UTF8 -Raw) | Foreach-Object -Process {
53-
$_ -replace "SophiaScriptVersion", $Version `
54-
-replace "SophiaScriptHash", $Hash `
55-
-replace "SophiaScriptDate", $(Get-Date -Format "yyyy-MM-dd")
56-
} | Set-Content -Path $_.FullName -Encoding utf8 -Force
57-
}
16+
. "Scripts\WinGet.ps1"
5817
5918
- name: Publish to WinGet
6019
run: |
6120
# %LOCALAPPDATA%\Microsoft\WinGet\Packages
62-
6321
# Get the latest wingetcreate
6422
# https://github.com/microsoft/winget-create
23+
# https://github.com/microsoft/winget-pkgs/blob/master/Tools/YamlCreate.ps1
6524
$Parameters = @{
6625
Uri = "https://aka.ms/wingetcreate/latest"
6726
OutFile = "wingetcreate.exe"

Scripts/WinGet.ps1

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Get local uploaded manifest version of the package
2+
$String = Get-Content -Path "Scripts\WinGet_Manifests\TeamSophia.SophiaScript.yaml" | Where-Object -FilterScript {$_ -match "ManifestVersion"}
3+
$LocalManifest = $String -split " " | Select-Object -Last 1
4+
5+
# Get latest supported manifest version provided
6+
# https://github.com/microsoft/winget-cli/tree/master/schemas/JSON/manifests
7+
$Parameters = @{
8+
Uri = "https://api.github.com/repos/microsoft/winget-cli/contents/schemas/JSON/manifests"
9+
UseBasicParsing = $true
10+
Verbose = $true
11+
}
12+
$LatestManifest = ((Invoke-RestMethod @Parameters).name | Where-Object {($_ -ne "preview") -and ($_ -ne "latest")}) -replace ("v", "") | Sort-Object -Property {[System.Version]$_} | Select-Object -Last 1
13+
14+
if ([System.Version]$LocalManifest -lt [System.Version]$LatestManifest)
15+
{
16+
Write-Warning -Message "A new manifest $($LatestManifest) available. Edit manifests in Scripts\WinGet_Manifests."
17+
exit
18+
}
19+
20+
# Get latest version tag for Windows 11
21+
$Parameters = @{
22+
Uri = "https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/refs/heads/master/sophia_script_versions.json"
23+
UseBasicParsing = $true
24+
Verbose = $true
25+
}
26+
$Version = (Invoke-RestMethod @Parameters).Sophia_Script_Windows_11_PowerShell_5_1
27+
28+
# Get archive hash
29+
$Parameters = @{
30+
Uri = "https://github.com/farag2/Sophia-Script-for-Windows/releases/download/$($Version)/Sophia.Script.for.Windows.11.v$($Version)_WinGet.exe"
31+
UseBasicParsing = $true
32+
Verbose = $true
33+
}
34+
$Request = (Invoke-WebRequest @Parameters).RawContentStream
35+
$Hash = (Get-FileHash -InputStream $Request).Hash
36+
37+
# Update the metadata for the files
38+
Get-ChildItem -Path Scripts\WinGet_Manifests | ForEach-Object -Process {
39+
(Get-Content -Path $_.FullName -Encoding UTF8 -Raw) | Foreach-Object -Process {
40+
$_ -replace "SophiaScriptVersion", $Version `
41+
-replace "SophiaScriptHash", $Hash `
42+
-replace "SophiaScriptDate", $(Get-Date -Format "yyyy-MM-dd")
43+
} | Set-Content -Path $_.FullName -Encoding utf8 -Force
44+
}

0 commit comments

Comments
 (0)