Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Fork.fork and additional logging #10

Merged
merged 4 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/update-via-script.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ jobs:
With: WinGetCreate
- PackageName: "SmartProjects.IsoBuster"
WebsiteURL: "https://www.isobuster.com/downloads/isobuster/isobuster_install_64bit.exe https://www.isobuster.com/downloads/isobuster/isobuster_install.exe"
- PackageName: "Fork.Fork"
WebsiteURL: "https://fork.dev"

steps:
- name: Checkout
Expand Down
23 changes: 23 additions & 0 deletions Scripts/Update-Fork.Fork.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
. .\Scripts\common.ps1


# Currently not all versions have .exe installers
#Text response with entries of form "<SHA> Fork-<Version>-<FUll|Delta>.nupkg <SIZE>"
# Invoke-WebRequest -Uri "https://git-fork.com/update/win/RELEASES?id=Fork" -OutFile "RELEASES"
# $releases = Get-Content "RELEASES"
# $versionNumbers = $releases | ForEach-Object {
# if ($_ -match 'Fork-(.*?)-') {
# $Matches[1]
# }
# }
# $versionNumbers = $versionNumbers | Sort-Object -Descending | Select-Object -Unique

# $latestVersion = $versionNumbers[0]
# $latestVersionUrl = "https://cdn.fork.dev/win/Fork-$latestVersion.exe"

$websiteContent = Invoke-WebRequest -Uri $WebsiteURL
$latestVersionUrl = $websiteContent.Links | Where-Object {$_.tagName -eq "A" -and $_.outerHTML.Contains('"downloadBtn2Win"')} | Select-Object -First 1 -ExpandProperty href
# extract version from link
$latestVersion = [regex]::Match($latestVersionUrl, '.*Fork-(.*).exe').Groups[1].Value

return $latestVersion, "$latestVersionUrl"
35 changes: 27 additions & 8 deletions Scripts/common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function Test-PackageAndVersionInGithub {
exit 0
}
else {
Write-Host "Package $wingetPackage is in winget, but version $latestVersion is not present."
return $true
}

Expand Down Expand Up @@ -147,8 +148,9 @@ function Get-ProductVersionFromFile {
if ($DownloadFileName -like "*.zip") {
$UnzipPath = "."
Expand-Archive -Path $DownloadFileName -DestinationPath $UnzipPath
$file = Get-ChildItem -Path $UnzipPath -Include "*.exe","*.msi" -Recurse | Select-Object -First 1
} else {
$file = Get-ChildItem -Path $UnzipPath -Include "*.exe", "*.msi" -Recurse | Select-Object -First 1
}
else {
$file = Get-ChildItem -Path $DownloadFileName
}

Expand Down Expand Up @@ -201,17 +203,34 @@ function Update-WingetPackage {
$ExistingPRs = Test-ExistingPRs -wingetPackage $wingetPackage -latestVersion $($Latest.Version)

if ($ExistingPRs) {
Write-Host "Downloading $with and open PR for $wingetPackage Version $($Latest.Version)"
Switch ($with) {
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 | ? {$_.browser_download_url.EndsWith("KomacSetup-x64.exe")} | Select-Object -First 1 -ExpandProperty browser_download_url
$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
}
.\komac.exe update --identifier $wingetPackage --version $Latest.Version --urls "$($Latest.URLs.replace(' ','" "'))" -s -t $gitToken
}
"WinGetCreate" {
Invoke-WebRequest https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe
if (Test-Path ".\wingetcreate.exe") {
Write-Host "wingetcreate successfully downloaded"
}
else {
Write-Error "wingetcreate not downloaded"
exit 1
}
.\wingetcreate.exe update $wingetPackage -s -v $Latest.Version -u "$($Latest.URLs.replace(' ','" "'))" --prtitle $prMessage -t $gitToken
}
default {
Write-Error "Invalid value \"$With\" for -With parameter. Valid values are 'Komac' and 'WinGetCreate'"
}
}
}
}
Expand All @@ -229,17 +248,17 @@ function Get-LatestMongoDBVersions {
$links = $content | Select-String -Pattern 'https?://[^"]+' -AllMatches | % { $_.Matches } | % { $_.Value }
$msilinks = $links | Select-String -Pattern 'https?://[^\s]*\.msi' -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value }

$Packagelinks = $msilinks | Select-String -Pattern "https?://[^\s]*$PackageFilter[^\s]*\.msi" -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value }| Where-Object { $_ -notmatch "$PackageFilter-isolated|$PackageFilter-readonly" }
$Packagelinks = $msilinks | Select-String -Pattern "https?://[^\s]*$PackageFilter[^\s]*\.msi" -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value } | Where-Object { $_ -notmatch "$PackageFilter-isolated|$PackageFilter-readonly" }

$versions = $Packagelinks | ForEach-Object { $_ -match '(\d+\.\d+\.\d+(-rc\d*|-beta\d*)?)' | Out-Null; $matches[1] }
$stableVersions = $versions | Where-Object { $_ -notmatch '(-rc|beta)' }

$latestVersion = $stableVersions | Sort-Object {[Version]$_} | Select-Object -Last 1
$latestVersion = $stableVersions | Sort-Object { [Version]$_ } | Select-Object -Last 1
$latestVersionUrl = $Packagelinks | Where-Object { $_ -match $latestVersion }

return @{
Version = $latestVersion
Url = $latestVersionUrl
Url = $latestVersionUrl
}
}

Expand Down