#!/usr/bin/env python3 import os import re def parse_action_yml(file_path): name = "" description = "" with open(file_path, "r", encoding="utf-8") as f: for line in f: # Only match top-level keys (no indentation) if line and not line.startswith(" ") and not line.startswith("\t"): line_stripped = line.strip() if line_stripped.startswith("name:"): name = line_stripped.split("name:", 1)[1].strip().strip("'\"") elif line_stripped.startswith("description:"): description = line_stripped.split("description:", 1)[1].strip().strip("'\"") return name, description def main(): repo_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) readme_path = os.path.join(repo_root, "README.md") actions = [] for entry in sorted(os.listdir(repo_root)): entry_path = os.path.join(repo_root, entry) if os.path.isdir(entry_path) and not entry.startswith('.'): for filename in ["action.yml", "action.yaml"]: action_yml = os.path.join(entry_path, filename) if os.path.exists(action_yml): name, desc = parse_action_yml(action_yml) actions.append({ "dir": entry, "name": name or entry, "description": desc or "No description provided." }) break # Build Markdown Table table_lines = [ "| Action | Description | Reference |", "| :--- | :--- | :--- |" ] for action in actions: ref = f"`rodydavis/shared-actions/{action['dir']}@main`" link = f"[{action['name']}](./{action['dir']})" table_lines.append(f"| {link} | {action['description']} | {ref} |") table_content = "\n".join(table_lines) # Update README with open(readme_path, "r", encoding="utf-8") as f: readme_content = f.read() pattern = r"().*?()" replacement = f"\\1\n\n{table_content}\n\n\\2" new_readme_content = re.sub(pattern, replacement, readme_content, flags=re.DOTALL) with open(readme_path, "w", encoding="utf-8") as f: f.write(new_readme_content) print("README.md updated successfully!") if __name__ == "__main__": main()