diff --git a/.github/workflows/generate_package_wiki.yml b/.github/workflows/generate_package_wiki.yml new file mode 100644 index 000000000..e5475aa4e --- /dev/null +++ b/.github/workflows/generate_package_wiki.yml @@ -0,0 +1,37 @@ +name: Generate Package Wiki + +on: + schedule: + # Runs daily at a weird time (02:50 UTC) to avoid delays during periods of + # high loads of GitHub Actions workflow runs. + - cron: '50 2 * * *' + workflow_dispatch: # Allow manual triggering + +jobs: + generate-wiki: + runs-on: windows-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Checkout Wiki Repo + uses: actions/checkout@v3 + with: + repository: ${{ github.repository }}.wiki + path: wiki + token: ${{ secrets.REPO_TOKEN }} + fetch-depth: 0 + + - name: Generate Wiki Content + id: generate-content + shell: pwsh + run: scripts/utils/generate_package_wiki.ps1 + + - name: Commit changes + working-directory: wiki + run: | + git config user.email 'vm-packages@google.com' + git config user.name 'vm-packages' + git add . + git commit -am "Update Package Wiki" + git push diff --git a/scripts/utils/generate_package_wiki.ps1 b/scripts/utils/generate_package_wiki.ps1 new file mode 100644 index 000000000..e92946c66 --- /dev/null +++ b/scripts/utils/generate_package_wiki.ps1 @@ -0,0 +1,61 @@ +$packagesDir = "packages" +$packages = Get-ChildItem -Path $packagesDir -Directory | ForEach-Object { $_.Name } | Sort-Object +$wikiContent = "" +$packagesByCategory = @{} + +foreach ($package in $packages) { +$categoryFile = "$packagesDir/$package/tools/chocolateyinstall.ps1" +if (Test-Path $categoryFile) { + $categoryMatch = Select-String -Path $categoryFile -Pattern '\$category\s*=\s*["''](.+?)["'']' -AllMatches + if ($categoryMatch) { + $category = $categoryMatch.Matches.Groups[1].Value.Trim("'""") + } else { + $category = "Not Categorized" + } +} else { + $category = "Not Categorized" +} + +if (-not ($packagesByCategory.ContainsKey($category))) { + $packagesByCategory[$category] = "" +} + +try { + $nuspecFile = "$packagesDir\$package\$package.nuspec" + if (Test-Path $nuspecFile) { + $xml = [xml](Get-Content $nuspecFile) + $description = $xml.package.metadata.description + } else { + $description = "Nuspec file not found." + } + if (-not $description) { + $description = "Description not found in .nuspec." + } +} +catch { + Write-Warning "Error getting description for $($package): $_" + $description = "Error retrieving description." +} + +$packagesByCategory[$category] += "| $package | $description |`n" +} + +# Process categories (excluding "Not Categorized") +$sortedCategories = ($packagesByCategory.Keys | Where-Object {$_ -ne "Not Categorized"} | Sort-Object) +foreach ($category in $sortedCategories) { +$wikiContent += "## $category`n`n" +$wikiContent += "| Package | Description |`n" +$wikiContent += "|---|---|`n" +$wikiContent += $packagesByCategory[$category] + "`n`n" +} + +# Add "Not Categorized" last +if ($packagesByCategory.ContainsKey("Not Categorized")) { +$wikiContent += "## Not Categorized`n`n" +$wikiContent += "| Package | Description |`n" +$wikiContent += "|---|---|`n" +$wikiContent += $packagesByCategory["Not Categorized"] + "`n`n" +} + +# Write the wiki content to a file +$wikiContent | Out-File -FilePath "wiki/Packages.md" -Encoding UTF8 \ No newline at end of file