pacu icon indicating copy to clipboard operation
pacu copied to clipboard

GitHub Action to update the modules Wiki

Open DaveYesland opened this issue 3 years ago • 2 comments

When a new module is added or changed it would be nice to just run a GitHub Action that updates the module details section of the Pacu Wiki. Code is below on how this might be done.

import os
import importlib
from pathlib import Path
​
cat_set = set()
text_list = []
current_directory = os.getcwd()
for root, directories, files in os.walk(Path(__file__).parent/'pacu/modules'):
    modules_directory_path = os.path.realpath(Path(__file__).parent/'pacu/modules')
    specific_module_directory = os.path.realpath(root)
​
    # Skip any directories inside module directories.
    if os.path.dirname(specific_module_directory) != modules_directory_path:
        continue
    # Skip the root directory.
    elif modules_directory_path == specific_module_directory:
        continue
​
    module_name = os.path.basename(root)
​
    for file in files:
        if file == 'main.py':
            # Make sure the format is correct
            module_path = str(Path('pacu/modules')/module_name/'main').replace('/', '.').replace('\\', '.')
            # Import the help function from the module
            module = __import__(module_path, globals(), locals(), ['module_info'], 0)
            importlib.reload(module)
            cat_set.add(module.module_info['category'])
            text_list += [{"cat":module.module_info['category'],"text":f"### {module.module_info['name']}\n> **{module.module_info['one_liner']}**\n\n{module.module_info['description']}\n\n"}]
for cat in cat_set:
    print(f"## {cat}")
    for text in text_list:
        if text["cat"] == cat:
            print(text["text"])

This just prints out the MD formatted text with all the modules and descriptions to match the current wiki format.

DaveYesland avatar Aug 19 '21 18:08 DaveYesland

Note to self: One thing to look into though is if the token included during runs has the ability to make changes to the wiki.

RyanJarv avatar Sep 01 '21 19:09 RyanJarv

This might be helpful https://github.community/t/how-to-updade-repo-wiki-from-github-actions/121151

DaveYesland avatar Sep 01 '21 20:09 DaveYesland