Readme CI
This commit is contained in:
161
.gitea/scripts/generate-readme.py
Normal file
161
.gitea/scripts/generate-readme.py
Normal file
@@ -0,0 +1,161 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Generate README.md with ArgoCD application status badges.
|
||||
Scans k8s/ directory structure to find all applications and generates badges for them.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Dict, List
|
||||
|
||||
|
||||
def scan_k8s_directory(k8s_path: str) -> Dict[str, List[str]]:
|
||||
"""
|
||||
Scan k8s/ directory and return applications grouped by category.
|
||||
|
||||
Args:
|
||||
k8s_path: Path to k8s directory
|
||||
|
||||
Returns:
|
||||
Dictionary with categories as keys and lists of app names as values
|
||||
"""
|
||||
apps_by_category = {
|
||||
'core': [],
|
||||
'apps': [],
|
||||
'games': []
|
||||
}
|
||||
|
||||
k8s_dir = Path(k8s_path)
|
||||
|
||||
for category in apps_by_category.keys():
|
||||
category_path = k8s_dir / category
|
||||
if category_path.exists() and category_path.is_dir():
|
||||
# Get all subdirectories (each subdirectory is an app)
|
||||
apps = [
|
||||
d.name for d in category_path.iterdir()
|
||||
if d.is_dir() and not d.name.startswith('.')
|
||||
]
|
||||
apps_by_category[category] = sorted(apps)
|
||||
|
||||
return apps_by_category
|
||||
|
||||
|
||||
def generate_badge_line(app_name: str) -> str:
|
||||
"""
|
||||
Generate markdown line with badge for an application.
|
||||
|
||||
Args:
|
||||
app_name: Name of the application
|
||||
|
||||
Returns:
|
||||
Markdown formatted string with badge
|
||||
"""
|
||||
badge_url = f"https://ag.hexor.cy/api/badge?name={app_name}&revision=true"
|
||||
app_url = f"https://ag.hexor.cy/applications/argocd/{app_name}"
|
||||
return f"| **{app_name}** | []({app_url}) |"
|
||||
|
||||
|
||||
def generate_readme_content(apps_by_category: Dict[str, List[str]]) -> str:
|
||||
"""
|
||||
Generate README.md content with all applications.
|
||||
|
||||
Args:
|
||||
apps_by_category: Dictionary with apps grouped by category
|
||||
|
||||
Returns:
|
||||
Complete README.md content
|
||||
"""
|
||||
lines = [
|
||||
"# homelab",
|
||||
"",
|
||||
"ArgoCD homelab project",
|
||||
"",
|
||||
"## ArgoCD Applications Status",
|
||||
"",
|
||||
"<table>",
|
||||
"<tr>",
|
||||
"<td valign=\"top\" width=\"50%\">",
|
||||
"",
|
||||
"### Core Applications",
|
||||
"",
|
||||
"| Application | Status |",
|
||||
"| :--- | :---: |"
|
||||
]
|
||||
|
||||
# Add core applications
|
||||
for app in apps_by_category.get('core', []):
|
||||
lines.append(generate_badge_line(app))
|
||||
|
||||
lines.extend([
|
||||
"",
|
||||
"### Games",
|
||||
"",
|
||||
"| Application | Status |",
|
||||
"| :--- | :---: |"
|
||||
])
|
||||
|
||||
# Add games
|
||||
for app in apps_by_category.get('games', []):
|
||||
lines.append(generate_badge_line(app))
|
||||
|
||||
lines.extend([
|
||||
"</td>",
|
||||
"<td valign=\"top\" width=\"50%\">",
|
||||
"",
|
||||
"### Applications",
|
||||
"",
|
||||
"| Application | Status |",
|
||||
"| :--- | :---: |"
|
||||
])
|
||||
|
||||
# Add applications
|
||||
for app in apps_by_category.get('apps', []):
|
||||
lines.append(generate_badge_line(app))
|
||||
|
||||
lines.extend([
|
||||
"",
|
||||
"</td>",
|
||||
"</tr>",
|
||||
"</table>"
|
||||
])
|
||||
|
||||
return '\n'.join(lines) + '\n'
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: generate-readme.py <k8s-directory> [output-file]")
|
||||
print("Example: generate-readme.py k8s/ README.md")
|
||||
sys.exit(1)
|
||||
|
||||
k8s_path = sys.argv[1]
|
||||
output_file = sys.argv[2] if len(sys.argv) > 2 else "README.md"
|
||||
|
||||
if not os.path.exists(k8s_path):
|
||||
print(f"Error: Directory {k8s_path} does not exist")
|
||||
sys.exit(1)
|
||||
|
||||
print(f"📁 Scanning {k8s_path}...")
|
||||
apps_by_category = scan_k8s_directory(k8s_path)
|
||||
|
||||
# Print statistics
|
||||
total_apps = sum(len(apps) for apps in apps_by_category.values())
|
||||
print(f"✅ Found {total_apps} applications:")
|
||||
for category, apps in apps_by_category.items():
|
||||
if apps:
|
||||
print(f" - {category}: {len(apps)} apps")
|
||||
|
||||
print(f"📝 Generating {output_file}...")
|
||||
readme_content = generate_readme_content(apps_by_category)
|
||||
|
||||
with open(output_file, 'w', encoding='utf-8') as f:
|
||||
f.write(readme_content)
|
||||
|
||||
print(f"✅ {output_file} generated successfully")
|
||||
print(f" Total lines: {len(readme_content.splitlines())}")
|
||||
print(f" File size: {len(readme_content)} bytes")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user