Skip to content

Commit

Permalink
Update REDAMEs from ADO pipelines added (#1067)
Browse files Browse the repository at this point in the history
* ADO wiki updated

* updated GitHub and ADO pipelines

* alignement between tasks

* fixed default values
  • Loading branch information
Msanzdelrio authored Mar 2, 2022
1 parent 59abf8b commit 3865b03
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 44 deletions.
28 changes: 16 additions & 12 deletions .azuredevops/platformPipelines/platform.updateReadMe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,42 +34,46 @@ 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:
targetType: inline
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:
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/platform.updateReadMe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -40,31 +40,33 @@ 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'
FilePath = Join-Path $env:GITHUB_WORKSPACE 'arm/README.md'
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
Expand Down
2 changes: 1 addition & 1 deletion docs/wiki/UtilitiesSetGitHubReadMeModuleTable.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'

Expand Down
97 changes: 80 additions & 17 deletions utilities/tools/helper/Get-ModulesAsMarkdownTable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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('\', '/')
}
}
}

<#
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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' {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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') {
Expand All @@ -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
Expand All @@ -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]"
Expand Down

0 comments on commit 3865b03

Please sign in to comment.