-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Github Action to Create Package Wiki
- Loading branch information
Showing
1 changed file
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |