mirror of
https://github.com/actions/versions-package-tools.git
synced 2025-12-10 19:50:24 +00:00
Add Validate-FiltersFormat function
This commit is contained in:
@@ -2,6 +2,21 @@
|
|||||||
|
|
||||||
Import-Module (Join-Path $PSScriptRoot "helpers.psm1") -Force
|
Import-Module (Join-Path $PSScriptRoot "helpers.psm1") -Force
|
||||||
|
|
||||||
|
Describe "Validate-FiltersFormat" {
|
||||||
|
It "Filter with word" {
|
||||||
|
{ Validate-FiltersFormat -Filters @("1two.2") } | Should -Throw "Invalid filter format"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Filter with non-word character" {
|
||||||
|
{ Validate-FiltersFormat -Filters @("1,.2") } | Should -Throw "Invalid filter format"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Valid filters" {
|
||||||
|
{ Validate-FiltersFormat -Filters @("*", "1", "1.*", "1.2", "1.2.*") } | Should -Not -Throw "Invalid filter format"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Describe "Format-Versions" {
|
Describe "Format-Versions" {
|
||||||
It "Clean versions" {
|
It "Clean versions" {
|
||||||
$actualOutput = Format-Versions -Versions @("14.2.0", "1.14.0")
|
$actualOutput = Format-Versions -Versions @("14.2.0", "1.14.0")
|
||||||
@@ -34,13 +49,13 @@ Describe "Format-Versions" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Describe "Filter-Versions" {
|
Describe "Select-VersionsByFilter" {
|
||||||
$inputVersions = @("8.2.1", "9.3.3", "10.0.2", "10.0.3", "10.5.6", "12.4.3", "12.5.1", "14.2.0")
|
$inputVersions = @("8.2.1", "9.3.3", "10.0.2", "10.0.3", "10.5.6", "12.4.3", "12.5.1", "14.2.0")
|
||||||
|
|
||||||
It "Include filter only" {
|
It "Include filter only" {
|
||||||
$includeFilters = @("8.*", "14.*")
|
$includeFilters = @("8.*", "14.*")
|
||||||
$excludeFilters = @()
|
$excludeFilters = @()
|
||||||
$actualOutput = Filter-Versions -Versions $inputVersions -IncludeFilters $includeFilters -ExcludeFilters $excludeFilters
|
$actualOutput = Select-VersionsByFilter -Versions $inputVersions -IncludeFilters $includeFilters -ExcludeFilters $excludeFilters
|
||||||
$expectedOutput = @("8.2.1", "14.2.0")
|
$expectedOutput = @("8.2.1", "14.2.0")
|
||||||
$actualOutput | Should -Be $expectedOutput
|
$actualOutput | Should -Be $expectedOutput
|
||||||
}
|
}
|
||||||
@@ -48,7 +63,7 @@ Describe "Filter-Versions" {
|
|||||||
It "Include and exclude filters" {
|
It "Include and exclude filters" {
|
||||||
$includeFilters = @("10.*", "12.*")
|
$includeFilters = @("10.*", "12.*")
|
||||||
$excludeFilters = @("10.0.*", "12.4.3")
|
$excludeFilters = @("10.0.*", "12.4.3")
|
||||||
$actualOutput = Filter-Versions -Versions $inputVersions -IncludeFilters $includeFilters -ExcludeFilters $excludeFilters
|
$actualOutput = Select-VersionsByFilter -Versions $inputVersions -IncludeFilters $includeFilters -ExcludeFilters $excludeFilters
|
||||||
$expectedOutput = @("10.5.6", "12.5.1")
|
$expectedOutput = @("10.5.6", "12.5.1")
|
||||||
$actualOutput | Should -Be $expectedOutput
|
$actualOutput | Should -Be $expectedOutput
|
||||||
}
|
}
|
||||||
@@ -56,13 +71,13 @@ Describe "Filter-Versions" {
|
|||||||
It "Exclude filter only" {
|
It "Exclude filter only" {
|
||||||
$includeFilters = @()
|
$includeFilters = @()
|
||||||
$excludeFilters = @("10.*", "12.*")
|
$excludeFilters = @("10.*", "12.*")
|
||||||
$actualOutput = Filter-Versions -Versions $inputVersions -IncludeFilters $includeFilters -ExcludeFilters $excludeFilters
|
$actualOutput = Select-VersionsByFilter -Versions $inputVersions -IncludeFilters $includeFilters -ExcludeFilters $excludeFilters
|
||||||
$expectedOutput = @("8.2.1", "9.3.3", "14.2.0")
|
$expectedOutput = @("8.2.1", "9.3.3", "14.2.0")
|
||||||
$actualOutput | Should -Be $expectedOutput
|
$actualOutput | Should -Be $expectedOutput
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Include and exclude filters are empty" {
|
It "Include and exclude filters are empty" {
|
||||||
$actualOutput = Filter-Versions -Versions $inputVersions
|
$actualOutput = Select-VersionsByFilter -Versions $inputVersions
|
||||||
$expectedOutput = @("8.2.1", "9.3.3", "10.0.2", "10.0.3", "10.5.6", "12.4.3", "12.5.1", "14.2.0")
|
$expectedOutput = @("8.2.1", "9.3.3", "10.0.2", "10.0.3", "10.5.6", "12.4.3", "12.5.1", "14.2.0")
|
||||||
$actualOutput | Should -Be $expectedOutput
|
$actualOutput | Should -Be $expectedOutput
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,6 @@ param (
|
|||||||
|
|
||||||
Import-Module (Join-Path $PSScriptRoot "helpers.psm1")
|
Import-Module (Join-Path $PSScriptRoot "helpers.psm1")
|
||||||
|
|
||||||
$VersionFilterToInclude.GetType()
|
|
||||||
$VersionFilterToInclude.Length
|
|
||||||
$VersionFilterToInclude | ForEach-Object { Write-Host $_ }
|
|
||||||
|
|
||||||
function Get-VersionsByUrl {
|
function Get-VersionsByUrl {
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory)] [string] $ToolPackagesUrl,
|
[Parameter(Mandatory)] [string] $ToolPackagesUrl,
|
||||||
@@ -29,6 +25,14 @@ function Get-VersionsByUrl {
|
|||||||
return $packages.version
|
return $packages.version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($VersionFilterToInclude) {
|
||||||
|
Validate-FiltersFormat -Filters $VersionFilterToInclude
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($VersionFilterToExclude) {
|
||||||
|
Validate-FiltersFormat -Filters $VersionFilterToExclude
|
||||||
|
}
|
||||||
|
|
||||||
Write-Host "Get the packages list from $DistURL"
|
Write-Host "Get the packages list from $DistURL"
|
||||||
$versionsFromDist = Get-VersionsByUrl -ToolPackagesUrl $DistURL `
|
$versionsFromDist = Get-VersionsByUrl -ToolPackagesUrl $DistURL `
|
||||||
-RetryIntervalSec $RetryIntervalSec `
|
-RetryIntervalSec $RetryIntervalSec `
|
||||||
@@ -41,9 +45,9 @@ Write-Host "Get the packages list from $ManifestLink"
|
|||||||
|
|
||||||
[Version[]] $formattedVersions = Format-Versions -Versions $versionsFromDist
|
[Version[]] $formattedVersions = Format-Versions -Versions $versionsFromDist
|
||||||
|
|
||||||
$formattedVersions = Filter-Versions -Versions $formattedVersions `
|
$formattedVersions = Select-VersionsByFilter -Versions $formattedVersions `
|
||||||
-IncludeFilters $VersionFilterToInclude `
|
-IncludeFilters $VersionFilterToInclude `
|
||||||
-ExcludeFilters $VersionFilterToExclude
|
-ExcludeFilters $VersionFilterToExclude
|
||||||
|
|
||||||
$versionsToBuild = Skip-ExistingVersions -VersionsFromManifest $versionsFromManifest `
|
$versionsToBuild = Skip-ExistingVersions -VersionsFromManifest $versionsFromManifest `
|
||||||
-VersionsFromDist $formattedVersions
|
-VersionsFromDist $formattedVersions
|
||||||
|
|||||||
@@ -1,3 +1,17 @@
|
|||||||
|
function Validate-FiltersFormat {
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory)] [string[]] $Filters
|
||||||
|
)
|
||||||
|
|
||||||
|
foreach($filter in $Filters) {
|
||||||
|
$filter.Split('.') | ForEach-Object {
|
||||||
|
if (($_ -notmatch '^\d+$') -and ($_ -ne '*')) {
|
||||||
|
throw "Invalid filter format - $filter"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function Format-Versions {
|
function Format-Versions {
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory)] [string[]] $Versions
|
[Parameter(Mandatory)] [string[]] $Versions
|
||||||
@@ -30,7 +44,7 @@ function Format-Versions {
|
|||||||
return $formattedVersions
|
return $formattedVersions
|
||||||
}
|
}
|
||||||
|
|
||||||
function Filter-Versions {
|
function Select-VersionsByFilter {
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory)] [version[]] $Versions,
|
[Parameter(Mandatory)] [version[]] $Versions,
|
||||||
[string[]] $IncludeFilters,
|
[string[]] $IncludeFilters,
|
||||||
@@ -45,8 +59,7 @@ function Filter-Versions {
|
|||||||
$ver = $_
|
$ver = $_
|
||||||
$matchedIncludeFilters = $IncludeFilters | Where-Object { $ver -like $_ }
|
$matchedIncludeFilters = $IncludeFilters | Where-Object { $ver -like $_ }
|
||||||
$matchedExcludeFilters = $ExcludeFilters | Where-Object { $ver -like $_ }
|
$matchedExcludeFilters = $ExcludeFilters | Where-Object { $ver -like $_ }
|
||||||
|
return ($null -ne $matchedIncludeFilters) -and ($null -eq $matchedExcludeFilters)
|
||||||
return ($matchedIncludeFilters -ne $null) -and ($matchedExcludeFilters -eq $null)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user