Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub Action to Create Package Wiki #1197

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/generate_package_wiki.yml
Original file line number Diff line number Diff line change
@@ -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 '[email protected]'
git config user.name 'vm-packages'
git add .
git commit -am "Update Package Wiki"
git push
61 changes: 61 additions & 0 deletions scripts/utils/generate_package_wiki.ps1
Original file line number Diff line number Diff line change
@@ -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
Loading