diff --git a/.azuredevops/platformPipelines/platform.updateReadMe.yml b/.azuredevops/platformPipelines/platform.updateReadMe.yml index 1d62c35b57..defe6e0d80 100644 --- a/.azuredevops/platformPipelines/platform.updateReadMe.yml +++ b/.azuredevops/platformPipelines/platform.updateReadMe.yml @@ -20,10 +20,10 @@ variables: jobs: - job: Update_module_tables pool: - ${{ if ne($(vmImage), '') }}: - vmImage: '$(vmImage)' - ${{ if ne($(poolName), '') }}: - name: '$(poolName)' + ${{ if ne(variables.vmImage, '') }}: + vmImage: ${{ variables.vmImage }} + ${{ if ne(variables.poolName, '') }}: + name: ${{ variables.poolName }} steps: - checkout: self persistCredentials: true @@ -34,21 +34,23 @@ jobs: pwsh: true script: | # Load used functions - . (Join-Path '$(System.DefaultWorkingDirectory)' 'utilities' 'tools' 'Set-GitHubReadMeModuleTable.ps1') + . (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] + Organization = '$(System.CollectionUri)'.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 - Set-GitHubReadMeModuleTable @functionInput -Verbose + Set-ReadMeModuleTable @functionInput -Verbose - task: PowerShell@2 displayName: 'Update module folder ReadMe' inputs: @@ -56,20 +58,22 @@ jobs: pwsh: true script: | # Load used functions - . (Join-Path '$(System.DefaultWorkingDirectory)' 'utilities' 'tools' 'Set-GitHubReadMeModuleTable.ps1') + . (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 = ('$(Build.Repository.Name)').split('/')[0] - RepositoryName = ('$(Build.Repository.Name)').split('/')[1] + 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 - Set-GitHubReadMeModuleTable @functionInput -Verbose + Set-ReadMeModuleTable @functionInput -Verbose - task: PowerShell@2 displayName: 'Push changes' inputs: 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-ReadMeModuleTable.ps1 similarity index 72% rename from utilities/tools/Set-GitHubReadMeModuleTable.ps1 rename to utilities/tools/Set-ReadMeModuleTable.ps1 index 451f4b52be..0af24e414d 100644 --- a/utilities/tools/Set-GitHubReadMeModuleTable.ps1 +++ b/utilities/tools/Set-ReadMeModuleTable.ps1 @@ -25,32 +25,39 @@ Mandatory. The set of columns to add to the table in the order you expect them i 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') +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-GitHubReadMeModuleTable { +function Set-ReadMeModuleTable { [CmdletBinding(SupportsShouldProcess)] param ( - [Parameter(Mandatory)] + [Parameter(Mandatory = $true)] [string] $FilePath, - [Parameter(Mandatory)] + [Parameter(Mandatory = $true)] [string] $ModulesPath, - [Parameter(Mandatory)] + [Parameter(Mandatory = $true)] [string] $RepositoryName, - [Parameter(Mandatory)] + [Parameter(Mandatory = $true)] [string] $Organization, - [Parameter(Mandatory)] + [Parameter(Mandatory = $false)] [ValidateSet('Name', 'ProviderNamespace', 'ResourceType', 'TemplateType', 'Deploy', 'Status')] - [string[]] $ColumnsInOrder, + [string[]] $ColumnsInOrder = @('Name', 'ProviderNamespace', 'ResourceType'), + + [Parameter(Mandatory = $false)] + [string] $SortByColumn = 'ProviderNamespace', + + [Parameter(Mandatory = $true)] + [ValidateSet('GitHub', 'ADO')] + [string]$Environment, [Parameter(Mandatory = $false)] - [string] $SortByColumn = 'ProviderNamespace' + [string]$ProjectName = '' ) # Load external functions @@ -66,8 +73,11 @@ function Set-GitHubReadMeModuleTable { Organization = $Organization ColumnsInOrder = $ColumnsInOrder SortByColumn = $SortByColumn + 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 16ce236c75..a028ae927d 100644 --- a/utilities/tools/helper/Get-ModulesAsMarkdownTable.ps1 +++ b/utilities/tools/helper/Get-ModulesAsMarkdownTable.ps1 @@ -38,19 +38,36 @@ 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(Mandatory)] + [ValidateSet('GitHub', 'ADO')] + [string]$Environment, - $pipelineName = (Get-Content -Path $pipelineFileUri)[0].TrimStart('name:').Replace('"', '').Trim() + [Parameter(Mandatory = $false)] + [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 ($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.Replace("'", '')) -replace ' ', '%20' + + # Note: Badge name is automatically the pipeline name + return ('[![{0}]({1})]({1})' -f $pipelineName, $pipelineFileGitUri).Replace('\', '/') + } + '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 + # Note: Badge name is automatically the pipeline name + return ('[![{0}]({1}/badge.svg)]({1})' -f $pipelineName, $pipelineFileGitUri).Replace('\', '/') + } + } } <# @@ -294,7 +311,14 @@ function Get-ResolvedSubServiceRow { [string] $RepositoryName, [Parameter(Mandatory = $true)] - [string] $Organization + [string] $Organization, + + [Parameter(Mandatory = $false)] + [ValidateSet('GitHub', 'ADO')] + [string]$Environment, + + [Parameter(Mandatory = $false)] + [string]$ProjectName = '' ) $rawSubFolders = Get-ChildItem -Path $subPath -Directory -Recurse -Exclude @('.bicep', '.parameters') -Force @@ -312,7 +336,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 ($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('\', '/')) + } + 'GitHub' { + $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 +361,15 @@ function Get-ResolvedSubServiceRow { } } 'ResourceType' { - $row['ResourceType'] = ('[{0}](https://github.com/{1}/{2}/tree/main/arm/{3})' -f $subName, $Organization, $RepositoryName, $relativePath.Replace('\', '/')) + switch ($Environment) { + 'ADO' { + $row['ResourceType'] = ('[{0}](https://dev.azure.com/{1}/{2}/_git/{3}?path=/arm/{4})' -f $subName, $Organization, $ProjectName, $RepositoryName, $relativePath.Replace('\', '/')) + } + 'GitHub' { + $row['ResourceType'] = ('[{0}](https://github.com/{1}/{2}/tree/main/arm/{3})' -f $subName, $Organization, $RepositoryName, $relativePath.Replace('\', '/')) + } + } + } 'TemplateType' { @@ -432,7 +472,14 @@ function Get-ModulesAsMarkdownTable { [string] $RepositoryName, [Parameter(Mandatory = $true)] - [string] $Organization + [string] $Organization, + + [Parameter(Mandatory)] + [ValidateSet('GitHub', 'ADO')] + [string]$Environment, + + [Parameter(Mandatory = $false)] + [string]$ProjectName = '' ) # Header @@ -484,15 +531,23 @@ function Get-ModulesAsMarkdownTable { RepositoryName = $RepositoryName SortByColumn = $SortByColumn Organization = $Organization + Environment = $Environment + ProjectName = $ProjectName } $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 ($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('\', '/')) + } + 'GitHub' { + $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 +564,15 @@ function Get-ModulesAsMarkdownTable { } } 'ResourceType' { - $row['ResourceType'] += ('[{0}](https://github.com/{1}/{2}/tree/main/arm/{3})' -f $containedFolderName, $Organization, $RepositoryName, $concatedBase.Replace('\', '/')) + 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('\', '/')) + } + 'GitHub' { + $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 @@ -518,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]"