name: WinGet push on: workflow_dispatch: jobs: publish: runs-on: windows-latest steps: - name: Checkout repository uses: actions/checkout@main - name: Preparation run: | # Get local uploaded manifest version of the package $String = Get-Content -Path "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 # Parse GitHub folder $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"}) -replace ("v", "") | Sort-Object -Property {[System.Version]$_} | Select-Object -Last 1 if ([System.Version]$LocalManifest -lt [System.Version]$LatestManifest) { Write-Warning -Message "New $($LatestManifest) manifest 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).zip" 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 run: | # Get the latest wingetcreate # https://github.com/microsoft/winget-create $Parameters = @{ Uri = "https://aka.ms/wingetcreate/latest" OutFile = "wingetcreate.exe" UseBasicParsing = $true } Invoke-WebRequest @Parameters .\wingetcreate.exe submit --prtitle "New Version: TeamSophia.SophiaScript version $Version" --token "${{ secrets.WINGET_PAT }}" "Scripts\WinGet_Manifests"