Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
Simplify version parsing and skip windows versions if continue=no
Browse files Browse the repository at this point in the history
  • Loading branch information
harrisonmeister committed Sep 27, 2023
1 parent 985f006 commit 3f5e224
Showing 1 changed file with 35 additions and 33 deletions.
68 changes: 35 additions & 33 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,49 +62,51 @@ jobs:
Write-Output "Getting kubectl version"
$chocoInformationRaw = choco info kubernetes-cli --limitoutput
$version = ($chocoInformationRaw.Split("|"))[1]
$versionOutput = ($chocoInformationRaw.Split("|"))[1]
if($version -like "*Failed to fetch results*")
{
Write-Host "Failed to retrieve kubectl details from Chocolatey"
[System.Version]$version = $null
$versionParsed = [System.Version]::TryParse($versionOutput, [ref]$version)
if(-not $versionParsed) {
Write-Host "Unable to parse '$versionOutput' as a valid version. Won't continue"
echo "CONTINUE=No" >> $env:GITHUB_OUTPUT
}
else
{
$versionSplit = $version.Split(".")
$versionToCompare = "$($versionSplit[0]).$($versionSplit[1]).$($versionSplit[2])"
else {
$versionToCompare = "$($version.Major).$($version.Minor).$($version.Build)"
Write-Host "Parsed version as $versionToCompare"
$workerToolsTags = Invoke-RestMethod "https://registry.hub.docker.com/v2/repositories/octopuslabs/k8s-workertools/tags?page_size=50"
$matchingTag = $workerToolsTags.results | Where-Object { $_.name -eq $versionToCompare }
$workerToolsTags = Invoke-RestMethod "https://registry.hub.docker.com/v2/repositories/octopuslabs/k8s-workertools/tags?page_size=50"
$matchingTag = $workerToolsTags.results | Where-Object { $_.name -eq $versionToCompare }
echo "VERSION=$versionToCompare" >> $env:GITHUB_OUTPUT
echo "VERSION=$versionToCompare" >> $env:GITHUB_OUTPUT
if ($null -ne $matchingTag)
{
Write-Host "Docker container already has latest version"
echo "CONTINUE=No" >> $env:GITHUB_OUTPUT
}
else
{
Write-Host "We need to upgrade the container to $versionToCompare"
echo "CONTINUE=Yes" >> $env:GITHUB_OUTPUT
}
if ($null -ne $matchingTag)
{
Write-Host "Docker container already has latest version"
echo "CONTINUE=No" >> $env:GITHUB_OUTPUT
}
else
{
Write-Host "We need to upgrade the container to $versionToCompare"
Write-Host "Getting OS versions for windows 2022 and 2019"
$win2019_manifest = (docker manifest inspect --verbose "octopuslabs/workertools:latest-windows.2019" | ConvertFrom-Json)
$WIN2019_VERSION = $win2019_manifest.Descriptor.Platform.'os.version'
Write-Host "WIN2019_VERSION: $WIN2019_VERSION"
Write-Host "Getting OS versions for windows 2022 and 2019"
$win2019_manifest = (docker manifest inspect --verbose "octopuslabs/workertools:latest-windows.2019" | ConvertFrom-Json)
$WIN2019_VERSION = $win2019_manifest.Descriptor.Platform.'os.version'
Write-Host "WIN2019_VERSION: $WIN2019_VERSION"
$win2022_manifest = (docker manifest inspect --verbose "octopuslabs/workertools:latest-windows.2022" | ConvertFrom-Json)
$WIN2022_VERSION = $win2022_manifest.Descriptor.Platform.'os.version'
Write-Host "WIN2022_VERSION: $WIN2022_VERSION"
$win2022_manifest = (docker manifest inspect --verbose "octopuslabs/workertools:latest-windows.2022" | ConvertFrom-Json)
$WIN2022_VERSION = $win2022_manifest.Descriptor.Platform.'os.version'
Write-Host "WIN2022_VERSION: $WIN2022_VERSION"
if([string]::IsNullOrWhiteSpace($WIN2019_VERSION) -or [string]::IsNullOrWhiteSpace($WIN2022_VERSION)) {
throw "Could not establish OS versions for windows 2022 and 2019 needed for docker manifest"
}
if([string]::IsNullOrWhiteSpace($WIN2019_VERSION) -or [string]::IsNullOrWhiteSpace($WIN2022_VERSION)) {
throw "Could not establish OS versions for windows 2022 and 2019 needed for docker manifest"
}
echo "WIN2019_VERSION=$WIN2019_VERSION" >> $env:GITHUB_OUTPUT
echo "WIN2022_VERSION=$WIN2022_VERSION" >> $env:GITHUB_OUTPUT
echo "WIN2019_VERSION=$WIN2019_VERSION" >> $env:GITHUB_OUTPUT
echo "WIN2022_VERSION=$WIN2022_VERSION" >> $env:GITHUB_OUTPUT
Write-Host "We have everything we need, continuing."
echo "CONTINUE=Yes" >> $env:GITHUB_OUTPUT
}
}
shell: powershell

Expand Down

0 comments on commit 3f5e224

Please sign in to comment.