Skip to content

Commit

Permalink
Merge pull request #2300 from JPRuskin/fix-kubernetes-cli
Browse files Browse the repository at this point in the history
(kubernetes-cli) Fixes Update.ps1 (HTML parsing)
  • Loading branch information
pauby authored Sep 7, 2023
2 parents 1c2a31e + 284bf00 commit 07b8e7f
Showing 1 changed file with 33 additions and 25 deletions.
58 changes: 33 additions & 25 deletions automatic/kubernetes-cli/update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ param($IncludeStream, [switch] $Force)

Import-Module AU

$changelogs = 'https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/README.md'
$changelogs = 'https://raw.githubusercontent.com/kubernetes/kubernetes/master/CHANGELOG/README.md'

function global:au_BeforeUpdate { Get-RemoteFiles -Purge -NoSuffix }

Expand All @@ -27,44 +27,52 @@ function global:au_SearchReplace {
function global:au_GetLatest {
# Only report the supported Kubernetes streams.

$changelog_page = Invoke-WebRequest -Uri $changelogs -UseBasicParsing
$changelogs = (Invoke-WebRequest -Uri $changelogs -UseBasicParsing).content

# There is quite a few versions that do not exist on chocolatey.org
# and since the limit of pushed packages is 10, we need to limit the amount
# of streams that we parse. Once packages are approved we can increase/remove
# the limit.
$minor_version_changelogs = $changelog_page.links `
| Where-Object href -match "CHANGELOG-(?<version>\d+\.\d+)\.md`$" `
| Select-Object -Expand href -First 10
$minor_version_changelogs = $changelogs `
| Select-String -Pattern "- \[CHANGELOG-(?<version>\d\.\d+)\.md\]" -AllMatches `
| ForEach-Object {$_.Matches.Groups.Where{$_.Name -eq 'version'}.value} `
| Select-Object -First 10

$streams = @{}

$minor_version_changelogs | ForEach-Object {
if ($_ -notmatch "CHANGELOG-(?<version>\d+\.\d+)\.md`$") {
return
}
$minor_version = $matches.version
foreach ($minor_version in $minor_version_changelogs) {
if ($streams.ContainsKey($minor_version)) {
return
}
$minor_changelog_page = Invoke-WebRequest -UseBasicParsing -Uri "https://github.com$_"
$url64 = $minor_changelog_page.links `
| Where-Object href -match "/v(?<version>\d+(\.\d+)+)/kubernetes-client-windows-amd64.tar.gz" `
| Select-Object -First 1 -Expand href
$patch_version = $matches.version

$minor_changelog_page = Invoke-WebRequest -UseBasicParsing -Uri "https://raw.githubusercontent.com/kubernetes/kubernetes/master/CHANGELOG/CHANGELOG-$($minor_version).md"
$url64 = $minor_changelog_page.content `
| Select-String -Pattern "(?<=\[.+\]\()(?<href>.+/v(?<version>\d+(\.\d+)+)/kubernetes-client-windows-amd64\.tar\.gz)\)" `
| ForEach-Object {$_.Matches.Groups.Where{$_.Name -eq 'href'}.value} `
| Select-Object -First 1

if (!$url64) {
return
}
$url32 = $minor_changelog_page.links `
| Where-Object href -match "/v(?<version>\d+(\.\d+)+)/kubernetes-client-windows-386.tar.gz" `
| Select-Object -First 1 -Expand href

$streams.Add($minor_version, @{
Version = $patch_version
URL32 = $url32
URL64 = $url64
ReleaseNotes= "https://github.com$_"
})

if ($url64 -match "/v(?<version>\d+(\.\d+)+)/kubernetes-client-windows-amd64.tar.gz") {
$patch_version = $matches.version
}

$url32 = $minor_changelog_page.content `
| Select-String -Pattern "(?<=\[.+\]\()(?<href>.+/v(?<version>\d+(\.\d+)+)/kubernetes-client-windows-386\.tar\.gz)\)" `
| ForEach-Object {$_.Matches.Groups.Where{$_.Name -eq 'href'}.value} `
| Select-Object -First 1

$streams.Add(
$minor_version,
@{
Version = $patch_version
URL32 = $url32
URL64 = $url64
ReleaseNotes = "https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-$($minor_version).md"
}
)
}

return @{ Streams = $streams }
Expand Down

0 comments on commit 07b8e7f

Please sign in to comment.