From e2e44e4d9fe85184579cff2866077d76278fe1c8 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Sun, 7 Aug 2022 21:04:15 +0200 Subject: [PATCH 1/4] Updated Join-Path --- utilities/tools/ConvertTo-ARMTemplate.ps1 | 10 +++++----- utilities/tools/Set-ModuleReadMe.ps1 | 2 +- utilities/tools/Test-ModuleLocally.ps1 | 15 ++++++++------- utilities/tools/Test-NamePrefixAvailability.ps1 | 8 ++++---- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/utilities/tools/ConvertTo-ARMTemplate.ps1 b/utilities/tools/ConvertTo-ARMTemplate.ps1 index 90fe651023..a6860a15c5 100644 --- a/utilities/tools/ConvertTo-ARMTemplate.ps1 +++ b/utilities/tools/ConvertTo-ARMTemplate.ps1 @@ -56,7 +56,7 @@ param ( ) $rootPath = Get-Item -Path $Path | Select-Object -ExpandProperty 'FullName' -$modulesFolderPath = Join-Path -Path $rootPath -ChildPath 'modules' +$modulesFolderPath = Join-Path $rootPath 'modules' if ($ConvertChildren) { $BicepFilesToConvert = Get-ChildItem -Path $modulesFolderPath -Filter 'deploy.bicep' -Recurse -Force } else { @@ -66,7 +66,7 @@ if ($ConvertChildren) { #region Remove existing deploy.json files Write-Verbose 'Remove existing deploy.json files' -if (Test-Path -Path (Join-Path -Path $modulesFolderPath -ChildPath 'deploy.bicep')) { +if (Test-Path -Path (Join-Path $modulesFolderPath 'deploy.bicep')) { $JsonFilesToRemove = Get-ChildItem -Path $modulesFolderPath -Filter 'deploy.json' -Recurse -Force -File Write-Verbose "Remove existing deploy.json files - Remove [$($JsonFilesToRemove.count)] file(s)" if ($PSCmdlet.ShouldProcess("[$($JsonFilesToRemove.count)] deploy.json files(s) in path [$modulesFolderPath]", 'Remove-Item')) { @@ -132,7 +132,7 @@ if (-not $SkipMetadataCleanup) { } $moduleFolderPath = $_.Directory.FullName - $JSONFilePath = Join-Path -Path $moduleFolderPath -ChildPath 'deploy.json' + $JSONFilePath = Join-Path $moduleFolderPath 'deploy.json' if (Test-Path -Path $JSONFilePath) { $JSONFileContent = Get-Content -Path $JSONFilePath $JSONObj = $JSONFileContent | ConvertFrom-Json @@ -174,7 +174,7 @@ if (-not $SkipPipelineUpdate) { Write-Verbose 'Update pipeline files' # GitHub workflow files - $ghWorkflowFolderPath = Join-Path -Path $rootPath -ChildPath '.github\workflows' + $ghWorkflowFolderPath = Join-Path -Path $rootPath '.github' 'workflows' if (Test-Path -Path $ghWorkflowFolderPath) { $ghWorkflowFilesToUpdate = Get-ChildItem -Path $ghWorkflowFolderPath -Filter 'ms.*.yml' -File -Force Write-Verbose ('Update workflow files - Processing [{0}] file(s)' -f $ghWorkflowFilesToUpdate.count) @@ -190,7 +190,7 @@ if (-not $SkipPipelineUpdate) { } # Azure DevOps Pipelines - $adoPipelineFolderPath = Join-Path -Path $rootPath -ChildPath '.azuredevops\modulePipelines' + $adoPipelineFolderPath = Join-Path -Path $rootPath '.azuredevops' 'modulePipelines' if (Test-Path -Path $adoPipelineFolderPath) { $adoPipelineFilesToUpdate = Get-ChildItem -Path $adoPipelineFolderPath -Filter 'ms.*.yml' -File -Force Write-Verbose ('Update Azure DevOps pipeline files - Processing [{0}] file(s)' -f $adoPipelineFilesToUpdate.count) diff --git a/utilities/tools/Set-ModuleReadMe.ps1 b/utilities/tools/Set-ModuleReadMe.ps1 index 4c9810c656..5ab34ce7e2 100644 --- a/utilities/tools/Set-ModuleReadMe.ps1 +++ b/utilities/tools/Set-ModuleReadMe.ps1 @@ -761,7 +761,7 @@ function Set-ModuleReadMe { ) # Load external functions - . (Join-Path $PSScriptRoot 'helper/Merge-FileWithNewContent.ps1') + . (Join-Path $PSScriptRoot 'helper' 'Merge-FileWithNewContent.ps1') . (Join-Path (Split-Path $PSScriptRoot -Parent) 'pipelines' 'sharedScripts' 'Get-NestedResourceList.ps1') # Check template & make full path diff --git a/utilities/tools/Test-ModuleLocally.ps1 b/utilities/tools/Test-ModuleLocally.ps1 index 6ded5e4342..b399f01ffe 100644 --- a/utilities/tools/Test-ModuleLocally.ps1 +++ b/utilities/tools/Test-ModuleLocally.ps1 @@ -139,12 +139,13 @@ function Test-ModuleLocally { begin { $repoRootPath = (Get-Item $PSScriptRoot).Parent.Parent $ModuleName = Split-Path (Split-Path $TemplateFilePath -Parent) -Leaf - Write-Verbose "Running Local Tests for $($ModuleName)" + $utilitiesFolderPath = Split-Path $PSScriptRoot -Parent + Write-Verbose "Running Local Tests for [$ModuleName]" # Load Tokens Converter Scripts - . (Join-Path $PSScriptRoot '../pipelines/tokensReplacement/Convert-TokensInFileList.ps1') + . (Join-Path $utilitiesFolderPath 'pipelines' 'tokensReplacement' 'Convert-TokensInFileList.ps1') # Load Modules Validation / Deployment Scripts - . (Join-Path $PSScriptRoot '../pipelines/resourceDeployment/New-TemplateDeployment.ps1') - . (Join-Path $PSScriptRoot '../pipelines/resourceDeployment/Test-TemplateDeployment.ps1') + . (Join-Path $utilitiesFolderPath 'pipelines' 'resourceDeployment' 'New-TemplateDeployment.ps1') + . (Join-Path $utilitiesFolderPath 'pipelines' 'resourceDeployment' 'Test-TemplateDeployment.ps1') } process { @@ -152,7 +153,7 @@ function Test-ModuleLocally { # PESTER Tests # ################ if ($PesterTest) { - Write-Verbose "Pester Testing Module: $ModuleName" + Write-Verbose "Pester Testing Module [$ModuleName]" try { $enforcedTokenList = @{} if ($ValidateOrDeployParameters.ContainsKey('subscriptionId')) { @@ -220,8 +221,8 @@ function Test-ModuleLocally { if (Test-Path $settingsFilePath) { $Settings = Get-Content -Path $settingsFilePath -Raw | ConvertFrom-Json -AsHashtable $ConvertTokensInputs += @{ - TokenPrefix = $Settings.parameterFileTokens.tokenPrefix - TokenSuffix = $Settings.parameterFileTokens.tokenSuffix + TokenPrefix = $Settings.parameterFileTokens.tokenPrefix + TokenSuffix = $Settings.parameterFileTokens.tokenSuffix } if ($Settings.parameterFileTokens.localTokens) { diff --git a/utilities/tools/Test-NamePrefixAvailability.ps1 b/utilities/tools/Test-NamePrefixAvailability.ps1 index 7a6c5668ae..ab52eefe04 100644 --- a/utilities/tools/Test-NamePrefixAvailability.ps1 +++ b/utilities/tools/Test-NamePrefixAvailability.ps1 @@ -42,8 +42,8 @@ function Test-NamePrefixAvailability { Write-Debug ('{0} entered' -f $MyInvocation.MyCommand) # Load helper Scripts - . (Join-Path $PSScriptRoot '../pipelines/tokensReplacement/Convert-TokensInFileList.ps1') - $root = (Get-Item $PSScriptRoot).Parent.Parent.FullName + $repoRoot = (Get-Item $PSScriptRoot).Parent.Parent.FullName + . (Join-Path $repoRoot 'utilities' 'pipelines' 'tokensReplacement' 'Convert-TokensInFileList.ps1') } process { @@ -56,7 +56,7 @@ function Test-NamePrefixAvailability { 'Microsoft.ContainerRegistry/registries' 'Microsoft.KeyVault/vaults' ) - $parameterFiles = (Get-ChildItem -Path $root -Recurse -Filter '*.json').FullName | ForEach-Object { $_.Replace('\', '/') } + $parameterFiles = (Get-ChildItem -Path $repoRoot -Recurse -Filter '*.json').FullName | ForEach-Object { $_.Replace('\', '/') } $parameterFiles = $parameterFiles | Where-Object { $_ -match '(?:{0}).*parameters\.json' -f ($relevantResourceTypes -join '|' -replace '/', '\/+') } # Replace parameter file tokens @@ -67,7 +67,7 @@ function Test-NamePrefixAvailability { } # Tokens in settings.json - $settingsFilePath = Join-Path $root 'settings.json' + $settingsFilePath = Join-Path $repoRoot 'settings.json' if (Test-Path $settingsFilePath) { $Settings = Get-Content -Path $settingsFilePath -Raw | ConvertFrom-Json -AsHashtable $ConvertTokensInputs += @{ From 5b4010f56ced6c95fe845ec32d80ef2f42ffcae2 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Sun, 7 Aug 2022 21:04:29 +0200 Subject: [PATCH 2/4] UPdated Join-Path --- .../pipelineTemplates/jobs.publishModule.yml | 12 ++++++------ .../platformPipelines/platform.updateReadMe.yml | 2 +- .github/workflows/platform.updateReadMe.yml | 2 +- .../resourcePublish/Get-ModulesToPublish.ps1 | 10 +++++----- .../pipelines/staticValidation/module.tests.ps1 | 2 +- .../tokensReplacement/Convert-TokensInFileList.ps1 | 6 +++--- .../tokensReplacement/helper/Convert-TokenInFile.ps1 | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.azuredevops/pipelineTemplates/jobs.publishModule.yml b/.azuredevops/pipelineTemplates/jobs.publishModule.yml index f22e1761c3..4bcf191f2a 100644 --- a/.azuredevops/pipelineTemplates/jobs.publishModule.yml +++ b/.azuredevops/pipelineTemplates/jobs.publishModule.yml @@ -159,9 +159,9 @@ jobs: . (Join-Path '$(System.DefaultWorkingDirectory)' '$(pipelineFunctionsPath)' 'resourcePublish' 'Publish-ModuleToUniversalArtifactFeed.ps1') #Prioritizing the bicep file - $TemplateFilePath = Join-Path -Path '$(ENVMODULEPATH)' -ChildPath 'deploy.bicep' + $TemplateFilePath = Join-Path '$(ENVMODULEPATH)' 'deploy.bicep' if (-not (Test-Path $TemplateFilePath)) { - $TemplateFilePath = Join-Path -Path '$(ENVMODULEPATH)' -ChildPath 'deploy.json' + $TemplateFilePath = Join-Path '$(ENVMODULEPATH)' 'deploy.json' } $functionInput = @{ @@ -218,9 +218,9 @@ jobs: . (Join-Path '$(System.DefaultWorkingDirectory)' '$(pipelineFunctionsPath)' 'resourcePublish' 'Publish-ModuleToTemplateSpec.ps1') #Prioritizing the bicep file - $TemplateFilePath = Join-Path -Path '$(ENVMODULEPATH)' -ChildPath 'deploy.bicep' + $TemplateFilePath = Join-Path '$(ENVMODULEPATH)' 'deploy.bicep' if (-not (Test-Path $TemplateFilePath)) { - $TemplateFilePath = Join-Path -Path '$(ENVMODULEPATH)' -ChildPath 'deploy.json' + $TemplateFilePath = Join-Path '$(ENVMODULEPATH)' 'deploy.json' } $functionInput = @{ @@ -278,9 +278,9 @@ jobs: . (Join-Path '$(System.DefaultWorkingDirectory)' '$(pipelineFunctionsPath)' 'resourcePublish' 'Publish-ModuleToPrivateBicepRegistry.ps1') #Prioritizing the bicep file - $TemplateFilePath = Join-Path -Path '$(ENVMODULEPATH)' -ChildPath 'deploy.bicep' + $TemplateFilePath = Join-Path '$(ENVMODULEPATH)' 'deploy.bicep' if (-not (Test-Path $TemplateFilePath)) { - $TemplateFilePath = Join-Path -Path '$(ENVMODULEPATH)' -ChildPath 'deploy.json' + $TemplateFilePath = Join-Path '$(ENVMODULEPATH)' 'deploy.json' } $functionInput = @{ diff --git a/.azuredevops/platformPipelines/platform.updateReadMe.yml b/.azuredevops/platformPipelines/platform.updateReadMe.yml index a858f0d353..0667b84f93 100644 --- a/.azuredevops/platformPipelines/platform.updateReadMe.yml +++ b/.azuredevops/platformPipelines/platform.updateReadMe.yml @@ -69,7 +69,7 @@ jobs: $functionInput = @{ ModulesPath = Join-Path '$(System.DefaultWorkingDirectory)' 'modules' - FilePath = Join-Path '$(System.DefaultWorkingDirectory)' 'modules/README.md' + FilePath = Join-Path '$(System.DefaultWorkingDirectory)' 'modules' 'README.md' Organization = '$(System.CollectionUri)'.Split('/')[3] RepositoryName = '$(Build.Repository.Name)' ColumnsInOrder = @('Name', 'ProviderNamespace','ResourceType') diff --git a/.github/workflows/platform.updateReadMe.yml b/.github/workflows/platform.updateReadMe.yml index 6625950b23..2a865cda47 100644 --- a/.github/workflows/platform.updateReadMe.yml +++ b/.github/workflows/platform.updateReadMe.yml @@ -59,7 +59,7 @@ jobs: $functionInput = @{ ModulesPath = Join-Path $env:GITHUB_WORKSPACE 'modules' - FilePath = Join-Path $env:GITHUB_WORKSPACE 'modules/README.md' + FilePath = Join-Path $env:GITHUB_WORKSPACE 'modules' 'README.md' Organization = ($env:GITHUB_REPOSITORY).split('/')[0] RepositoryName = ($env:GITHUB_REPOSITORY).split('/')[1] ColumnsInOrder = @('Name', 'ProviderNamespace','ResourceType') diff --git a/utilities/pipelines/resourcePublish/Get-ModulesToPublish.ps1 b/utilities/pipelines/resourcePublish/Get-ModulesToPublish.ps1 index 7993734f5a..ff468a5b3c 100644 --- a/utilities/pipelines/resourcePublish/Get-ModulesToPublish.ps1 +++ b/utilities/pipelines/resourcePublish/Get-ModulesToPublish.ps1 @@ -103,9 +103,9 @@ function Find-TemplateFile { } #Prioritizing the bicep file - $TemplateFilePath = Join-Path -Path $FolderPath -ChildPath 'deploy.bicep' + $TemplateFilePath = Join-Path $FolderPath 'deploy.bicep' if (-not (Test-Path $TemplateFilePath)) { - $TemplateFilePath = Join-Path -Path $FolderPath -ChildPath 'deploy.json' + $TemplateFilePath = Join-Path $FolderPath 'deploy.json' } if (-not (Test-Path $TemplateFilePath)) { @@ -211,9 +211,9 @@ function Get-ParentModuleTemplateFile { $ParentFolderPath = Split-Path $ModuleFolderPath -Parent #Prioritizing the bicep file - $ParentTemplateFilePath = Join-Path -Path $ParentFolderPath -ChildPath 'deploy.bicep' + $ParentTemplateFilePath = Join-Path $ParentFolderPath 'deploy.bicep' if (-not (Test-Path $TemplateFilePath)) { - $ParentTemplateFilePath = Join-Path -Path $ParentFolderPath -ChildPath 'deploy.json' + $ParentTemplateFilePath = Join-Path $ParentFolderPath 'deploy.json' } if (-not (Test-Path -Path $ParentTemplateFilePath)) { @@ -283,7 +283,7 @@ function Get-ModuleVersionFromFile { ) $ModuleFolder = Split-Path -Path $TemplateFilePath -Parent - $VersionFilePath = Join-Path -Path $ModuleFolder -ChildPath 'version.json' + $VersionFilePath = Join-Path $ModuleFolder 'version.json' if (-not (Test-Path -Path $VersionFilePath)) { throw "No version file found at: [$VersionFilePath]" diff --git a/utilities/pipelines/staticValidation/module.tests.ps1 b/utilities/pipelines/staticValidation/module.tests.ps1 index 8a1dc99e07..6766636802 100644 --- a/utilities/pipelines/staticValidation/module.tests.ps1 +++ b/utilities/pipelines/staticValidation/module.tests.ps1 @@ -35,7 +35,7 @@ $script:jsonTemplateLoadFailedException = "Unable to load the deploy.json templa $script:templateNotFoundException = 'No template file found in folder [{0}]' # -f $moduleFolderPath # Import any helper function used in this test script -Import-Module (Join-Path $PSScriptRoot 'helper\helper.psm1') -Force +Import-Module (Join-Path $PSScriptRoot 'helper' 'helper.psm1') -Force Describe 'File/folder tests' -Tag Modules { diff --git a/utilities/pipelines/tokensReplacement/Convert-TokensInFileList.ps1 b/utilities/pipelines/tokensReplacement/Convert-TokensInFileList.ps1 index 84fc839615..efb4907875 100644 --- a/utilities/pipelines/tokensReplacement/Convert-TokensInFileList.ps1 +++ b/utilities/pipelines/tokensReplacement/Convert-TokensInFileList.ps1 @@ -25,7 +25,7 @@ Optional. A string for a custom output directory of the modified parameter file .NOTES - Make sure you provide the right information in the objects that contain tokens. This is in the form of - @( +@( @{ Name = 'deploymentSpId'; Value = '12345678-1234-1234-1234-123456789123' } @{ Name = 'tenantId'; Value = '12345678-1234-1234-1234-123456789123' } @@ -37,7 +37,7 @@ function Convert-TokensInFileList { [CmdletBinding()] param ( [parameter( - Mandatory = $true, + Mandatory = $true, ValueFromPipeline = $true )] [String[]] $FilePathList, @@ -60,7 +60,7 @@ function Convert-TokensInFileList { begin { # Load used funtions - . (Join-Path $PSScriptRoot './helper/Convert-TokenInFile.ps1') + . (Join-Path $PSScriptRoot 'helper' 'Convert-TokenInFile.ps1') } process { diff --git a/utilities/pipelines/tokensReplacement/helper/Convert-TokenInFile.ps1 b/utilities/pipelines/tokensReplacement/helper/Convert-TokenInFile.ps1 index bb7be0eb72..7e6a5dc98c 100644 --- a/utilities/pipelines/tokensReplacement/helper/Convert-TokenInFile.ps1 +++ b/utilities/pipelines/tokensReplacement/helper/Convert-TokenInFile.ps1 @@ -81,7 +81,7 @@ function Convert-TokenInFile { # Set Content if ($OutputDirectory -and (Test-Path -Path $OutputDirectory -PathType Container)) { # If Specific Output Directory Provided - $Path = (Join-Path -Path $OutputDirectory -ChildPath $FileName) + $Path = (Join-Path $OutputDirectory $FileName) } # Set Content $File | Set-Content -Path $Path From 7b6774f0b72b131693aaf3d5812e60b4df69c08e Mon Sep 17 00:00:00 2001 From: MrMCake Date: Sun, 7 Aug 2022 21:09:10 +0200 Subject: [PATCH 3/4] Update to latest --- .../pipelines/tokensReplacement/helper/Convert-TokenInFile.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utilities/pipelines/tokensReplacement/helper/Convert-TokenInFile.ps1 b/utilities/pipelines/tokensReplacement/helper/Convert-TokenInFile.ps1 index 7e6a5dc98c..0491a78f0c 100644 --- a/utilities/pipelines/tokensReplacement/helper/Convert-TokenInFile.ps1 +++ b/utilities/pipelines/tokensReplacement/helper/Convert-TokenInFile.ps1 @@ -81,7 +81,7 @@ function Convert-TokenInFile { # Set Content if ($OutputDirectory -and (Test-Path -Path $OutputDirectory -PathType Container)) { # If Specific Output Directory Provided - $Path = (Join-Path $OutputDirectory $FileName) + $Path = Join-Path $OutputDirectory $FileName } # Set Content $File | Set-Content -Path $Path From cc888b54759e7ba44a7d8018c61f79c049222fbd Mon Sep 17 00:00:00 2001 From: MrMCake Date: Wed, 17 Aug 2022 09:32:07 +0200 Subject: [PATCH 4/4] Update to latest --- utilities/tools/Test-ModuleLocally.ps1 | 8 -------- 1 file changed, 8 deletions(-) diff --git a/utilities/tools/Test-ModuleLocally.ps1 b/utilities/tools/Test-ModuleLocally.ps1 index 962a59b3a7..4425705df8 100644 --- a/utilities/tools/Test-ModuleLocally.ps1 +++ b/utilities/tools/Test-ModuleLocally.ps1 @@ -229,14 +229,6 @@ function Test-ModuleLocally { if (($ValidationTest -or $DeploymentTest) -and $ValidateOrDeployParameters) { - # Find Test Parameter Files - # ------------------------- - if ((Get-Item -Path $testFilePath) -is [System.IO.DirectoryInfo]) { - $moduleTestFiles = (Get-ChildItem -Path $testFilePath).FullName - } else { - $moduleTestFiles = @($testFilePath) - } - # Invoke Token Replacement Functionality and Convert Tokens in Parameter Files $null = Convert-TokensInFileList @tokenConfiguration