Skip to content

Commit 2a4d541

Browse files
Add staged logging to update-index
Use LogGroup and Write-Host messages to show processing stages and per-module progress. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 7fd5ed1 commit 2a4d541

2 files changed

Lines changed: 139 additions & 94 deletions

File tree

.github/actions/update-index/src/Helper.psm1

Lines changed: 118 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ function Show-RepoList {
6464
}
6565
}
6666
} | Sort-Object Type, Name
67+
$reposByType = $repos | Group-Object Type | Sort-Object Name
68+
Write-Host 'Repository type distribution:'
69+
$reposByType | ForEach-Object {
70+
Write-Host " - $($_.Name): $($_.Count)"
71+
}
72+
Write-Host 'Repository table preview:'
6773
$repos | Format-Table -AutoSize
6874
}
6975

@@ -106,25 +112,28 @@ function Update-MDSection {
106112
[string] $Content
107113
)
108114

109-
$startSegment = "<!-- $Name`_START -->"
110-
$endSegment = "<!-- $Name`_END -->"
111-
$currentContent = Get-Content -Path $Path
112-
$startIndex = $currentContent.IndexOf($startSegment)
113-
$endIndex = $currentContent.IndexOf($endSegment)
115+
LogGroup "Update markdown section [$Name] in [$Path]" {
116+
$startSegment = "<!-- $Name`_START -->"
117+
$endSegment = "<!-- $Name`_END -->"
118+
$currentContent = Get-Content -Path $Path
119+
$startIndex = $currentContent.IndexOf($startSegment)
120+
$endIndex = $currentContent.IndexOf($endSegment)
114121

115-
if ($startIndex -lt 0) {
116-
throw "[$Name] The start comment segment was not found in the file."
117-
}
118-
if ($endIndex -lt 0) {
119-
throw "[$Name] The end comment segment was not found in the file."
120-
}
121-
if ($endIndex -lt $startIndex) {
122-
throw "[$Name] The end comment segment was found before the start comment segment."
123-
}
122+
if ($startIndex -lt 0) {
123+
throw "[$Name] The start comment segment was not found in the file."
124+
}
125+
if ($endIndex -lt 0) {
126+
throw "[$Name] The end comment segment was not found in the file."
127+
}
128+
if ($endIndex -lt $startIndex) {
129+
throw "[$Name] The end comment segment was found before the start comment segment."
130+
}
124131

125-
$updatedContent = $currentContent[0..$startIndex] + $Content + $currentContent[($endIndex)..($currentContent.Length - 1)]
126-
if ($PSCmdlet.ShouldProcess('Readme section', 'Update')) {
127-
Set-Content -Path $Path -Value $updatedContent
132+
$updatedContent = $currentContent[0..$startIndex] + $Content + $currentContent[($endIndex)..($currentContent.Length - 1)]
133+
if ($PSCmdlet.ShouldProcess('Readme section', 'Update')) {
134+
Set-Content -Path $Path -Value $updatedContent
135+
Write-Host "Section [$Name] updated in [$Path]"
136+
}
128137
}
129138
}
130139

@@ -654,96 +663,115 @@ function Update-ModuleList {
654663
[object[]] $Repos = @()
655664
)
656665

657-
if ($Repos.Count -eq 0) {
658-
$Repos = Show-RepoList
659-
}
660-
661-
$moduleCatalogTemplateVersion = 'v2'
662-
$moduleCatalogTemplateFolder = Join-Path (Join-Path $PSScriptRoot '..') 'templates\module-catalog'
663-
$moduleCatalogRowTemplatePath = Join-Path $moduleCatalogTemplateFolder "$moduleCatalogTemplateVersion-row.html"
664-
$moduleCatalogTableTemplatePath = Join-Path $moduleCatalogTemplateFolder "$moduleCatalogTemplateVersion-table.html"
665-
$moduleCatalogRowTemplate = Get-TemplateContent -Path $moduleCatalogRowTemplatePath
666-
$moduleCatalogTableTemplate = Get-TemplateContent -Path $moduleCatalogTableTemplatePath
666+
LogGroup 'Prepare module catalog generation' {
667+
if ($Repos.Count -eq 0) {
668+
Write-Host 'No repository list was provided, retrieving repositories now'
669+
$Repos = Show-RepoList
670+
}
667671

668-
$moduleRepos = $Repos | Where-Object {
669-
$_.Type -eq 'Module' -and $_.Owner -eq 'PSModule'
670-
} | Sort-Object Name
672+
$moduleCatalogTemplateVersion = 'v2'
673+
$moduleCatalogTemplateFolder = Join-Path (Join-Path $PSScriptRoot '..') 'templates\module-catalog'
674+
$moduleCatalogRowTemplatePath = Join-Path $moduleCatalogTemplateFolder "$moduleCatalogTemplateVersion-row.html"
675+
$moduleCatalogTableTemplatePath = Join-Path $moduleCatalogTemplateFolder "$moduleCatalogTemplateVersion-table.html"
676+
$moduleCatalogRowTemplate = Get-TemplateContent -Path $moduleCatalogRowTemplatePath
677+
$moduleCatalogTableTemplate = Get-TemplateContent -Path $moduleCatalogTableTemplatePath
678+
679+
$moduleRepos = $Repos | Where-Object {
680+
$_.Type -eq 'Module' -and $_.Owner -eq 'PSModule'
681+
} | Sort-Object Name
682+
Write-Host "Module repositories to process: $($moduleRepos.Count)"
683+
684+
$catalogFolderPath = Join-Path 'src\docs\Modules\Catalog' 'Repositories'
685+
if (-not (Test-Path $catalogFolderPath)) {
686+
Write-Host "Creating catalog folder [$catalogFolderPath]"
687+
$null = New-Item -Path $catalogFolderPath -ItemType Directory
688+
}
671689

672-
$catalogFolderPath = Join-Path 'src\docs\Modules\Catalog' 'Repositories'
673-
if (-not (Test-Path $catalogFolderPath)) {
674-
$null = New-Item -Path $catalogFolderPath -ItemType Directory
690+
$processLatestVersion = Get-RepositoryVersion -Owner 'PSModule' -Name 'Process-PSModule'
691+
Write-Host "Latest Process-PSModule version: $processLatestVersion"
692+
$moduleTableRows = ''
675693
}
676694

677-
$processLatestVersion = Get-RepositoryVersion -Owner 'PSModule' -Name 'Process-PSModule'
678-
$moduleTableRows = ''
679-
695+
$moduleRepoTotal = $moduleRepos.Count
696+
$moduleRepoIndex = 0
680697
foreach ($repo in $moduleRepos) {
698+
$moduleRepoIndex++
681699
$owner = [string](Get-PropertyValue -InputObject $repo -Names @('Owner') -Default 'PSModule')
682700
$name = [string](Get-PropertyValue -InputObject $repo -Names @('Name') -Default '')
683701
if ([string]::IsNullOrWhiteSpace($name)) {
702+
Write-Host "Skipping module at index [$moduleRepoIndex] because the repository name is empty"
684703
continue
685704
}
686705

687-
$description = [string](Get-PropertyValue -InputObject $repo -Names @('Description') -Default 'No description available.')
688-
if ([string]::IsNullOrWhiteSpace($description)) {
689-
$description = 'No description available.'
690-
}
706+
LogGroup "Process module [$moduleRepoIndex/$moduleRepoTotal] [$owner/$name]" {
707+
$description = [string](Get-PropertyValue -InputObject $repo -Names @('Description') -Default 'No description available.')
708+
if ([string]::IsNullOrWhiteSpace($description)) {
709+
$description = 'No description available.'
710+
}
691711

692-
$defaultBranch = [string](Get-PropertyValue -InputObject $repo -Names @('DefaultBranch', 'default_branch') -Default 'main')
693-
if ([string]::IsNullOrWhiteSpace($defaultBranch)) {
694-
$defaultBranch = 'main'
695-
}
712+
$defaultBranch = [string](Get-PropertyValue -InputObject $repo -Names @('DefaultBranch', 'default_branch') -Default 'main')
713+
if ([string]::IsNullOrWhiteSpace($defaultBranch)) {
714+
$defaultBranch = 'main'
715+
}
696716

697-
$readmeContent = Get-RepositoryReadmeContent -Owner $owner -Name $name
698-
$aboutSummary = Get-MarkdownSummary -Markdown $readmeContent
699-
if ([string]::IsNullOrWhiteSpace($aboutSummary)) {
700-
$aboutSummary = $description
701-
}
717+
Write-Host "Collecting metadata from branch [$defaultBranch]"
718+
$readmeContent = Get-RepositoryReadmeContent -Owner $owner -Name $name
719+
$aboutSummary = Get-MarkdownSummary -Markdown $readmeContent
720+
if ([string]::IsNullOrWhiteSpace($aboutSummary)) {
721+
$aboutSummary = $description
722+
}
702723

703-
$titleSummary = ConvertTo-HtmlAttributeValue -Value $aboutSummary
704-
$version = Get-RepositoryVersion -Owner $owner -Name $name
705-
$processReference = Get-WorkflowReference -Owner $owner -Name $name -DefaultBranch $defaultBranch
706-
$processStatus = Get-ProcessReferenceStatus -Reference $processReference -LatestVersion $processLatestVersion
707-
$issues = Get-OpenItemCount -Owner $owner -Name $name -Type issue
708-
$pullRequests = Get-OpenItemCount -Owner $owner -Name $name -Type pr
709-
$stars = [int](Get-PropertyValue -InputObject $repo -Names @('Stars', 'stargazers_count', 'StargazersCount') -Default 0)
710-
711-
$modulePageFileName = "$name.md"
712-
$modulePagePath = Join-Path $catalogFolderPath $modulePageFileName
713-
$modulePageRelativeLink = "./Repositories/$modulePageFileName"
714-
715-
$moduleData = [pscustomobject]@{
716-
Owner = $owner
717-
Name = $name
718-
Description = $description
719-
Version = $version
720-
ProcessReference = $processReference
721-
ProcessStatus = $processStatus
722-
Issues = $issues
723-
PullRequests = $pullRequests
724-
Stars = $stars
725-
About = $aboutSummary
724+
$titleSummary = ConvertTo-HtmlAttributeValue -Value $aboutSummary
725+
$version = Get-RepositoryVersion -Owner $owner -Name $name
726+
$processReference = Get-WorkflowReference -Owner $owner -Name $name -DefaultBranch $defaultBranch
727+
$processStatus = Get-ProcessReferenceStatus -Reference $processReference -LatestVersion $processLatestVersion
728+
$issues = Get-OpenItemCount -Owner $owner -Name $name -Type issue
729+
$pullRequests = Get-OpenItemCount -Owner $owner -Name $name -Type pr
730+
$stars = [int](Get-PropertyValue -InputObject $repo -Names @('Stars', 'stargazers_count', 'StargazersCount') -Default 0)
731+
732+
Write-Host "Version [$version], Process ref [$processReference], status [$processStatus]"
733+
Write-Host "Open issues [$issues], open PRs [$pullRequests], stars [$stars]"
734+
735+
$modulePageFileName = "$name.md"
736+
$modulePagePath = Join-Path $catalogFolderPath $modulePageFileName
737+
$modulePageRelativeLink = "./Repositories/$modulePageFileName"
738+
739+
$moduleData = [pscustomobject]@{
740+
Owner = $owner
741+
Name = $name
742+
Description = $description
743+
Version = $version
744+
ProcessReference = $processReference
745+
ProcessStatus = $processStatus
746+
Issues = $issues
747+
PullRequests = $pullRequests
748+
Stars = $stars
749+
About = $aboutSummary
750+
}
751+
New-ModuleCatalogPage -Path $modulePagePath -ModuleData $moduleData
752+
Write-Host "Wrote repository page [$modulePagePath]"
753+
754+
$moduleTableRow = $moduleCatalogRowTemplate
755+
$moduleTableRow = $moduleTableRow.Replace('{{ MODULE_PAGE_LINK }}', $modulePageRelativeLink)
756+
$moduleTableRow = $moduleTableRow.Replace('{{ TITLE_SUMMARY }}', $titleSummary)
757+
$moduleTableRow = $moduleTableRow.Replace('{{ NAME }}', $name)
758+
$moduleTableRow = $moduleTableRow.Replace('{{ VERSION }}', $version)
759+
$moduleTableRow = $moduleTableRow.Replace('{{ PROCESS_REFERENCE }}', $processReference)
760+
$moduleTableRow = $moduleTableRow.Replace('{{ PROCESS_STATUS }}', $processStatus)
761+
$moduleTableRow = $moduleTableRow.Replace('{{ OWNER }}', $owner)
762+
$moduleTableRow = $moduleTableRow.Replace('{{ ISSUES }}', [string]$issues)
763+
$moduleTableRow = $moduleTableRow.Replace('{{ PULL_REQUESTS }}', [string]$pullRequests)
764+
$moduleTableRow = $moduleTableRow.Replace('{{ STARS }}', [string]$stars)
765+
$moduleTableRows += $moduleTableRow.TrimEnd()
766+
$moduleTableRows += [Environment]::NewLine
726767
}
727-
New-ModuleCatalogPage -Path $modulePagePath -ModuleData $moduleData
728-
729-
$moduleTableRow = $moduleCatalogRowTemplate
730-
$moduleTableRow = $moduleTableRow.Replace('{{ MODULE_PAGE_LINK }}', $modulePageRelativeLink)
731-
$moduleTableRow = $moduleTableRow.Replace('{{ TITLE_SUMMARY }}', $titleSummary)
732-
$moduleTableRow = $moduleTableRow.Replace('{{ NAME }}', $name)
733-
$moduleTableRow = $moduleTableRow.Replace('{{ VERSION }}', $version)
734-
$moduleTableRow = $moduleTableRow.Replace('{{ PROCESS_REFERENCE }}', $processReference)
735-
$moduleTableRow = $moduleTableRow.Replace('{{ PROCESS_STATUS }}', $processStatus)
736-
$moduleTableRow = $moduleTableRow.Replace('{{ OWNER }}', $owner)
737-
$moduleTableRow = $moduleTableRow.Replace('{{ ISSUES }}', [string]$issues)
738-
$moduleTableRow = $moduleTableRow.Replace('{{ PULL_REQUESTS }}', [string]$pullRequests)
739-
$moduleTableRow = $moduleTableRow.Replace('{{ STARS }}', [string]$stars)
740-
$moduleTableRows += $moduleTableRow.TrimEnd()
741-
$moduleTableRows += [Environment]::NewLine
742768
}
743769

744-
$moduleTable = $moduleCatalogTableTemplate.Replace('{{ ROWS }}', $moduleTableRows.TrimEnd())
745-
746-
Update-MDSection -Path '.\src\docs\Modules\Catalog\index.md' -Name 'MODULE_CATALOG' -Content $moduleTable
770+
LogGroup 'Write module catalog table to docs index' {
771+
$moduleTable = $moduleCatalogTableTemplate.Replace('{{ ROWS }}', $moduleTableRows.TrimEnd())
772+
Update-MDSection -Path '.\src\docs\Modules\Catalog\index.md' -Name 'MODULE_CATALOG' -Content $moduleTable
773+
Write-Host 'Module catalog table update completed'
774+
}
747775
}
748776

749777
function Update-FunctionAppList {
Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
Import-Module -Name (Join-Path $PSScriptRoot 'Helper.psm1')
22

3-
$repos = Show-RepoList
4-
# Update-ActionList
5-
# Update-FunctionAppList
6-
Update-ModuleList -Repos $repos
3+
LogGroup 'Initialize update-index run' {
4+
Write-Host "Starting update-index in [$PSScriptRoot]"
5+
}
6+
7+
LogGroup 'Collect repositories' {
8+
$repos = Show-RepoList
9+
Write-Host "Repository collection complete: $($repos.Count) records"
10+
}
11+
12+
LogGroup 'Skipped generators' {
13+
Write-Host 'Update-ActionList is currently disabled in main.ps1'
14+
Write-Host 'Update-FunctionAppList is currently disabled in main.ps1'
15+
}
16+
17+
LogGroup 'Update module catalog docs' {
18+
Update-ModuleList -Repos $repos
19+
}
20+
21+
LogGroup 'Finalize update-index run' {
22+
Write-Host 'update-index run completed'
23+
}

0 commit comments

Comments
 (0)