You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
versions-package-tools/get-new-tool-versions/helpers.psm1

66 lines
1.9 KiB
PowerShell

5 years ago
function Format-Versions {
param (
[Parameter(Mandatory)] [string[]] $Versions
)
[Version[]] $formattedVersions = @()
foreach($version in $Versions) {
$substredVersion = $null
5 years ago
# 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 '(?<number>\d)')) {
5 years ago
Write-Host "Invalid version format - $version"
5 years ago
exit 1
5 years ago
}
5 years ago
$firstDigitIndex = $version.indexof($Matches.number)
$substredVersion = $version.substring($firstDigitIndex)
5 years ago
5 years ago
# Filter versions to exclude unstable (for example: "go1.15beta1")
5 years ago
# 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
}
5 years ago
function Skip-ExistingVersions {
5 years ago
param (
[Parameter(Mandatory)] [string[]] $VersionsFromManifest,
[Parameter(Mandatory)] [string[]] $VersionsFromDist
)
5 years ago
$newVersions = @()
$newVersions += $VersionsFromDist | Where-Object { $VersionsFromManifest -notcontains $_ }
5 years ago
5 years ago
return $newVersions
5 years ago
}