Skip to content

Commit

Permalink
rewrite package rebuild workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
a-mnich committed Oct 28, 2024
1 parent c94e2b3 commit adc1539
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 21 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/rebuild-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ on:
Message:
description: "Message"
required: false

submit:
description: 'True to auto-submit'
required: true
type: boolean
default: false
resolves:
description: 'resolves this issues'
required: false
jobs:
update:
name: Rebuild manifests
Expand All @@ -21,13 +28,8 @@ jobs:
uses: actions/checkout@v4
- name: Trigger Mass Package Update
run: |
Write-Host "Currently in: $(Get-Location)"
$fullPathFork = "$(Get-Location)"
if($message -eq $null) {
scripts/Update-PackageManifests.ps1 -PackageIdentifier ${{ github.event.inputs.PackageIdentifier }} -OutputDir $fullPathFork -Token ${{env.WINGET_PAT}}
} else {
scripts/Update-PackageManifests.ps1 -PackageIdentifier ${{ github.event.inputs.PackageIdentifier }} -OutputDir $fullPathFork -Token ${{env.WINGET_PAT}} -Message ${{ github.event.inputs.Message }}
}
scripts/Update-PackageManifests.ps1 -PackageIdentifier ${{ github.event.inputs.PackageIdentifier }} -OutputDir $fullPathFork -Token ${{env.WINGET_PAT}} -Submit ${{ github.event.inputs.submit }} -Resolves ${{ github.event.inputs.resolves }}
- uses: actions/upload-artifact@v4
with:
name: manifests
Expand Down
43 changes: 36 additions & 7 deletions modules/WingetMaintainerModule/Public/Test-ExistingPRs.ps1
Original file line number Diff line number Diff line change
@@ -1,23 +1,52 @@
<#
.SYNOPSIS
Checks for existing pull requests (PRs) for a specified package identifier and version in the 'microsoft/winget-pkgs' repository.
.DESCRIPTION
The `Test-ExistingPRs` function searches for existing open and merged pull requests in the 'microsoft/winget-pkgs' repository that match the specified package identifier and version.
It uses the GitHub CLI (`gh`) to perform the search and returns `true` if any matching PRs are found, otherwise returns `false`.
.PARAMETER Version
The version of the package to check for existing PRs. This parameter is mandatory.
.PARAMETER PackageIdentifier
The identifier of the package to check for existing PRs. This parameter is optional and defaults to the value of the `PackageName` environment variable if not specified.
.EXAMPLE
Test-ExistingPRs -Version "1.0.0" -PackageIdentifier "example.package"
Checks for existing PRs for the package 'example.package' with version '1.0.0'.
.EXAMPLE
Test-ExistingPRs -Version "1.0.0"
Checks for existing PRs for the package specified in the `PackageName` environment variable with version '1.0.0'.
.OUTPUTS
System.Boolean
Returns `true` if any matching PRs are found, otherwise returns `false`.
.NOTES
This function requires the GitHub CLI (`gh`) to be installed and authenticated.
#>
function Test-ExistingPRs {
param(
[Parameter(Mandatory = $true)] [string] $latestVersion,
[Parameter(Mandatory = $false)] [string] $wingetPackage = ${Env:PackageName}
[Parameter(Mandatory = $true)] [string] $Version,
[Parameter(Mandatory = $false)] [string] $PackageIdentifier = ${Env:PackageName}
)
Write-Host "Checking for exisitng PRs for $wingetPackage $($Latest.Version)"
$ExistingOpenPRs = gh pr list --search "$($wingetPackage) $($latestVersion) in:title draft:false" --state 'open' --json 'title,url' --repo 'microsoft/winget-pkgs' | ConvertFrom-Json
$ExistingMergedPRs = gh pr list --search "$($wingetPackage) $($latestVersion) in:title draft:false" --state 'merged' --json 'title,url' --repo 'microsoft/winget-pkgs' | ConvertFrom-Json
Write-Host "Checking for existing PRs for $PackageIdentifier $Version"
$ExistingOpenPRs = gh pr list --search "$($PackageIdentifier) $($Version) in:title draft:false" --state 'open' --json 'title,url' --repo 'microsoft/winget-pkgs' | ConvertFrom-Json
$ExistingMergedPRs = gh pr list --search "$($PackageIdentifier) $($Version) in:title draft:false" --state 'merged' --json 'title,url' --repo 'microsoft/winget-pkgs' | ConvertFrom-Json
$ExistingPRs = @($ExistingOpenPRs) + @($ExistingMergedPRs)

if ($ExistingPRs.Count -gt 0) {
$ExistingPRs | ForEach-Object {
Write-Host "Found existing PR: $($_.title)"
Write-Host "-> $($_.url)"
}
exit 0
return $true
}
else {

return $true
return $false
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ function Update-WingetPackage {

if ($PackageAndVersionInWinget) {

$ExistingPRs = Test-ExistingPRs -wingetPackage $wingetPackage -latestVersion $($Latest.Version)
$PRExists = Test-ExistingPRs -PackageIdentifier $wingetPackage -Version $($Latest.Version)

if ($ExistingPRs) {
if (!$PRExists) {
Write-Host "Downloading $With and open PR for $wingetPackage Version $($Latest.Version)"
Switch ($With) {
"Komac" {
Expand Down
12 changes: 7 additions & 5 deletions scripts/Update-PackageManifests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ param(
[Parameter(Mandatory = $true)] [string] $PackageIdentifier,
[Parameter(Mandatory = $true)] [string] $OutputDir,
[Parameter(Mandatory = $true)] [string] $Token,
[Parameter(Mandatory = $false)] [string] $Message
[Parameter(Mandatory = $false)] [string] $Submit,
[Parameter(Mandatory = $false)] [string] $Resolves
)

# Check if powershell-yaml module is installed
Expand Down Expand Up @@ -74,15 +75,16 @@ function Update-WingetPackage {
$manifestDict = @{}
$manifestDict[$Version] = Get-InstallerManifestContentGH -PackageIdentifier $PackageIdentifier -Version $Version
}

Install-Komac
foreach ($version in $manifestDict.Keys) {
$manifest = $manifestDict[$version]
# Extract the installer links from the manifest
$installerLinks = Export-InstallerLinks -Manifest $manifest

Install-Komac
.\komac.exe update $PackageIdentifier --version $version --urls $installerLinks -o $OutputDir -t $Token --dry-run
$prExists = Test-ExistingPRs -PackageIdentifier $PackageIdentifier -Version $version
if(!$prExists || $Submit -eq $false) {
.\komac.exe update $PackageIdentifier --version $version --urls $installerLinks -o $OutputDir -t $Token ($Submit -eq $true ? '-s' : '--dry-run') ($resolves -match '^\d+$' ? "--resolves $resolves" : $null )
}
}
}

Update-WingetPackage -PackageIdentifier $PackageIdentifier -OutputDir $OutputDir -All
Expand Down

0 comments on commit adc1539

Please sign in to comment.