diff --git a/.github/workflows/octo.yml b/.github/workflows/octo.yml index 9e5dfef..7bea3b5 100644 --- a/.github/workflows/octo.yml +++ b/.github/workflows/octo.yml @@ -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 diff --git a/.github/workflows/octopus-cli.yml b/.github/workflows/octopus-cli.yml index ef8d4b5..5478ea2 100644 --- a/.github/workflows/octopus-cli.yml +++ b/.github/workflows/octopus-cli.yml @@ -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