Skip to content

Commit

Permalink
Simplify versioning checks
Browse files Browse the repository at this point in the history
  • Loading branch information
harrisonmeister committed Sep 27, 2023
1 parent 84be25f commit 08f80aa
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 75 deletions.
84 changes: 45 additions & 39 deletions .github/workflows/octo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,56 @@ jobs:
name: Compare latest version with container
run: |
$chocoInformationRaw = choco info octopustools --limitoutput
$version = ($chocoInformationRaw.Split("|"))[1]
$versionSplit = $version.Split(".")
Write-Host "Retrieving tags ..."
$response = try {
$repositoryTags = Invoke-RestMethod "https://registry.hub.docker.com/v2/repositories/octopuslabs/gitlab-octocli/tags"
Write-Host "Retrieval successful!"
} catch [System.Net.WebException] {
$_.Exception.Response
Write-Host "Retrieval failed!!"
}
Write-Host "Version: $version"
echo "VERSION=$version" >> $env:GITHUB_OUTPUT
if ($null -eq $response)
{
$matchingTag = $repositoryTags.results | Where-Object {$_.Name -eq $version}
if ($null -ne $matchingTag)
{
Write-Host "Docker container already has latest version."
$versionOutput = ($chocoInformationRaw.Split("|"))[1]
[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
{
Write-Host "Octopus CLI has been updated, create new image."
echo "CONTINUE=Yes" >> $env:GITHUB_OUTPUT
}
}
else
{
if ($response.StatusCode.value__ -eq 404)
{
Write-Host "No tags exist for repo, assuming first build."
echo "CONTINUE=Yes" >> $env:GITHUB_OUTPUT
}
}
else {
$versionToCompare = "$($version.Major).$($version.Minor).$($version.Build)"
Write-Host "Parsed version as $versionToCompare"
echo "VERSION=$versionToCompare" >> $env:GITHUB_OUTPUT
Write-Host "Retrieving tags ..."
$response = try {
$repositoryTags = Invoke-RestMethod "https://registry.hub.docker.com/v2/repositories/octopuslabs/gitlab-octocli/tags"
Write-Host "Retrieval successful!"
} catch [System.Net.WebException] {
$_.Exception.Response
Write-Host "Retrieval failed!!"
}
if ($null -eq $response)
{
$matchingTag = $repositoryTags.results | Where-Object {$_.Name -eq $versionToCompare}
if ($null -ne $matchingTag)
{
Write-Host "Docker container already has latest version."
echo "CONTINUE=No" >> $env:GITHUB_OUTPUT
}
else
{
Write-Host "Octopus CLI has been updated, create new image."
echo "CONTINUE=Yes" >> $env:GITHUB_OUTPUT
}
}
else
{
if ($response.StatusCode.value__ -eq 404)
{
Write-Host "No tags exist for repo, assuming first build."
echo "CONTINUE=Yes" >> $env:GITHUB_OUTPUT
}
}
}
shell: powershell



build-linux:
needs: [get-octo-cli-version]
runs-on: ubuntu-latest
Expand Down
79 changes: 43 additions & 36 deletions .github/workflows/octopus-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,51 @@ jobs:
name: Compare latest version with container
run: |
$chocoInformationRaw = choco info octopus-cli --limitoutput
$version = ($chocoInformationRaw.Split("|"))[1]
$versionSplit = $version.Split(".")
Write-Host "Retrieving tags ..."
$response = try {
$repositoryTags = Invoke-RestMethod "https://registry.hub.docker.com/v2/repositories/octopuslabs/gitlab-octopus-cli/tags"
Write-Host "Retrieval successful!"
} catch [System.Net.WebException] {
$_.Exception.Response
Write-Host "Retrieval failed!!"
}
Write-Host "Version: $version"
echo "VERSION=$version" >> $env:GITHUB_OUTPUT
if ($null -eq $response)
{
$matchingTag = $repositoryTags.results | Where-Object {$_.Name -eq $version}
if ($null -ne $matchingTag)
{
Write-Host "Docker container already has latest version."
$versionOutput = ($chocoInformationRaw.Split("|"))[1]
[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
{
Write-Host "vNext Octopus CLI has been updated, create new image."
echo "CONTINUE=Yes" >> $env:GITHUB_OUTPUT
}
}
else
{
if ($response.StatusCode.value__ -eq 404)
{
Write-Host "No tags exist for repo, assuming first build."
echo "CONTINUE=Yes" >> $env:GITHUB_OUTPUT
}
else {
$versionToCompare = "$($version.Major).$($version.Minor).$($version.Build)"
Write-Host "Parsed version as $versionToCompare"
echo "VERSION=$versionToCompare" >> $env:GITHUB_OUTPUT
$response = try {
$repositoryTags = Invoke-RestMethod "https://registry.hub.docker.com/v2/repositories/octopuslabs/gitlab-octopus-cli/tags"
Write-Host "Retrieval successful!"
} catch [System.Net.WebException] {
$_.Exception.Response
Write-Host "Retrieval failed!!"
}
if ($null -eq $response)
{
$matchingTag = $repositoryTags.results | Where-Object {$_.Name -eq $versionToCompare}
if ($null -ne $matchingTag)
{
Write-Host "Docker container already has latest version."
echo "CONTINUE=No" >> $env:GITHUB_OUTPUT
}
else
{
Write-Host "vNext Octopus CLI has been updated, create new image."
echo "CONTINUE=Yes" >> $env:GITHUB_OUTPUT
}
}
else
{
if ($response.StatusCode.value__ -eq 404)
{
Write-Host "No tags exist for repo, assuming first build."
echo "CONTINUE=Yes" >> $env:GITHUB_OUTPUT
}
}
}
shell: powershell
Expand Down

0 comments on commit 08f80aa

Please sign in to comment.