diff --git a/get-new-tool-versions/get-new-tool-versions.ps1 b/get-new-tool-versions/get-new-tool-versions.ps1 index 7eebb55..6df0727 100644 --- a/get-new-tool-versions/get-new-tool-versions.ps1 +++ b/get-new-tool-versions/get-new-tool-versions.ps1 @@ -37,25 +37,23 @@ Write-Host "Get the packages list from $ManifestLink" [Version[]] $formattedVersions = Format-Versions -Versions $versionsFromDist -if (-not ([string]::IsNullOrEmpty($VersionFilterToInclude))) { +if ($VersionFilterToInclude) { $formattedVersions = Filter-Versions -Versions $formattedVersions ` -VersionFilter $VersionFilterToInclude ` -IncludeVersions $true } -if (-not ([string]::IsNullOrEmpty($VersionFilterToExclude))) { +if ($VersionFilterToExclude) { $formattedVersions = Filter-Versions -Versions $formattedVersions ` -VersionFilter $VersionFilterToExclude ` -IncludeVersions $false } -$versionsToBuild = Get-VersionsToBuild -VersionsFromManifest $versionsFromManifest ` - -VersionsFromDist $formattedVersions +$versionsToBuild = Skip-ExistingVersions -VersionsFromManifest $versionsFromManifest ` + -VersionsFromDist $formattedVersions -if ([string]::IsNullOrEmpty($versionsToBuild)) { - Write-Host "There isn't versions to build" - return $null -} else { +if ($versionsToBuild) { Write-Host "The following versions are available to build:`n$versionsToBuild" - return "$versionsToBuild" +} else { + Write-Host "There isn't versions to build" } diff --git a/get-new-tool-versions/helpers.psm1 b/get-new-tool-versions/helpers.psm1 index c70b3fe..8463fd4 100644 --- a/get-new-tool-versions/helpers.psm1 +++ b/get-new-tool-versions/helpers.psm1 @@ -8,16 +8,15 @@ function Format-Versions { 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 { + # Cut a string from index of first digit because initially it has invalid format (v14.4.0 or go1.14.4) + if (-not ($version -match '(?\d)')) { Write-Host "Invalid version format - $version" - exit 1 + exit 1 } + $firstDigitIndex = $version.indexof($Matches.number) + $substredVersion = $version.substring($firstDigitIndex) - # We filter versions to exclude unstable (for example: "go1.15beta1") + # 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 @@ -54,14 +53,14 @@ function Filter-Versions { return $filteredVersions } -function Get-VersionsToBuild { +function Skip-ExistingVersions { param ( [Parameter(Mandatory)] [string[]] $VersionsFromManifest, [Parameter(Mandatory)] [string[]] $VersionsFromDist ) - [System.Collections.ArrayList]$versionsToBuid = $VersionsFromDist - $VersionsFromManifest | ForEach-Object { $versionsToBuid.Remove($_) } + $newVersions = @() + $newVersions += $VersionsFromDist | Where-Object { $VersionsFromManifest -notcontains $_ } - return $versionsToBuid + return $newVersions } \ No newline at end of file