From 11429c4fc690abf8e018b29ad4627d5a82945a06 Mon Sep 17 00:00:00 2001 From: Marius Date: Fri, 28 Jan 2022 17:23:04 +0100 Subject: [PATCH 1/3] Dont replace on workflow or pipeline files if they do not exist --- utilities/tools/ConvertTo-ARMTemplate.ps1 | 40 +++++++++++++---------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/utilities/tools/ConvertTo-ARMTemplate.ps1 b/utilities/tools/ConvertTo-ARMTemplate.ps1 index bfc5ee75a3..ede9df4619 100644 --- a/utilities/tools/ConvertTo-ARMTemplate.ps1 +++ b/utilities/tools/ConvertTo-ARMTemplate.ps1 @@ -173,29 +173,33 @@ if (-not $SkipPipelineUpdate) { # GitHub workflow files $ghWorkflowFolderPath = Join-Path -Path $rootPath -ChildPath '.github\workflows' - $ghWorkflowFilesToUpdate = Get-ChildItem -Path $ghWorkflowFolderPath -Filter 'ms.*.yml' -File -Force - Write-Verbose ('Update workflow files - Processing [{0}] file(s)' -f $ghWorkflowFilesToUpdate.count) - if ($PSCmdlet.ShouldProcess(('[{0}] ms.*.yml file(s) in path [{1}]' -f $ghWorkflowFilesToUpdate.Count, $ghWorkflowFolderPath), 'Set-Content')) { - # parallelism is not supported on GitHub runners - #$ghWorkflowFilesToUpdate | ForEach-Object -ThrottleLimit $env:NUMBER_OF_PROCESSORS -Parallel { - $ghWorkflowFilesToUpdate | ForEach-Object { - $content = $_ | Get-Content - $content = $content -replace 'templateFilePath:(.*).bicep', 'templateFilePath:$1.json' - $_ | Set-Content -Value $content + 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) + if ($PSCmdlet.ShouldProcess(('[{0}] ms.*.yml file(s) in path [{1}]' -f $ghWorkflowFilesToUpdate.Count, $ghWorkflowFolderPath), 'Set-Content')) { + # parallelism is not supported on GitHub runners + #$ghWorkflowFilesToUpdate | ForEach-Object -ThrottleLimit $env:NUMBER_OF_PROCESSORS -Parallel { + $ghWorkflowFilesToUpdate | ForEach-Object { + $content = $_ | Get-Content + $content = $content -replace 'templateFilePath:(.*).bicep', 'templateFilePath:$1.json' + $_ | Set-Content -Value $content + } } } # Azure DevOps Pipelines $adoPipelineFolderPath = Join-Path -Path $rootPath -ChildPath '.azuredevops\modulePipelines' - $adoPipelineFilesToUpdate = Get-ChildItem -Path $adoPipelineFolderPath -Filter 'ms.*.yml' -File -Force - Write-Verbose ('Update Azure DevOps pipeline files - Processing [{0}] file(s)' -f $adoPipelineFilesToUpdate.count) - if ($PSCmdlet.ShouldProcess(('[{0}] ms.*.yml file(s) in path [{1}]' -f $adoPipelineFilesToUpdate.Count, $adoPipelineFolderPath), 'Set-Content')) { - # parallelism is not supported on GitHub runners - #$adoPipelineFilesToUpdate | ForEach-Object -ThrottleLimit $env:NUMBER_OF_PROCESSORS -Parallel { - $adoPipelineFilesToUpdate | ForEach-Object { - $content = $_ | Get-Content - $content = $content -replace 'templateFilePath:(.*).bicep', 'templateFilePath:$1.json' - $_ | Set-Content -Value $content + 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) + if ($PSCmdlet.ShouldProcess(('[{0}] ms.*.yml file(s) in path [{1}]' -f $adoPipelineFilesToUpdate.Count, $adoPipelineFolderPath), 'Set-Content')) { + # parallelism is not supported on GitHub runners + #$adoPipelineFilesToUpdate | ForEach-Object -ThrottleLimit $env:NUMBER_OF_PROCESSORS -Parallel { + $adoPipelineFilesToUpdate | ForEach-Object { + $content = $_ | Get-Content + $content = $content -replace 'templateFilePath:(.*).bicep', 'templateFilePath:$1.json' + $_ | Set-Content -Value $content + } } } From 88ccec9e23f580b5ad7b43102eb08b76fa2a0301 Mon Sep 17 00:00:00 2001 From: Marius Date: Fri, 28 Jan 2022 18:07:17 +0100 Subject: [PATCH 2/3] Only pre-clean deploy.json when bicep exists. --- utilities/tools/ConvertTo-ARMTemplate.ps1 | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/utilities/tools/ConvertTo-ARMTemplate.ps1 b/utilities/tools/ConvertTo-ARMTemplate.ps1 index ede9df4619..f9375588ba 100644 --- a/utilities/tools/ConvertTo-ARMTemplate.ps1 +++ b/utilities/tools/ConvertTo-ARMTemplate.ps1 @@ -66,13 +66,22 @@ if ($ConvertChildren) { #region Remove existing deploy.json files Write-Verbose 'Remove existing deploy.json files' -$JsonFilesToRemove = Get-ChildItem -Path $armFolderPath -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 [$armFolderPath]", 'Remove-Item')) { - $JsonFilesToRemove | Remove-Item -Force + +# Use case: New module is brought in and needs to be converted to json + +# Suggestion: Skip JSON +# Suggestion: Provide path on the script on what to convert +# Suggestion: Only remove if bicep exists + +if (Test-Path -Path (Join-Path -Path $armFolderPath -ChildPath 'deploy.bicep')) { + $JsonFilesToRemove = Get-ChildItem -Path $armFolderPath -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 [$armFolderPath]", 'Remove-Item')) { + $JsonFilesToRemove | Remove-Item -Force + } + Write-Verbose 'Remove existing deploy.json files - Done' } -Write-Verbose 'Remove existing deploy.json files - Done' #endregion #region Convert bicep files to json From 1016e0eba209bdf687a80d54700a0b9667041e3c Mon Sep 17 00:00:00 2001 From: Marius Date: Fri, 28 Jan 2022 18:38:30 +0100 Subject: [PATCH 3/3] cleanup --- utilities/tools/ConvertTo-ARMTemplate.ps1 | 7 ------- 1 file changed, 7 deletions(-) diff --git a/utilities/tools/ConvertTo-ARMTemplate.ps1 b/utilities/tools/ConvertTo-ARMTemplate.ps1 index f9375588ba..ed3150bef3 100644 --- a/utilities/tools/ConvertTo-ARMTemplate.ps1 +++ b/utilities/tools/ConvertTo-ARMTemplate.ps1 @@ -66,13 +66,6 @@ if ($ConvertChildren) { #region Remove existing deploy.json files Write-Verbose 'Remove existing deploy.json files' - -# Use case: New module is brought in and needs to be converted to json - -# Suggestion: Skip JSON -# Suggestion: Provide path on the script on what to convert -# Suggestion: Only remove if bicep exists - if (Test-Path -Path (Join-Path -Path $armFolderPath -ChildPath 'deploy.bicep')) { $JsonFilesToRemove = Get-ChildItem -Path $armFolderPath -Filter 'deploy.json' -Recurse -Force -File Write-Verbose "Remove existing deploy.json files - Remove [$($JsonFilesToRemove.count)] file(s)"