From 408dae79c900a3ca0e738bff138276399e68b051 Mon Sep 17 00:00:00 2001 From: Elliot Chernofsky Date: Wed, 11 Dec 2024 00:12:24 -0500 Subject: [PATCH] Add Github Action to Create Package Wiki --- .github/workflows/generate_package_wiki.yml | 105 ++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 .github/workflows/generate_package_wiki.yml diff --git a/.github/workflows/generate_package_wiki.yml b/.github/workflows/generate_package_wiki.yml new file mode 100644 index 00000000..1bbd19a2 --- /dev/null +++ b/.github/workflows/generate_package_wiki.yml @@ -0,0 +1,105 @@ +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: Install Chocolatey + run: choco install chocolatey -y + + - name: Generate Wiki Content + id: generate-content + shell: pwsh + run: | + $source = "https://www.myget.org/F/vm-packages/api/v2" + + $packagesDir = "packages" + $packages = Get-ChildItem -Path $packagesDir -Directory | ForEach-Object { $_.Name } | Sort-Object + + $wikiContent = "# Package List`n`n" + $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 + + - 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