Skip to content

Commit

Permalink
Mass Package Rebuild (#16)
Browse files Browse the repository at this point in the history
* add debug logs

* various fixes

* fix paths; use generic komac install

* fix path

* fix fork var

* hopefully fix komac install

* add missing komac install

* change komac call

* add komac token

* fix push, prepare code for PR

* add debug logs

* various fixes

* fix paths; use generic komac install

* fix path

* fix fork var

* hopefully fix komac install

* add missing komac install

* change komac call

* add komac token

* fix push, prepare code for PR

* WIP: mass update

* remove old code

* rename workflow
  • Loading branch information
a-mnich authored May 15, 2024
1 parent 0a2ccc8 commit 203ef65
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 66 deletions.
29 changes: 0 additions & 29 deletions .github/workflows/MassUpdateManifests.yml

This file was deleted.

34 changes: 34 additions & 0 deletions .github/workflows/rebuild-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Rebuild Package Manifests
on:
workflow_dispatch:
inputs:
PackageIdentifier:
description: "Package Identifier"
required: true
Message:
description: "Message"
required: false

jobs:
update:
name: Rebuild manifests
runs-on: windows-latest
env:
WINGET_PKGS_FORK_REPO: ${{vars.WINGET_PKGS_FORK_REPO}}
WINGET_PAT: ${{secrets.WINGET_PAT}}
steps:
- name: Checkout
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 }}
}
- uses: actions/upload-artifact@v4
with:
name: manifests
path: manifests
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
manifests/
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
#Import-Module powershell-yaml
# param(
# [Parameter(Mandatory = $true)] [string] $PackageIdentifier,
# [Parameter(Mandatory = $true)] [string] $OutputDir
# )
param(
[Parameter(Mandatory = $true)] [string] $PackageIdentifier,
[Parameter(Mandatory = $true)] [string] $OutputDir,
[Parameter(Mandatory = $true)] [string] $Token,
[Parameter(Mandatory = $false)] [string] $Message
)

# Check if powershell-yaml module is installed
if (-not (Get-Module -Name powershell-yaml -ListAvailable)) {
# Install powershell-yaml module
Install-Module -Name powershell-yaml -Scope CurrentUser -Force
}

# Import powershell-yaml module
Import-Module -Name powershell-yaml
. .\Scripts\common.ps1

function Get-InstallerManifestContentGH {
param(
Expand All @@ -18,7 +29,8 @@ function Get-AllInstallerManifestsGH {
param(
[Parameter(Mandatory = $true)] [string] $PackageIdentifier
)
$versions = (komac.exe list-versions --identifier $PackageIdentifier --json) | ConvertFrom-Json
Install-Komac
$versions = (.\komac.exe list-versions --identifier $PackageIdentifier --json -t $Token) | ConvertFrom-Json

$manifestDict = @{}
foreach ($version in $versions) {
Expand Down Expand Up @@ -63,35 +75,17 @@ function Update-WingetPackage {
$manifestDict[$Version] = Get-InstallerManifestContentGH -PackageIdentifier $PackageIdentifier -Version $Version
}

$packageFolder = "$OutputDir\manifests\$($PackageIdentifier.Substring(0, 1).ToLower())/$($PackageIdentifier.replace(".", "/"))"
Set-Location $packageFolder
git checkout master

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

# Create the branch name
$branchName = "manual_" + $PackageIdentifier + "_" + $version
# Create a new branch on the remote
git checkout -b $branchName

Komac.exe update --version $version --identifier $PackageIdentifier --urls ($installerLinks -join ' ') -o $OutputDir

git add $version
# Commit the changes
git commit -am "Update existing $PackageIdentifier version $($directory.Name) Manifest"
git checkout master

# Push the branch to the remote
#git push origin $branchName
}

Install-Komac
.\komac.exe update --version $version --identifier $PackageIdentifier --urls ($installerLinks -join ' ') -o $OutputDir -t $Token --dry-run
}
}

Update-WingetPackage -PackageIdentifier "hoppscotch.Hoppscotch" -OutputDir "C:\Programming\winget-pkgs" -All

Update-WingetPackage -PackageIdentifier $PackageIdentifier -OutputDir $OutputDir -All



Expand Down
26 changes: 17 additions & 9 deletions Scripts/common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,22 @@ function Get-ProductVersionFromFile {
return $versionInfo
}

function Install-Komac {
if(-not (Test-Path ".\komac.exe")) {
#$latestKomacRelease = (Invoke-RestMethod -Uri "https://api.github.com/repos/russellbanks/Komac/releases/latest").assets | Where-Object { $_.browser_download_url.EndsWith("KomacPortable-x64.exe") } | Select-Object -First 1 -ExpandProperty browser_download_url
$latestKomacRelease = "https://github.com/b0t-at/Komac/releases/download/v2.99/KomacPortable-x64.exe"
Invoke-WebRequest -Uri $latestKomacRelease -OutFile komac.exe
}

if (Test-Path ".\komac.exe") {
Write-Host "Komac successfully downloaded"
}
else {
Write-Error "Komac not downloaded"
exit 1
}
}

function Update-WingetPackage {
param(
[Parameter(Mandatory = $true)] [string] $WebsiteURL,
Expand Down Expand Up @@ -207,15 +223,7 @@ function Update-WingetPackage {
Write-Host "Downloading $With and open PR for $wingetPackage Version $($Latest.Version)"
Switch ($With) {
"Komac" {
$latestKomacRelease = (Invoke-RestMethod -Uri "https://api.github.com/repos/russellbanks/Komac/releases/latest").assets | Where-Object { $_.browser_download_url.EndsWith("KomacPortable-x64.exe") } | Select-Object -First 1 -ExpandProperty browser_download_url
Invoke-WebRequest -Uri $latestKomacRelease -OutFile komac.exe
if (Test-Path ".\komac.exe") {
Write-Host "Komac successfully downloaded"
}
else {
Write-Error "Komac not downloaded"
exit 1
}
Install-Komac
.\komac.exe update --identifier $wingetPackage --version $Latest.Version --urls "$($Latest.URLs.replace(' ','" "'))" ($Submit -eq $true ? "-s" : "") -t $gitToken
}
"WinGetCreate" {
Expand Down

0 comments on commit 203ef65

Please sign in to comment.