From b229bb20dbb619bb1913911029153208c7573be8 Mon Sep 17 00:00:00 2001 From: Margarita Sanz Date: Wed, 2 Mar 2022 09:16:47 +0100 Subject: [PATCH 1/4] ADO wiki updated --- .../platform.updateReadMe.yml | 118 +++++++++--------- utilities/tools/Set-ReadMeModuleTable.ps1 | 90 +++++++++++++ .../helper/Get-ModulesAsMarkdownTable.ps1 | 89 ++++++++++--- 3 files changed, 225 insertions(+), 72 deletions(-) create mode 100644 utilities/tools/Set-ReadMeModuleTable.ps1 diff --git a/.azuredevops/platformPipelines/platform.updateReadMe.yml b/.azuredevops/platformPipelines/platform.updateReadMe.yml index 1d62c35b57..3fa45466b1 100644 --- a/.azuredevops/platformPipelines/platform.updateReadMe.yml +++ b/.azuredevops/platformPipelines/platform.updateReadMe.yml @@ -20,65 +20,71 @@ variables: jobs: - job: Update_module_tables pool: - ${{ if ne($(vmImage), '') }}: - vmImage: '$(vmImage)' - ${{ if ne($(poolName), '') }}: - name: '$(poolName)' - steps: - - checkout: self - persistCredentials: true - - task: PowerShell@2 - displayName: 'Update general ReadMe' - inputs: - targetType: inline - pwsh: true - script: | - # Load used functions - . (Join-Path '$(System.DefaultWorkingDirectory)' 'utilities' 'tools' 'Set-GitHubReadMeModuleTable.ps1') + ${{ if ne(variables.vmImage, '') }}: + vmImage: ${{ variables.vmImage }} + ${{ if ne(variables.poolName, '') }}: + name: ${{ variables.poolName }} + steps: + - checkout: self + persistCredentials: true + - task: PowerShell@2 + displayName: 'Update general ReadMe' + inputs: + targetType: inline + pwsh: true + script: | + # Load used functions + . (Join-Path '$(System.DefaultWorkingDirectory)' 'utilities' 'tools' 'Set-ReadMeModuleTable.ps1') - $functionInput = @{ - ModulesPath = Join-Path '$(System.DefaultWorkingDirectory)' 'arm' - FilePath = Join-Path '$(System.DefaultWorkingDirectory)' 'README.md' - Organization = ('$(Build.Repository.Name)').split('/')[0] - RepositoryName = ('$(Build.Repository.Name)').split('/')[1] - ColumnsInOrder = @('Name', 'Status') - SortByColumn = 'Name' - } + $OrganizationURI = '$(System.CollectionUri)' - Write-Verbose "Invoke task with" -Verbose - Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose + $functionInput = @{ + ModulesPath = Join-Path '$(System.DefaultWorkingDirectory)' 'arm' + FilePath = Join-Path '$(System.DefaultWorkingDirectory)' 'README.md' + Organization = $OrganizationURI.Split('/')[3] + RepositoryName = $(Build.Repository.Name) + ColumnsInOrder = @('Name', 'Status') + SortByColumn = 'Name' + ADO = $true + ProjectName = '$(System.TeamProject)' + } - Set-GitHubReadMeModuleTable @functionInput -Verbose - - task: PowerShell@2 - displayName: 'Update module folder ReadMe' - inputs: - targetType: inline - pwsh: true - script: | - # Load used functions - . (Join-Path '$(System.DefaultWorkingDirectory)' 'utilities' 'tools' 'Set-GitHubReadMeModuleTable.ps1') + Write-Verbose "Invoke task with" -Verbose + Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose - $functionInput = @{ - ModulesPath = Join-Path '$(System.DefaultWorkingDirectory)' 'arm' - FilePath = Join-Path '$(System.DefaultWorkingDirectory)' 'arm/README.md' - Organization = ('$(Build.Repository.Name)').split('/')[0] - RepositoryName = ('$(Build.Repository.Name)').split('/')[1] - ColumnsInOrder = @('Name', 'ProviderNamespace','ResourceType') - } + Set-ReadMeModuleTable @functionInput -Verbose + - task: PowerShell@2 + displayName: 'Update module folder ReadMe' + inputs: + targetType: inline + pwsh: true + script: | + # Load used functions + . (Join-Path '$(System.DefaultWorkingDirectory)' 'utilities' 'tools' 'Set-ReadMeModuleTable.ps1') - Write-Verbose "Invoke task with" -Verbose - Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose + $functionInput = @{ + ModulesPath = Join-Path '$(System.DefaultWorkingDirectory)' 'arm' + FilePath = Join-Path '$(System.DefaultWorkingDirectory)' 'arm/README.md' + Organization = $OrganizationURI.Split('/')[3] + RepositoryName = $(Build.Repository.Name) + ColumnsInOrder = @('Name', 'ProviderNamespace','ResourceType') + ADO = $true + ProjectName = '$(System.TeamProject)' + } - Set-GitHubReadMeModuleTable @functionInput -Verbose - - task: PowerShell@2 - displayName: 'Push changes' - inputs: - targetType: inline - pwsh: true - script: | - git config --global user.email '$(pipelinePrincipalGitUserEmail)' - git config --global user.name '$(pipelinePrincipalGitUserName)' - Write-Verbose '$(Build.SourceBranch)' -Verbose - git add . - git commit -m "Push updated Readme file(s)" - git push $(Build.Repository.Uri) HEAD:$(Build.SourceBranch) + Write-Verbose "Invoke task with" -Verbose + Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose + + Set-ReadMeModuleTable @functionInput -Verbose + - task: PowerShell@2 + displayName: 'Push changes' + inputs: + targetType: inline + pwsh: true + script: | + git config --global user.email '$(pipelinePrincipalGitUserEmail)' + git config --global user.name '$(pipelinePrincipalGitUserName)' + Write-Verbose '$(Build.SourceBranch)' -Verbose + git add . + git commit -m "Push updated Readme file(s)" + git push $(Build.Repository.Uri) HEAD:$(Build.SourceBranch) diff --git a/utilities/tools/Set-ReadMeModuleTable.ps1 b/utilities/tools/Set-ReadMeModuleTable.ps1 new file mode 100644 index 0000000000..89c8bf1a32 --- /dev/null +++ b/utilities/tools/Set-ReadMeModuleTable.ps1 @@ -0,0 +1,90 @@ +#region Helper functions + +<# +.SYNOPSIS +Update the given ReadMe file with the latest module table + +.DESCRIPTION +Update the given ReadMe file with the latest module table. +You can specify the columns to be generated. + +.PARAMETER FilePath +Mandatory. The path to the ReadMe file to update + +.PARAMETER ModulesPath +Mandatory. The path to the modules folder to process + +.PARAMETER RepositoryName +Mandatory. The name of the repository the modules are in (required to generate the correct links) + +.PARAMETER Organization +Mandatory. The name of the Organization the modules are in (required to generate the correct links) + +.PARAMETER ColumnsInOrder +Mandatory. The set of columns to add to the table in the order you expect them in the table. +Available are 'Name', 'ProviderNamespace', 'ResourceType', 'TemplateType', 'Deploy' & 'Status' + +.EXAMPLE +Set-ReadMeModuleTable -FilePath 'C:\readme.md' -ModulesPath 'C:\arm' -RepositoryName 'ResourceModules' -Organization 'Azure' -ColumnsInOrder @('Name','Status') + +Update the defined table section in the 'readme.md' file with a table that has the columns 'Name' & 'Status' +#> +function Set-ReadMeModuleTable { + + [CmdletBinding(SupportsShouldProcess)] + param ( + [Parameter(Mandatory = $false)] + [string] $FilePath = 'C:\Users\masanzde\Documents\IACs\Azure\ResourceModules\README.md', + + [Parameter(Mandatory = $false)] + [string] $ModulesPath = 'C:\Users\masanzde\Documents\IACs\Azure\ResourceModules\arm', + + [Parameter(Mandatory = $false)] + [string] $RepositoryName = 'ResourceModules', + + [Parameter(Mandatory = $false)] + [string] $Organization = 'masanzde', + + [Parameter(Mandatory = $false)] + [ValidateSet('Name', 'ProviderNamespace', 'ResourceType', 'TemplateType', 'Deploy', 'Status')] + [string[]] $ColumnsInOrder = @('Name', 'ProviderNamespace', 'ResourceType'), + + [Parameter(Mandatory = $false)] + [string] $SortByColumn = 'ProviderNamespace', + + [Parameter(ParameterSetName = 'AzureDevOps', Mandatory = $false)] + [switch]$ADO = $false, + + [Parameter(ParameterSetName = 'AzureDevOps', Mandatory = $false)] + [string]$ProjectName = '' + ) + + # Load external functions + . (Join-Path $PSScriptRoot 'helper/Get-ModulesAsMarkdownTable.ps1') + . (Join-Path $PSScriptRoot 'helper/Merge-FileWithNewContent.ps1') + + # Logic + $contentArray = Get-Content -Path $FilePath + + $tableStringInputObject = @{ + Path = $ModulesPath + RepositoryName = $RepositoryName + Organization = $Organization + ColumnsInOrder = $ColumnsInOrder + SortByColumn = $SortByColumn + ADO = $ADO + ProjectName = $ProjectName + } + $tableString = Get-ModulesAsMarkdownTable @tableStringInputObject + + $newContent = Merge-FileWithNewContent -oldContent $contentArray -newContent $tableString -sectionStartIdentifier '## Available Resource Modules' -contentType 'table' + + Write-Verbose 'New content:' + Write-Verbose '============' + Write-Verbose ($newContent | Out-String) + + if ($PSCmdlet.ShouldProcess("File in path [$FilePath]", 'Overwrite')) { + Set-Content -Path $FilePath -Value $newContent -Force + Write-Verbose "File [$FilePath] updated" -Verbose + } +} diff --git a/utilities/tools/helper/Get-ModulesAsMarkdownTable.ps1 b/utilities/tools/helper/Get-ModulesAsMarkdownTable.ps1 index 16ce236c75..9ac462db4e 100644 --- a/utilities/tools/helper/Get-ModulesAsMarkdownTable.ps1 +++ b/utilities/tools/helper/Get-ModulesAsMarkdownTable.ps1 @@ -38,19 +38,34 @@ function Get-PipelineStatusUrl { [string] $RepositoryName, [Parameter(Mandatory)] - [string] $Organization - ) + [string] $Organization, - $shortProvider = $provider.Replace('Microsoft.', 'MS.') - $pipelineFileName = ('{0}.{1}.yml' -f $shortProvider, $name).Replace('\', '/').Replace('/', '.').ToLower() - $pipelineFileUri = ".github/workflows/$pipelineFileName" + [Parameter(ParameterSetName = 'AzureDevOps', Mandatory = $false)] + [switch]$ADO, - $pipelineName = (Get-Content -Path $pipelineFileUri)[0].TrimStart('name:').Replace('"', '').Trim() + [Parameter(ParameterSetName = 'AzureDevOps', Mandatory = $true)] + [string]$ProjectName + ) - $pipelineFileGitUri = 'https://github.com/{0}/{1}/actions/workflows/{2}' -f $Organization, $RepositoryName, $pipelineFileName - # Note: Badge name is automatically the pipeline name - return ('[![{0}]({1}/badge.svg)]({1})' -f $pipelineName, $pipelineFileGitUri).Replace('\', '/') + $shortProvider = $provider.Replace('Microsoft.', 'MS.') + $pipelineFileName = ('{0}.{1}.yml' -f $shortProvider, $name).Replace('\', '/').Replace('/', '.').ToLower() + switch ($ADO) { + $true { + $pipelineFileUri = ".azuredevops/modulePipelines/$pipelineFileName" + $pipelineName = (Get-Content -Path $pipelineFileUri)[0].TrimStart('name:').Replace('"', '').Trim() + $pipelineFileGitUri = 'https://dev.azure.com/{0}/{1}/_apis/build/status/{2}?branchName=main' -f $Organization, $Projectname, $pipelineName + # Note: Badge name is automatically the pipeline name + return ('[![{0}]({1})]({1})' -f $pipelineName, $pipelineFileGitUri).Replace('\', '/') + } + Default { + $pipelineFileUri = ".github/workflows/$pipelineFileName" + $pipelineName = (Get-Content -Path $pipelineFileUri)[0].TrimStart('name:').Replace('"', '').Trim() + $pipelineFileGitUri = 'https://github.com/{0}/{1}/actions/workflows/{2}' -f $Organization, $RepositoryName, $pipelineFileName + # Note: Badge name is automatically the pipeline name + return ('[![{0}]({1}/badge.svg)]({1})' -f $pipelineName, $pipelineFileGitUri).Replace('\', '/') + } + } } <# @@ -294,7 +309,13 @@ function Get-ResolvedSubServiceRow { [string] $RepositoryName, [Parameter(Mandatory = $true)] - [string] $Organization + [string] $Organization, + + [Parameter(ParameterSetName = 'AzureDevOps', Mandatory = $false)] + [switch]$ADO, + + [Parameter(ParameterSetName = 'AzureDevOps', Mandatory = $true)] + [string]$ProjectName ) $rawSubFolders = Get-ChildItem -Path $subPath -Directory -Recurse -Exclude @('.bicep', '.parameters') -Force @@ -312,7 +333,15 @@ function Get-ResolvedSubServiceRow { foreach ($column in $ColumnsInOrder) { switch ($column) { 'Name' { - $row['Name'] = ('[{0}](https://github.com/{1}/{2}/tree/main/arm/{3})' -f (Get-ResourceModuleName -path $subfolder), $Organization, $RepositoryName, $relativePath.Replace('\', '/')) + switch ($ADO) { + $true { + $row['Name'] = ('[{0}](https://dev.azure.com/{1}/{2}/_git/{3}?path=/arm/{4})' -f (Get-ResourceModuleName -path $subfolder), $Organization, $ProjectName, $RepositoryName, $relativePath.Replace('\', '/')) + } + Default { + $row['Name'] = ('[{0}](https://github.com/{1}/{2}/tree/main/arm/{3})' -f (Get-ResourceModuleName -path $subfolder), $Organization, $RepositoryName, $relativePath.Replace('\', '/')) + } + } + } 'ProviderNamespace' { # If we don't sort by provider, we have to add the provider to each row to ensure readability of each row @@ -329,7 +358,15 @@ function Get-ResolvedSubServiceRow { } } 'ResourceType' { - $row['ResourceType'] = ('[{0}](https://github.com/{1}/{2}/tree/main/arm/{3})' -f $subName, $Organization, $RepositoryName, $relativePath.Replace('\', '/')) + switch ($ADO) { + $true { + $row['ResourceType'] = ('[{0}](https://dev.azure.com/{1}/{2}/_git/{3}?path=/arm/{4})' -f $subName, $Organization, $ProjectName, $RepositoryName, $relativePath.Replace('\', '/')) + } + Default { + $row['ResourceType'] = ('[{0}](https://github.com/{1}/{2}/tree/main/arm/{3})' -f $subName, $Organization, $RepositoryName, $relativePath.Replace('\', '/')) + } + } + } 'TemplateType' { @@ -432,7 +469,13 @@ function Get-ModulesAsMarkdownTable { [string] $RepositoryName, [Parameter(Mandatory = $true)] - [string] $Organization + [string] $Organization, + + [Parameter(ParameterSetName = 'AzureDevOps', Mandatory = $false)] + [switch]$ADO, + + [Parameter(ParameterSetName = 'AzureDevOps', Mandatory = $true)] + [string]$ProjectName ) # Header @@ -488,11 +531,17 @@ function Get-ModulesAsMarkdownTable { $output = Get-ResolvedSubServiceRow @recursiveSubServiceInputObject } else { $row = @{} - foreach ($column in $ColumnsInOrder) { switch ($column) { 'Name' { - $row['Name'] = ('[{0}](https://github.com/{1}/{2}/tree/main/arm/{3})' -f (Get-ResourceModuleName -path $containedFolder), $Organization, $RepositoryName, $concatedBase.Replace('\', '/')) + switch ($ADO) { + $true { + $row['Name'] = ('[{0}](https://dev.azure.com/{1}/{2}/_git/{3}?path=/arm/{4})' -f (Get-ResourceModuleName -path $containedFolder), $Organization, $ProjectName, $RepositoryName, $concatedBase.Replace('\', '/')) + } + Default { + $row['Name'] = ('[{0}](https://github.com/{1}/{2}/tree/main/arm/{3})' -f (Get-ResourceModuleName -path $containedFolder), $Organization, $RepositoryName, $concatedBase.Replace('\', '/')) + } + } } 'ProviderNamespace' { if ($previousProvider -eq $provider -and $SortByColumn -ne 'Name') { @@ -509,7 +558,15 @@ function Get-ModulesAsMarkdownTable { } } 'ResourceType' { - $row['ResourceType'] += ('[{0}](https://github.com/{1}/{2}/tree/main/arm/{3})' -f $containedFolderName, $Organization, $RepositoryName, $concatedBase.Replace('\', '/')) + switch ($ADO) { + $true { + $row['ResourceType'] = ('[{0}](https://dev.azure.com/{1}/{2}/_git/{3}?path=/arm/{4})' -f (Get-ResourceModuleName -path $containedFolder), $Organization, $ProjectName, $RepositoryName, $concatedBase.Replace('\', '/')) + } + Default { + $row['ResourceType'] += ('[{0}](https://github.com/{1}/{2}/tree/main/arm/{3})' -f $containedFolderName, $Organization, $RepositoryName, $concatedBase.Replace('\', '/')) + } + } + } 'TemplateType' { $row['TemplateType'] += Get-TypeColumnString -path $containedFolder From f135557e90b98a172a89b72f8ae63a8c96537624 Mon Sep 17 00:00:00 2001 From: Margarita Sanz Date: Wed, 2 Mar 2022 11:06:08 +0100 Subject: [PATCH 2/4] updated GitHub and ADO pipelines --- .../platform.updateReadMe.yml | 114 +++++++++--------- .github/workflows/platform.updateReadMe.yml | 10 +- .../UtilitiesSetGitHubReadMeModuleTable.md | 2 +- .../tools/Set-GitHubReadMeModuleTable.ps1 | 82 ------------- utilities/tools/Set-ReadMeModuleTable.ps1 | 12 +- .../helper/Get-ModulesAsMarkdownTable.ps1 | 64 +++++----- 6 files changed, 106 insertions(+), 178 deletions(-) delete mode 100644 utilities/tools/Set-GitHubReadMeModuleTable.ps1 diff --git a/.azuredevops/platformPipelines/platform.updateReadMe.yml b/.azuredevops/platformPipelines/platform.updateReadMe.yml index 3fa45466b1..939b0081ee 100644 --- a/.azuredevops/platformPipelines/platform.updateReadMe.yml +++ b/.azuredevops/platformPipelines/platform.updateReadMe.yml @@ -24,67 +24,67 @@ jobs: vmImage: ${{ variables.vmImage }} ${{ if ne(variables.poolName, '') }}: name: ${{ variables.poolName }} - steps: - - checkout: self - persistCredentials: true - - task: PowerShell@2 - displayName: 'Update general ReadMe' - inputs: - targetType: inline - pwsh: true - script: | - # Load used functions - . (Join-Path '$(System.DefaultWorkingDirectory)' 'utilities' 'tools' 'Set-ReadMeModuleTable.ps1') + steps: + - checkout: self + persistCredentials: true + - task: PowerShell@2 + displayName: 'Update general ReadMe' + inputs: + targetType: inline + pwsh: true + script: | + # Load used functions + . (Join-Path '$(System.DefaultWorkingDirectory)' 'utilities' 'tools' 'Set-ReadMeModuleTable.ps1') - $OrganizationURI = '$(System.CollectionUri)' + $OrganizationURI = '$(System.CollectionUri)' - $functionInput = @{ - ModulesPath = Join-Path '$(System.DefaultWorkingDirectory)' 'arm' - FilePath = Join-Path '$(System.DefaultWorkingDirectory)' 'README.md' - Organization = $OrganizationURI.Split('/')[3] - RepositoryName = $(Build.Repository.Name) - ColumnsInOrder = @('Name', 'Status') - SortByColumn = 'Name' - ADO = $true - ProjectName = '$(System.TeamProject)' - } + $functionInput = @{ + ModulesPath = Join-Path '$(System.DefaultWorkingDirectory)' 'arm' + FilePath = Join-Path '$(System.DefaultWorkingDirectory)' 'README.md' + Organization = $OrganizationURI.Split('/')[3] + RepositoryName = '$(Build.Repository.Name)' + ColumnsInOrder = @('Name', 'Status') + SortByColumn = 'Name' + Environment = 'ADO' + ProjectName = '$(System.TeamProject)' + } - Write-Verbose "Invoke task with" -Verbose - Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose + Write-Verbose "Invoke task with" -Verbose + Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose - Set-ReadMeModuleTable @functionInput -Verbose - - task: PowerShell@2 - displayName: 'Update module folder ReadMe' - inputs: - targetType: inline - pwsh: true - script: | - # Load used functions - . (Join-Path '$(System.DefaultWorkingDirectory)' 'utilities' 'tools' 'Set-ReadMeModuleTable.ps1') + Set-ReadMeModuleTable @functionInput -Verbose + - task: PowerShell@2 + displayName: 'Update module folder ReadMe' + inputs: + targetType: inline + pwsh: true + script: | + # Load used functions + . (Join-Path '$(System.DefaultWorkingDirectory)' 'utilities' 'tools' 'Set-ReadMeModuleTable.ps1') - $functionInput = @{ - ModulesPath = Join-Path '$(System.DefaultWorkingDirectory)' 'arm' - FilePath = Join-Path '$(System.DefaultWorkingDirectory)' 'arm/README.md' - Organization = $OrganizationURI.Split('/')[3] - RepositoryName = $(Build.Repository.Name) - ColumnsInOrder = @('Name', 'ProviderNamespace','ResourceType') - ADO = $true - ProjectName = '$(System.TeamProject)' - } + $functionInput = @{ + ModulesPath = Join-Path '$(System.DefaultWorkingDirectory)' 'arm' + FilePath = Join-Path '$(System.DefaultWorkingDirectory)' 'arm/README.md' + Organization = '$(System.CollectionUri)'.Split('/')[3] + RepositoryName = '$(Build.Repository.Name)' + ColumnsInOrder = @('Name', 'ProviderNamespace','ResourceType') + Environment = 'ADO' + ProjectName = '$(System.TeamProject)' + } - Write-Verbose "Invoke task with" -Verbose - Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose + Write-Verbose "Invoke task with" -Verbose + Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose - Set-ReadMeModuleTable @functionInput -Verbose - - task: PowerShell@2 - displayName: 'Push changes' - inputs: - targetType: inline - pwsh: true - script: | - git config --global user.email '$(pipelinePrincipalGitUserEmail)' - git config --global user.name '$(pipelinePrincipalGitUserName)' - Write-Verbose '$(Build.SourceBranch)' -Verbose - git add . - git commit -m "Push updated Readme file(s)" - git push $(Build.Repository.Uri) HEAD:$(Build.SourceBranch) + Set-ReadMeModuleTable @functionInput -Verbose + - task: PowerShell@2 + displayName: 'Push changes' + inputs: + targetType: inline + pwsh: true + script: | + git config --global user.email '$(pipelinePrincipalGitUserEmail)' + git config --global user.name '$(pipelinePrincipalGitUserName)' + Write-Verbose '$(Build.SourceBranch)' -Verbose + git add . + git commit -m "Push updated Readme file(s)" + git push $(Build.Repository.Uri) HEAD:$(Build.SourceBranch) diff --git a/.github/workflows/platform.updateReadMe.yml b/.github/workflows/platform.updateReadMe.yml index 25e71f3655..829dd17ae6 100644 --- a/.github/workflows/platform.updateReadMe.yml +++ b/.github/workflows/platform.updateReadMe.yml @@ -31,7 +31,7 @@ jobs: shell: pwsh run: | # Load used functions - . "$env:GITHUB_WORKSPACE/utilities/tools/Set-GitHubReadMeModuleTable.ps1" + . "$env:GITHUB_WORKSPACE/utilities/tools/Set-ReadMeModuleTable.ps1" $functionInput = @{ ModulesPath = Join-Path $env:GITHUB_WORKSPACE 'arm' @@ -40,18 +40,19 @@ jobs: RepositoryName = ($env:GITHUB_REPOSITORY).split('/')[1] ColumnsInOrder = @('Name', 'Status') SortByColumn = 'Name' + Environment = 'GitHub' } Write-Verbose "Invoke task with" -Verbose Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose - Set-GitHubReadMeModuleTable @functionInput -Verbose + Set-ReadMeModuleTable @functionInput -Verbose - name: 'Update module folder ReadMe' shell: pwsh run: | # Load used functions - . "$env:GITHUB_WORKSPACE/utilities/tools/Set-GitHubReadMeModuleTable.ps1" + . "$env:GITHUB_WORKSPACE/utilities/tools/Set-ReadMeModuleTable.ps1" $functionInput = @{ ModulesPath = Join-Path $env:GITHUB_WORKSPACE 'arm' @@ -59,12 +60,13 @@ jobs: Organization = ($env:GITHUB_REPOSITORY).split('/')[0] RepositoryName = ($env:GITHUB_REPOSITORY).split('/')[1] ColumnsInOrder = @('Name', 'ProviderNamespace','ResourceType') + Environment = 'GitHub' } Write-Verbose "Invoke task with" -Verbose Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose - Set-GitHubReadMeModuleTable @functionInput -Verbose + Set-ReadMeModuleTable @functionInput -Verbose - name: 'Push changes' shell: pwsh diff --git a/docs/wiki/UtilitiesSetGitHubReadMeModuleTable.md b/docs/wiki/UtilitiesSetGitHubReadMeModuleTable.md index 341b812d94..f423065ca3 100644 --- a/docs/wiki/UtilitiesSetGitHubReadMeModuleTable.md +++ b/docs/wiki/UtilitiesSetGitHubReadMeModuleTable.md @@ -14,7 +14,7 @@ In the platform's pipeline `platform.updateReadMe.yml`, this script is invoked e --- # Location -You can find the script under `/utilities/tools/Set-GitHubReadMeModuleTable.ps1` +You can find the script under `/utilities/tools/Set-ReadMeModuleTable.ps1` # How it works diff --git a/utilities/tools/Set-GitHubReadMeModuleTable.ps1 b/utilities/tools/Set-GitHubReadMeModuleTable.ps1 deleted file mode 100644 index 451f4b52be..0000000000 --- a/utilities/tools/Set-GitHubReadMeModuleTable.ps1 +++ /dev/null @@ -1,82 +0,0 @@ -#region Helper functions - -<# -.SYNOPSIS -Update the given ReadMe file with the latest module table - -.DESCRIPTION -Update the given ReadMe file with the latest module table. -You can specify the columns to be generated. - -.PARAMETER FilePath -Mandatory. The path to the ReadMe file to update - -.PARAMETER ModulesPath -Mandatory. The path to the modules folder to process - -.PARAMETER RepositoryName -Mandatory. The name of the repository the modules are in (required to generate the correct links) - -.PARAMETER Organization -Mandatory. The name of the Organization the modules are in (required to generate the correct links) - -.PARAMETER ColumnsInOrder -Mandatory. The set of columns to add to the table in the order you expect them in the table. -Available are 'Name', 'ProviderNamespace', 'ResourceType', 'TemplateType', 'Deploy' & 'Status' - -.EXAMPLE -Set-GitHubReadMeModuleTable -FilePath 'C:\readme.md' -ModulesPath 'C:\arm' -RepositoryName 'ResourceModules' -Organization 'Azure' -ColumnsInOrder @('Name','Status') - -Update the defined table section in the 'readme.md' file with a table that has the columns 'Name' & 'Status' -#> -function Set-GitHubReadMeModuleTable { - - [CmdletBinding(SupportsShouldProcess)] - param ( - [Parameter(Mandatory)] - [string] $FilePath, - - [Parameter(Mandatory)] - [string] $ModulesPath, - - [Parameter(Mandatory)] - [string] $RepositoryName, - - [Parameter(Mandatory)] - [string] $Organization, - - [Parameter(Mandatory)] - [ValidateSet('Name', 'ProviderNamespace', 'ResourceType', 'TemplateType', 'Deploy', 'Status')] - [string[]] $ColumnsInOrder, - - [Parameter(Mandatory = $false)] - [string] $SortByColumn = 'ProviderNamespace' - ) - - # Load external functions - . (Join-Path $PSScriptRoot 'helper/Get-ModulesAsMarkdownTable.ps1') - . (Join-Path $PSScriptRoot 'helper/Merge-FileWithNewContent.ps1') - - # Logic - $contentArray = Get-Content -Path $FilePath - - $tableStringInputObject = @{ - Path = $ModulesPath - RepositoryName = $RepositoryName - Organization = $Organization - ColumnsInOrder = $ColumnsInOrder - SortByColumn = $SortByColumn - } - $tableString = Get-ModulesAsMarkdownTable @tableStringInputObject - - $newContent = Merge-FileWithNewContent -oldContent $contentArray -newContent $tableString -sectionStartIdentifier '## Available Resource Modules' -contentType 'table' - - Write-Verbose 'New content:' - Write-Verbose '============' - Write-Verbose ($newContent | Out-String) - - if ($PSCmdlet.ShouldProcess("File in path [$FilePath]", 'Overwrite')) { - Set-Content -Path $FilePath -Value $newContent -Force - Write-Verbose "File [$FilePath] updated" -Verbose - } -} diff --git a/utilities/tools/Set-ReadMeModuleTable.ps1 b/utilities/tools/Set-ReadMeModuleTable.ps1 index 89c8bf1a32..46d6ee7bf9 100644 --- a/utilities/tools/Set-ReadMeModuleTable.ps1 +++ b/utilities/tools/Set-ReadMeModuleTable.ps1 @@ -52,10 +52,11 @@ function Set-ReadMeModuleTable { [Parameter(Mandatory = $false)] [string] $SortByColumn = 'ProviderNamespace', - [Parameter(ParameterSetName = 'AzureDevOps', Mandatory = $false)] - [switch]$ADO = $false, + [Parameter(Mandatory = $true)] + [ValidateSet('GitHub', 'ADO')] + [string]$Environment, - [Parameter(ParameterSetName = 'AzureDevOps', Mandatory = $false)] + [Parameter(Mandatory = $false)] [string]$ProjectName = '' ) @@ -72,10 +73,11 @@ function Set-ReadMeModuleTable { Organization = $Organization ColumnsInOrder = $ColumnsInOrder SortByColumn = $SortByColumn - ADO = $ADO + Environment = $Environment ProjectName = $ProjectName } - $tableString = Get-ModulesAsMarkdownTable @tableStringInputObject + Write-Verbose ($tableStringInputObject | ConvertTo-Json | Out-String) -Verbose + $tableString = Get-ModulesAsMarkdownTable @tableStringInputObject -Verbose $newContent = Merge-FileWithNewContent -oldContent $contentArray -newContent $tableString -sectionStartIdentifier '## Available Resource Modules' -contentType 'table' diff --git a/utilities/tools/helper/Get-ModulesAsMarkdownTable.ps1 b/utilities/tools/helper/Get-ModulesAsMarkdownTable.ps1 index 9ac462db4e..a028ae927d 100644 --- a/utilities/tools/helper/Get-ModulesAsMarkdownTable.ps1 +++ b/utilities/tools/helper/Get-ModulesAsMarkdownTable.ps1 @@ -40,25 +40,27 @@ function Get-PipelineStatusUrl { [Parameter(Mandatory)] [string] $Organization, - [Parameter(ParameterSetName = 'AzureDevOps', Mandatory = $false)] - [switch]$ADO, + [Parameter(Mandatory)] + [ValidateSet('GitHub', 'ADO')] + [string]$Environment, - [Parameter(ParameterSetName = 'AzureDevOps', Mandatory = $true)] - [string]$ProjectName + [Parameter(Mandatory = $false)] + [string]$ProjectName = '' ) $shortProvider = $provider.Replace('Microsoft.', 'MS.') $pipelineFileName = ('{0}.{1}.yml' -f $shortProvider, $name).Replace('\', '/').Replace('/', '.').ToLower() - switch ($ADO) { - $true { + switch ($Environment) { + 'ADO' { $pipelineFileUri = ".azuredevops/modulePipelines/$pipelineFileName" $pipelineName = (Get-Content -Path $pipelineFileUri)[0].TrimStart('name:').Replace('"', '').Trim() - $pipelineFileGitUri = 'https://dev.azure.com/{0}/{1}/_apis/build/status/{2}?branchName=main' -f $Organization, $Projectname, $pipelineName + $pipelineFileGitUri = ('https://dev.azure.com/{0}/{1}/_apis/build/status/{2}?branchName=main' -f $Organization, $Projectname, $pipelineName.Replace("'", '')) -replace ' ', '%20' + # Note: Badge name is automatically the pipeline name return ('[![{0}]({1})]({1})' -f $pipelineName, $pipelineFileGitUri).Replace('\', '/') } - Default { + 'GitHub' { $pipelineFileUri = ".github/workflows/$pipelineFileName" $pipelineName = (Get-Content -Path $pipelineFileUri)[0].TrimStart('name:').Replace('"', '').Trim() $pipelineFileGitUri = 'https://github.com/{0}/{1}/actions/workflows/{2}' -f $Organization, $RepositoryName, $pipelineFileName @@ -311,11 +313,12 @@ function Get-ResolvedSubServiceRow { [Parameter(Mandatory = $true)] [string] $Organization, - [Parameter(ParameterSetName = 'AzureDevOps', Mandatory = $false)] - [switch]$ADO, + [Parameter(Mandatory = $false)] + [ValidateSet('GitHub', 'ADO')] + [string]$Environment, - [Parameter(ParameterSetName = 'AzureDevOps', Mandatory = $true)] - [string]$ProjectName + [Parameter(Mandatory = $false)] + [string]$ProjectName = '' ) $rawSubFolders = Get-ChildItem -Path $subPath -Directory -Recurse -Exclude @('.bicep', '.parameters') -Force @@ -333,11 +336,11 @@ function Get-ResolvedSubServiceRow { foreach ($column in $ColumnsInOrder) { switch ($column) { 'Name' { - switch ($ADO) { - $true { + switch ($Environment) { + 'ADO' { $row['Name'] = ('[{0}](https://dev.azure.com/{1}/{2}/_git/{3}?path=/arm/{4})' -f (Get-ResourceModuleName -path $subfolder), $Organization, $ProjectName, $RepositoryName, $relativePath.Replace('\', '/')) } - Default { + 'GitHub' { $row['Name'] = ('[{0}](https://github.com/{1}/{2}/tree/main/arm/{3})' -f (Get-ResourceModuleName -path $subfolder), $Organization, $RepositoryName, $relativePath.Replace('\', '/')) } } @@ -358,11 +361,11 @@ function Get-ResolvedSubServiceRow { } } 'ResourceType' { - switch ($ADO) { - $true { + switch ($Environment) { + 'ADO' { $row['ResourceType'] = ('[{0}](https://dev.azure.com/{1}/{2}/_git/{3}?path=/arm/{4})' -f $subName, $Organization, $ProjectName, $RepositoryName, $relativePath.Replace('\', '/')) } - Default { + 'GitHub' { $row['ResourceType'] = ('[{0}](https://github.com/{1}/{2}/tree/main/arm/{3})' -f $subName, $Organization, $RepositoryName, $relativePath.Replace('\', '/')) } } @@ -471,11 +474,12 @@ function Get-ModulesAsMarkdownTable { [Parameter(Mandatory = $true)] [string] $Organization, - [Parameter(ParameterSetName = 'AzureDevOps', Mandatory = $false)] - [switch]$ADO, + [Parameter(Mandatory)] + [ValidateSet('GitHub', 'ADO')] + [string]$Environment, - [Parameter(ParameterSetName = 'AzureDevOps', Mandatory = $true)] - [string]$ProjectName + [Parameter(Mandatory = $false)] + [string]$ProjectName = '' ) # Header @@ -527,6 +531,8 @@ function Get-ModulesAsMarkdownTable { RepositoryName = $RepositoryName SortByColumn = $SortByColumn Organization = $Organization + Environment = $Environment + ProjectName = $ProjectName } $output = Get-ResolvedSubServiceRow @recursiveSubServiceInputObject } else { @@ -534,11 +540,11 @@ function Get-ModulesAsMarkdownTable { foreach ($column in $ColumnsInOrder) { switch ($column) { 'Name' { - switch ($ADO) { - $true { + switch ($Environment) { + 'ADO' { $row['Name'] = ('[{0}](https://dev.azure.com/{1}/{2}/_git/{3}?path=/arm/{4})' -f (Get-ResourceModuleName -path $containedFolder), $Organization, $ProjectName, $RepositoryName, $concatedBase.Replace('\', '/')) } - Default { + 'GitHub' { $row['Name'] = ('[{0}](https://github.com/{1}/{2}/tree/main/arm/{3})' -f (Get-ResourceModuleName -path $containedFolder), $Organization, $RepositoryName, $concatedBase.Replace('\', '/')) } } @@ -558,11 +564,11 @@ function Get-ModulesAsMarkdownTable { } } 'ResourceType' { - switch ($ADO) { - $true { + switch ($Environment) { + 'ADO' { $row['ResourceType'] = ('[{0}](https://dev.azure.com/{1}/{2}/_git/{3}?path=/arm/{4})' -f (Get-ResourceModuleName -path $containedFolder), $Organization, $ProjectName, $RepositoryName, $concatedBase.Replace('\', '/')) } - Default { + 'GitHub' { $row['ResourceType'] += ('[{0}](https://github.com/{1}/{2}/tree/main/arm/{3})' -f $containedFolderName, $Organization, $RepositoryName, $concatedBase.Replace('\', '/')) } } @@ -575,7 +581,7 @@ function Get-ModulesAsMarkdownTable { $row['Deploy'] += Get-DeployToAzureUrl -path $containedFolder -RepositoryName $RepositoryName -Organization $Organization } 'Status' { - $row['Status'] += Get-PipelineStatusUrl -name $containedFolderName -provider $provider -RepositoryName $RepositoryName -Organization $Organization + $row['Status'] += Get-PipelineStatusUrl -name $containedFolderName -provider $provider -RepositoryName $RepositoryName -Organization $Organization -Environment $Environment -ProjectName $ProjectName } Default { Write-Warning "Column [$column] not existing. Available are: [Name|ProviderNamespace|ResourceType|TemplateType|Deploy|Status]" From f9ad84f79388d3be172bf58bb9df113da1eda49f Mon Sep 17 00:00:00 2001 From: Margarita Sanz Date: Wed, 2 Mar 2022 11:30:39 +0100 Subject: [PATCH 3/4] alignement between tasks --- .azuredevops/platformPipelines/platform.updateReadMe.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.azuredevops/platformPipelines/platform.updateReadMe.yml b/.azuredevops/platformPipelines/platform.updateReadMe.yml index 939b0081ee..defe6e0d80 100644 --- a/.azuredevops/platformPipelines/platform.updateReadMe.yml +++ b/.azuredevops/platformPipelines/platform.updateReadMe.yml @@ -36,12 +36,10 @@ jobs: # Load used functions . (Join-Path '$(System.DefaultWorkingDirectory)' 'utilities' 'tools' 'Set-ReadMeModuleTable.ps1') - $OrganizationURI = '$(System.CollectionUri)' - $functionInput = @{ ModulesPath = Join-Path '$(System.DefaultWorkingDirectory)' 'arm' FilePath = Join-Path '$(System.DefaultWorkingDirectory)' 'README.md' - Organization = $OrganizationURI.Split('/')[3] + Organization = '$(System.CollectionUri)'.Split('/')[3] RepositoryName = '$(Build.Repository.Name)' ColumnsInOrder = @('Name', 'Status') SortByColumn = 'Name' From 3ba19e66dafd6b7bb4a58f2891e68c6b2fb46bdf Mon Sep 17 00:00:00 2001 From: Margarita Sanz Date: Wed, 2 Mar 2022 11:48:26 +0100 Subject: [PATCH 4/4] fixed default values --- utilities/tools/Set-ReadMeModuleTable.ps1 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/utilities/tools/Set-ReadMeModuleTable.ps1 b/utilities/tools/Set-ReadMeModuleTable.ps1 index 46d6ee7bf9..0af24e414d 100644 --- a/utilities/tools/Set-ReadMeModuleTable.ps1 +++ b/utilities/tools/Set-ReadMeModuleTable.ps1 @@ -33,17 +33,17 @@ function Set-ReadMeModuleTable { [CmdletBinding(SupportsShouldProcess)] param ( - [Parameter(Mandatory = $false)] - [string] $FilePath = 'C:\Users\masanzde\Documents\IACs\Azure\ResourceModules\README.md', + [Parameter(Mandatory = $true)] + [string] $FilePath, - [Parameter(Mandatory = $false)] - [string] $ModulesPath = 'C:\Users\masanzde\Documents\IACs\Azure\ResourceModules\arm', + [Parameter(Mandatory = $true)] + [string] $ModulesPath, - [Parameter(Mandatory = $false)] - [string] $RepositoryName = 'ResourceModules', + [Parameter(Mandatory = $true)] + [string] $RepositoryName, - [Parameter(Mandatory = $false)] - [string] $Organization = 'masanzde', + [Parameter(Mandatory = $true)] + [string] $Organization, [Parameter(Mandatory = $false)] [ValidateSet('Name', 'ProviderNamespace', 'ResourceType', 'TemplateType', 'Deploy', 'Status')]