diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d2f266..c8e5e61 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,14 +40,15 @@ jobs: with: commit_message: "[ci] auto-format" branch: ${{ github.head_ref }} - - - name: Apply Version Metadata + - name: Apply Plugin Metadata run: | - LAST_SHORTEN_COMMIT_HASH=$(git log --pretty=format:'%h' -n 1) LAST_COMMIT_HASH=$(git log --pretty=format:'%H' -n 1) CHANGED_FILES=$(git diff-tree --no-commit-id --name-only -r "$LAST_COMMIT_HASH") - echo CHANGED_FILES - python test/auto_apply_version_metadata.py "$LAST_SHORTEN_COMMIT_HASH" "$CHANGED_FILES" + python test/auto_apply_plugin_metadata.py "$CHANGED_FILES" + + - name: Apply Version Metadata + run: | + python test/auto_apply_version_metadata.py $(git log --pretty=format:'%h' -n 1) - name: Commit Version Metadata uses: stefanzweifel/git-auto-commit-action@v5 diff --git a/plugins/minigames/air_soccer.py b/plugins/minigames/air_soccer.py index 3ffdeb5..746909c 100644 --- a/plugins/minigames/air_soccer.py +++ b/plugins/minigames/air_soccer.py @@ -1,6 +1,5 @@ # Released under the MIT License. See LICENSE for details. # BY Stary_Agent -# """Hockey game and support classes.""" # ba_meta require api 9 diff --git a/plugins/utilities/discord_richpresence.py b/plugins/utilities/discord_richpresence.py index 28e2225..46dbb57 100644 --- a/plugins/utilities/discord_richpresence.py +++ b/plugins/utilities/discord_richpresence.py @@ -4,7 +4,8 @@ # ba_meta require api 9 #!"Made to you by @brostos & @Dliwk" -# +# TODO +# - Update to the latest libs from __future__ import annotations @@ -1249,4 +1250,4 @@ class DiscordRP(babase.Plugin): self.rpc_thread.presence() except Exception as e: # raise (e) - pass + pass \ No newline at end of file diff --git a/test/auto_apply_plugin_metadata.py b/test/auto_apply_plugin_metadata.py new file mode 100644 index 0000000..58633fb --- /dev/null +++ b/test/auto_apply_plugin_metadata.py @@ -0,0 +1,52 @@ +import ast +import json +import sys + +def update_plugin_json(plugin_info, category): + name = next(iter(plugin_info)) + details = plugin_info[name] + + with open(f"{category}.json",'r+') as file: + data = json.load(file) + try: + # Check if plugin is already in the json + data['plugins'][name] + plugman_version = int(next(iter(data["plugins"][name]["versions"])).replace('.', '')) + current_version = int(next(iter(details["versions"])).replace('.', '')) + # `or` In case another change was made on the plugin while still on pr + if current_version > plugman_version or current_version == plugman_version: + data[name][details]["versions"][next(iter(details["versions"]))] = None + elif current_version < plugman_version: + raise Exception('Version cant be lower than the previous') + except KeyError: + data["plugins"][name] = details + file.seek(0) + json.dump(data, file, indent = 2, ensure_ascii=False) + # Ensure old content is removed + file.truncate() + +def extract_ba_plugman(plugins: str) -> dict | list: + for plugin in plugins: + if "plugins/" in plugin: + # Split the path and get the part after 'plugins/' + parts = plugin.split("plugins/")[1].split("/") + category = parts[0] # First part after plugins/ + + with open(plugin, "r") as f: + tree = ast.parse(f.read()) + + for node in ast.walk(tree): + if isinstance(node, ast.Assign): + # Check if the assignment matches our variable name + if len(node.targets) == 1 and getattr(node.targets[0], "id", None) == 'ba_plugman': + # Convert AST node to a Python object safely + # return ast.literal_eval(node.value) + update_plugin_json(ast.literal_eval(node.value), category) + break + else: + raise ValueError(f"Variable ba_plugman not found.") + +if __name__ == "__main__": + plugins = sys.argv + extract_ba_plugman(plugins) + \ No newline at end of file