Skip to content

Commit

Permalink
Add Github Action to Create Package Wiki
Browse files Browse the repository at this point in the history
  • Loading branch information
emtuls committed Dec 12, 2024
1 parent fe713e9 commit 408dae7
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions .github/workflows/generate_package_wiki.yml
Original file line number Diff line number Diff line change
@@ -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 '[email protected]'
git config user.name 'vm-packages'
git add .
git commit -am "Update Package Wiki"
git push

0 comments on commit 408dae7

Please sign in to comment.