Skip to content

Commit

Permalink
[CI environment] Get yml pipeline name based on specs resourcetype (#…
Browse files Browse the repository at this point in the history
…3507)

* update pester pipeline scripts

* cleanup
  • Loading branch information
eriqua authored Aug 6, 2023
1 parent a05a34e commit 74193af
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
1 change: 1 addition & 0 deletions utilities/pipelines/staticValidation/helper/helper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ $repoRootPath = (Get-Item $PSScriptRoot).Parent.Parent.Parent.Parent.FullName
. (Join-Path $repoRootPath 'utilities' 'pipelines' 'sharedScripts' 'Get-ModuleTestFileList.ps1')
. (Join-Path $repoRootPath 'utilities' 'tools' 'Get-CrossReferencedModuleList.ps1')
. (Join-Path $repoRootPath 'utilities' 'tools' 'helper' 'ConvertTo-OrderedHashtable.ps1')
. (Join-Path $repoRootPath 'utilities' 'tools' 'helper' 'Get-PipelineFileName.ps1')

####################################
# Load test-specific functions #
Expand Down
9 changes: 5 additions & 4 deletions utilities/pipelines/staticValidation/module.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Describe 'Pipeline tests' -Tag 'Pipeline' {
)

$workflowsFolderName = Join-Path $repoRootPath '.github' 'workflows'
$workflowFileName = 'ms.{0}.yml' -f $moduleFolderName.Replace('\', '/').Replace('/', '.').Replace('-', '').ToLower()
$workflowFileName = Get-PipelineFileName -ResourceIdentifier $moduleFolderName
$workflowPath = Join-Path $workflowsFolderName $workflowFileName
Test-Path $workflowPath | Should -Be $true -Because "path [$workflowPath] should exist."
}
Expand All @@ -191,7 +191,7 @@ Describe 'Pipeline tests' -Tag 'Pipeline' {
}

$workflowsFolderName = Join-Path $repoRootPath '.github' 'workflows'
$workflowFileName = 'ms.{0}.yml' -f $moduleFolderName.Replace('\', '/').Replace('/', '.').Replace('-', '').ToLower()
$workflowFileName = Get-PipelineFileName -ResourceIdentifier $moduleFolderName
$workflowFilePath = Join-Path $workflowsFolderName $workflowFileName
$workflowContent = Get-Content -Path $workflowFilePath

Expand Down Expand Up @@ -240,7 +240,8 @@ Describe 'Pipeline tests' -Tag 'Pipeline' {
)

$pipelinesFolderName = Join-Path $repoRootPath '.azuredevops' 'modulePipelines'
$pipelineFileName = 'ms.{0}.yml' -f $moduleFolderName.Replace('\', '/').Replace('/', '.').Replace('-', '').ToLower()
$pipelineFileName = Get-PipelineFileName -ResourceIdentifier $moduleFolderName
Write-Verbose "pipelineFileName $pipelineFileName" -Verbose
$pipelinePath = Join-Path $pipelinesFolderName $pipelineFileName
Test-Path $pipelinePath | Should -Be $true -Because "path [$pipelinePath] should exist."
}
Expand All @@ -260,7 +261,7 @@ Describe 'Pipeline tests' -Tag 'Pipeline' {
}

$pipelinesFolderName = Join-Path $repoRootPath '.azuredevops' 'modulePipelines'
$pipelineFileName = 'ms.{0}.yml' -f $moduleFolderName.Replace('\', '/').Replace('/', '.').Replace('-', '').ToLower()
$pipelineFileName = Get-PipelineFileName -ResourceIdentifier $moduleFolderName
$pipelineFilePath = Join-Path $pipelinesFolderName $pipelineFileName
$pipelineContent = Get-Content -Path $pipelineFilePath

Expand Down
38 changes: 38 additions & 0 deletions utilities/tools/helper/Get-PipelineFileName.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<#
.SYNOPSIS
Find the correct yml pipeline naming for a given resource identifier.
.DESCRIPTION
Find the correct yml pipeline naming for a given resource identifier.
If a child resource type is provided, the corresponding yml pipeline name is the one of its parent resource type
.PARAMETER ResourceIdentifier
Mandatory. The resource identifier to search for, i.e. the relative module file path starting from the resource provider folder.
.EXAMPLE
Get-PipelineFileName -ResourceIdentifier 'storage/storage-account/blob-service/container/immutability-policy'.
Returns 'ms.storage.storageaccounts.yml'.
.EXAMPLE
Get-PipelineFileName -ResourceIdentifier 'storage/storage-account'.
Returns 'ms.storage.storageaccounts.yml'.
#>
function Get-PipelineFileName {

[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string] $ResourceIdentifier
)

. (Join-Path $PSScriptRoot 'Get-SpecsAlignedResourceName.ps1')

$provider, $parentType, $childTypeString = $ResourceIdentifier -split '[\/|\\]', 3
$parentResourceIdentifier = $provider, $parentType -join '/'
$formattedParentResourceType = Get-SpecsAlignedResourceName -ResourceIdentifier $parentResourceIdentifier
$pipelineFileName = '{0}.yml' -f $formattedParentResourceType.Replace('Microsoft.', 'ms.').Replace('/', '.').ToLower()

return $pipelineFileName
}

0 comments on commit 74193af

Please sign in to comment.