diff --git a/check-new-tool-versions.ps1 b/get-new-tool-versions/get-new-tool-versions.ps1 similarity index 53% rename from check-new-tool-versions.ps1 rename to get-new-tool-versions/get-new-tool-versions.ps1 index 3b83239..7eebb55 100644 --- a/check-new-tool-versions.ps1 +++ b/get-new-tool-versions/get-new-tool-versions.ps1 @@ -12,6 +12,8 @@ param ( [UInt32] $RetryCount = 3 ) +Import-Module (Join-Path $PSScriptRoot "helpers.psm1") + function Get-VersionsByUrl { param ( [Parameter(Mandatory)] [string] $ToolPackagesUrl, @@ -23,74 +25,6 @@ function Get-VersionsByUrl { return $packages.version } -function Format-Versions { - param ( - [Parameter(Mandatory)] [string[]] $Versions - ) - - [Version[]] $formattedVersions = @() - - foreach($version in $Versions) { - $substredVersion = $null - - # We cut a string from index of first digit because initially it has invalid format (v14.4.0 or go1.14.4) - if ($version -match '(?\d)') { - $firstDigitIndex = $version.indexof($Matches.number) - $substredVersion = $version.substring($firstDigitIndex) - } else { - Write-Host "Invalid version format - $version" - exit 1 - } - - # We filter versions to exclude unstable (for example: "go1.15beta1") - # Valid version format: x.x or x.x.x - if ($substredVersion -notmatch '^\d+\.+\d+\.*\d*$') { - continue - } - - if ($substredVersion.Split(".").Length -lt 3) { - $formattedVersions += "$substredVersion.0" - } else { - $formattedVersions += $substredVersion - } - } - - return $formattedVersions -} - -function Filter-Versions { - param ( - [Parameter(Mandatory)] [string[]] $Versions, - [Parameter(Mandatory)] [string] $VersionFilter, - [Parameter(Mandatory)] [bool] $IncludeVersions - ) - - $versionFilters = $VersionFilter.Split(',') - [Version[]] $filteredVersions = @() - - foreach($filter in $versionFilters) { - if ($IncludeVersions) { - $filteredVersions += $Versions | Where-Object { $_ -like $filter } - } else { - $filteredVersions += $Versions | Where-Object { $_ -notlike $filter } - } - } - - return $filteredVersions -} - -function Get-VersionsToBuild { - param ( - [Parameter(Mandatory)] [string[]] $VersionsFromManifest, - [Parameter(Mandatory)] [string[]] $VersionsFromDist - ) - - [System.Collections.ArrayList]$versionsToBuid = $VersionsFromDist - $VersionsFromManifest | ForEach-Object { $versionsToBuid.Remove($_) } - - return $versionsToBuid -} - Write-Host "Get the packages list from $DistURL" $versionsFromDist = Get-VersionsByUrl -ToolPackagesUrl $DistURL ` -RetryIntervalSec $RetryIntervalSec ` diff --git a/get-new-tool-versions/helpers.psm1 b/get-new-tool-versions/helpers.psm1 new file mode 100644 index 0000000..c70b3fe --- /dev/null +++ b/get-new-tool-versions/helpers.psm1 @@ -0,0 +1,67 @@ +function Format-Versions { + param ( + [Parameter(Mandatory)] [string[]] $Versions + ) + + [Version[]] $formattedVersions = @() + + foreach($version in $Versions) { + $substredVersion = $null + + # We cut a string from index of first digit because initially it has invalid format (v14.4.0 or go1.14.4) + if ($version -match '(?\d)') { + $firstDigitIndex = $version.indexof($Matches.number) + $substredVersion = $version.substring($firstDigitIndex) + } else { + Write-Host "Invalid version format - $version" + exit 1 + } + + # We filter versions to exclude unstable (for example: "go1.15beta1") + # Valid version format: x.x or x.x.x + if ($substredVersion -notmatch '^\d+\.+\d+\.*\d*$') { + continue + } + + if ($substredVersion.Split(".").Length -lt 3) { + $formattedVersions += "$substredVersion.0" + } else { + $formattedVersions += $substredVersion + } + } + + return $formattedVersions +} + +function Filter-Versions { + param ( + [Parameter(Mandatory)] [string[]] $Versions, + [Parameter(Mandatory)] [string] $VersionFilter, + [Parameter(Mandatory)] [bool] $IncludeVersions + ) + + $versionFilters = $VersionFilter.Split(',') + [Version[]] $filteredVersions = @() + + foreach($filter in $versionFilters) { + if ($IncludeVersions) { + $filteredVersions += $Versions | Where-Object { $_ -like $filter } + } else { + $filteredVersions += $Versions | Where-Object { $_ -notlike $filter } + } + } + + return $filteredVersions +} + +function Get-VersionsToBuild { + param ( + [Parameter(Mandatory)] [string[]] $VersionsFromManifest, + [Parameter(Mandatory)] [string[]] $VersionsFromDist + ) + + [System.Collections.ArrayList]$versionsToBuid = $VersionsFromDist + $VersionsFromManifest | ForEach-Object { $versionsToBuid.Remove($_) } + + return $versionsToBuid +} \ No newline at end of file