Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2e12c4c
Added initial script
AlexanderSehr Dec 21, 2021
22f031b
Update to latest
AlexanderSehr Dec 21, 2021
fbf9a66
Optimized files
AlexanderSehr Dec 21, 2021
829cebb
Update to latest
AlexanderSehr Dec 21, 2021
184db0f
Update to latest
AlexanderSehr Dec 21, 2021
622ff5b
Update to latest
AlexanderSehr Dec 21, 2021
be2bd87
Merge branch 'users/rahalan/TestConversionScript' into users/rahalan/…
AlexanderSehr Dec 21, 2021
5523158
Update to latest
AlexanderSehr Dec 21, 2021
720301d
Update to latest
AlexanderSehr Dec 21, 2021
a48f4aa
Update to latest
AlexanderSehr Dec 21, 2021
2b4f62d
Update to latest
AlexanderSehr Dec 21, 2021
3f95f60
Update to latest
AlexanderSehr Dec 21, 2021
4f55426
Update to latest
AlexanderSehr Dec 21, 2021
0c0e818
Update to latest
AlexanderSehr Dec 21, 2021
41eb851
Update to latest
AlexanderSehr Dec 21, 2021
36c3673
Update to latest
AlexanderSehr Dec 21, 2021
6d5ddb8
Update to latest
AlexanderSehr Dec 21, 2021
41d9842
Update to latest
AlexanderSehr Dec 21, 2021
70c4967
Update to latest
AlexanderSehr Dec 21, 2021
8c335f5
Update to latest
AlexanderSehr Dec 21, 2021
5668d42
Update to latest
AlexanderSehr Dec 21, 2021
ab5973c
Path & Match fixes
AlexanderSehr Dec 21, 2021
0e9520f
Updated tests
AlexanderSehr Dec 21, 2021
56f7785
Update to latest
AlexanderSehr Dec 21, 2021
ce17743
Minor change
AlexanderSehr Dec 21, 2021
1cedb95
Extended replacement
AlexanderSehr Dec 21, 2021
953a5fa
Extended replacement
AlexanderSehr Dec 21, 2021
8993ae4
Updated trigger
AlexanderSehr Dec 21, 2021
c09788e
Update to latest
AlexanderSehr Dec 21, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 30 additions & 56 deletions .github/workflows/platform.convertToArmTemplate.tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,68 +9,42 @@ on:
- 'utilities/tools/tests/ConvertTo-ARMTemplate**'

jobs:
job_test_Default:
runs-on: windows-latest
name: 'Run test for default parameter'
job_test_convert:
runs-on: ubuntu-latest
name: 'Test with parameter'
strategy:
fail-fast: false
matrix:
tags: ['Default', 'ConvertChildren', 'Skip']
steps:
- name: 'Checkout'
uses: actions/checkout@v2
with:
fetch-depth: 0
token: '${{ secrets.PLATFORM_REPO_UPDATE_PAT }}' # Sets general GIT credentials up
- name: 'Run Pester tests'
shell: pwsh
run: |
Invoke-Pester -Path ./utilities/tools/tests/ConvertTo-ARMTemplate-Default.Tests.ps1 -Verbose
job_test_ConvertChildren:
runs-on: windows-latest
name: 'Run test for -ConvertChildren parameter'
steps:
- name: 'Checkout'
uses: actions/checkout@v2
with:
fetch-depth: 0
token: '${{ secrets.PLATFORM_REPO_UPDATE_PAT }}' # Sets general GIT credentials up
- name: 'Run Pester tests'
shell: pwsh
run: |
Invoke-Pester -Path ./utilities/tools/tests/ConvertTo-ARMTemplate-ConvertChildren.Tests.ps1 -Verbose
job_test_SkipMetadataCleanup:
runs-on: windows-latest
name: 'Run test for -SkipMetadataCleanup parameter'
steps:
- name: 'Checkout'
uses: actions/checkout@v2
Invoke-Pester -Configuration @{
Run = @{
Path = @(
Join-Path "$env:GITHUB_WORKSPACE" 'utilities' 'tools' 'tests' 'ConvertTo-ARMTemplate.Tests.ps1'
)
}
Filter = @{
Tag = '${{ matrix.tags }}'
}
TestResult = @{
TestSuiteName = 'Conversion Tests'
OutputPath = Join-Path "$env:GITHUB_WORKSPACE" 'utilities' 'tools' 'tests' 'conversion-testResults-${{ matrix.tags }}.xml'
OutputFormat = 'JUnitXml'
Enabled = $true
}
Output = @{
Verbosity = 'Detailed'
}
}
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
if: always()
with:
fetch-depth: 0
token: '${{ secrets.PLATFORM_REPO_UPDATE_PAT }}' # Sets general GIT credentials up
- name: 'Run Pester tests'
shell: pwsh
run: |
Invoke-Pester -Path ./utilities/tools/tests/ConvertTo-ARMTemplate-SkipMetadataCleanup.Tests.ps1 -Verbose
job_test_SkipBicepCleanUp:
runs-on: windows-latest
name: 'Run test for -SkipBicepCleanUp parameter'
steps:
- name: 'Checkout'
uses: actions/checkout@v2
with:
fetch-depth: 0
token: '${{ secrets.PLATFORM_REPO_UPDATE_PAT }}' # Sets general GIT credentials up
- name: 'Run Pester tests'
shell: pwsh
run: |
Invoke-Pester -Path ./utilities/tools/tests/ConvertTo-ARMTemplate-SkipBicepCleanUp.Tests.ps1 -Verbose
job_test_SkipWorkflowUpdate:
runs-on: windows-latest
name: 'Run test for -SkipWorkflowUpdate parameter'
steps:
- name: 'Checkout'
uses: actions/checkout@v2
with:
fetch-depth: 0
token: '${{ secrets.PLATFORM_REPO_UPDATE_PAT }}' # Sets general GIT credentials up
- name: 'Run Pester tests'
shell: pwsh
run: |
Invoke-Pester -Path ./utilities/tools/tests/ConvertTo-ARMTemplate-SkipWorkflowUpdate.Tests.ps1 -Verbose
files: 'utilities/tools/tests/conversion-testResults-${{ matrix.tags }}.xml'
45 changes: 30 additions & 15 deletions utilities/tools/ConvertTo-ARMTemplate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Optional. Skip Cleanup of Bicep metadata from json files
.PARAMETER SkipBicepCleanUp
Optional. Skip removal of bicep files and folders

.PARAMETER SkipWorkflowUpdate
.PARAMETER SkipPipelineUpdate
Optional. Skip replacing .bicep with .json in workflow files

.EXAMPLE
Expand All @@ -32,7 +32,7 @@ Optional. Skip replacing .bicep with .json in workflow files
Converts top level bicep modules to json-based ARM template, cleaning up all bicep files and folders and updating the workflow files to use the json files.

.EXAMPLE
. .\utilities\tools\ConvertTo-ARMTemplate.ps1 -ConvertChildren -SkipMetadataCleanup -SkipBicepCleanUp -SkipWorkflowUpdate
. .\utilities\tools\ConvertTo-ARMTemplate.ps1 -ConvertChildren -SkipMetadataCleanup -SkipBicepCleanUp -SkipPipelineUpdate

Only converts top level bicep modules to json based ARM template, keeping metadata in json, keeping all bicep files and folders, and not updating workflows.

Expand All @@ -52,7 +52,7 @@ param (
[switch] $SkipBicepCleanUp,

[Parameter(Mandatory = $false)]
[switch] $SkipWorkflowUpdate
[switch] $SkipPipelineUpdate
)

$rootPath = Get-Item -Path $Path | Select-Object -ExpandProperty 'FullName'
Expand Down Expand Up @@ -83,7 +83,7 @@ if ($PSCmdlet.ShouldProcess("[$($BicepFilesToConvert.count)] deploy.bicep file(s
# parallelism is not supported on GitHub runners
#$BicepFilesToConvert | ForEach-Object -ThrottleLimit $env:NUMBER_OF_PROCESSORS -Parallel {
$BicepFilesToConvert | ForEach-Object {
Invoke-Expression -Command "az bicep build --file '$_'"
az bicep build --file $_
}
}

Expand Down Expand Up @@ -167,23 +167,38 @@ if (-not $SkipBicepCleanUp) {
}
#endregion

#region Update workflow files - Replace .bicep with .json in workflow files
if (-not $SkipWorkflowUpdate) {
Write-Verbose 'Update workflow files'
#region Update pipeline files - Replace .bicep with .json in workflow files
if (-not $SkipPipelineUpdate) {
Write-Verbose 'Update pipeline files'

$workflowFolderPath = Join-Path -Path $rootPath -ChildPath '.github\workflows'
$workflowFilesToUpdate = Get-ChildItem -Path $workflowFolderPath -Filter 'ms.*.yml' -File -Force
Write-Verbose "Update workflow files - Processing [$($workflowFilesToUpdate.count)] file(s)"
if ($PSCmdlet.ShouldProcess("[$($workflowFilesToUpdate.count)] ms.*.yml file(s) in path [$armFolderPath]", 'Set-Content')) {
# 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
#$workflowFilesToUpdate | ForEach-Object -ThrottleLimit $env:NUMBER_OF_PROCESSORS -Parallel {
$workflowFilesToUpdate | ForEach-Object {
#$ghWorkflowFilesToUpdate | ForEach-Object -ThrottleLimit $env:NUMBER_OF_PROCESSORS -Parallel {
$ghWorkflowFilesToUpdate | ForEach-Object {
$content = $_ | Get-Content
$content = $content.Replace('deploy.bicep', 'deploy.json')
$content = $content -replace 'templateFilePath:(.*).bicep', 'templateFilePath:$1.json'
$_ | Set-Content -Value $content
}
}

Write-Verbose 'Update workflow files - Done'
# 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
}
}

Write-Verbose 'Update pipeline files - Done'
}
#endregion

This file was deleted.

80 changes: 0 additions & 80 deletions utilities/tools/tests/ConvertTo-ARMTemplate-Default.Tests.ps1

This file was deleted.

Loading