Skip to content

Commit

Permalink
adding generation scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
GitPaulo committed Nov 13, 2024
1 parent 109d929 commit 04686a2
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: 📦 Update Plugin Repo JSON

on:
workflow_dispatch: # Allows manual triggering
schedule:
- cron: '0 0 * * *' # Runs daily at midnight (adjust as needed)

jobs:
update-plugin-repo:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests
- name: Run script to update repo.json and README
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: python generate_repo.py

- name: Commit and push changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add pluginmaster.json README.md
git commit -m "Automated update of pluginmaster.json and README"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# DalamudRepo
Generated repo for my FFXIV Dalamud plugins

## Plugins

| Name | Description | Version | Last Updated |
|------|-------------|---------|--------------|
| Combat Headgear | Toggle headgear visibility in and out of combat. | 2.0.0 | 2024-11-13 |
| Right Click Search Info | Rich click a player and view their search info and more. | 2.0.0 | 2024-11-13 |

83 changes: 83 additions & 0 deletions generate_repo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import os
import json
import requests
import re
from time import time, strftime, gmtime

GITHUB_USERNAME = 'GitPaulo'
GITHUB_API_TOKEN = os.getenv('GITHUB_TOKEN')
HEADERS = {'Authorization': f'token {GITHUB_API_TOKEN}'}

# GitHub API URL to list all repos for a user
REPO_SEARCH_API_URL = f'https://api.github.com/users/{GITHUB_USERNAME}/repos'
REPO_JSON_URL = 'https://raw.githubusercontent.com/{}/{}/master/repo.json'
README_FILE = 'README.md'

def main():
# Fetch all repos with "dalamud" tag
dalamud_repos = get_dalamud_repos()
# Process each repo and aggregate the plugin data
master_manifest = [fetch_repo_json(repo) for repo in dalamud_repos if repo]
master_manifest = [manifest for manifest in master_manifest if manifest] # Filter out None entries

# Write the consolidated repo JSON file
write_master_json(master_manifest)

# Generate and update the markdown table in README
update_readme_with_table(master_manifest)

def get_dalamud_repos():
response = requests.get(REPO_SEARCH_API_URL, headers=HEADERS)
response.raise_for_status()
repos = response.json()
return [repo for repo in repos if 'dalamud' in repo.get('topics', [])]

def fetch_repo_json(repo):
repo_name = repo['name']
repo_json_url = REPO_JSON_URL.format(GITHUB_USERNAME, repo_name)

response = requests.get(repo_json_url, headers=HEADERS)
if response.status_code != 200:
print(f"Error fetching repo.json for {repo_name}: {response.status_code}")
return None

try:
manifest = response.json()[0] # Each repo.json is expected to be a list; take the first entry
except (json.JSONDecodeError, IndexError) as e:
print(f"Error parsing JSON for {repo_name}: {e}")
return None

# Add last update time (ISO format)
manifest['LastUpdate'] = strftime("%Y-%m-%d", gmtime(time()))

return manifest

def write_master_json(master):
with open('pluginmaster.json', 'w') as f:
json.dump(master, f, indent=4)

def update_readme_with_table(master_manifest):
# Generate the markdown table for plugins
table = "| Name | Description | Version | Last Updated |\n"
table += "|------|-------------|---------|--------------|\n"
for plugin in master_manifest:
table += f"| {plugin['Name']} | {plugin['Description']} | {plugin['AssemblyVersion']} | {plugin['LastUpdate']} |\n"

# Load README file and update the ## Plugins section
with open(README_FILE, 'r') as f:
readme_content = f.read()

# Regex to find the Plugins section and replace it with the new table
new_content = re.sub(
r"(## Plugins\s*\n)(.*?)(\n##|$)",
rf"\1{table}\3",
readme_content,
flags=re.DOTALL
)

# Write updated content back to README file
with open(README_FILE, 'w') as f:
f.write(new_content)

if __name__ == '__main__':
main()
52 changes: 52 additions & 0 deletions pluginmaster.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[
{
"Author": "GitPaulo",
"Name": "Combat Headgear",
"Description": "Toggle headgear visibility in and out of combat.",
"InternalName": "CombatHeadgear",
"AssemblyVersion": "2.0.0",
"RepoUrl": "https://github.com/GitPaulo/CombatHeadgear",
"IconUrl": "https://raw.githubusercontent.com/GitPaulo/CombatHeadgear/master/Data/icon.png",
"ApplicableVersion": "any",
"Tags": [
"dalamud",
"headgear",
"visibility",
"combat",
"GitPaulo",
"artin"
],
"DalamudApiLevel": 10,
"IsHide": "False",
"IsTestingExclusive": "False",
"DownloadLinkInstall": "https://github.com/GitPaulo/CombatHeadgear/releases/download/2.0.0/CombatHeadgearPlugin.zip",
"DownloadLinkTesting": "https://github.com/GitPaulo/CombatHeadgear/releases/download/2.0.0/CombatHeadgearPlugin.zip",
"DownloadLinkUpdate": "https://github.com/GitPaulo/CombatHeadgear/releases/download/2.0.0/CombatHeadgearPlugin.zip",
"LastUpdate": "2024-11-13"
},
{
"Author": "GitPaulo",
"Name": "Right Click Search Info",
"Description": "Rich click a player and view their search info and more.",
"InternalName": "RightClickSearchInfo",
"AssemblyVersion": "2.0.0",
"RepoUrl": "https://github.com/GitPaulo/RightClickSearchInfo",
"IconUrl": "https://raw.githubusercontent.com/GitPaulo/RightClickSearchInfo/master/Data/icon.png",
"ApplicableVersion": "any",
"Tags": [
"dalamud",
"search",
"info",
"lodestone",
"GitPaulo",
"artin"
],
"DalamudApiLevel": 10,
"IsHide": "False",
"IsTestingExclusive": "False",
"DownloadLinkInstall": "https://github.com/GitPaulo/RightClickSearchInfo/releases/download/2.0.0/RightClickSearchInfo.zip",
"DownloadLinkTesting": "https://github.com/GitPaulo/RightClickSearchInfo/releases/download/2.0.0/RightClickSearchInfo.zip",
"DownloadLinkUpdate": "https://github.com/GitPaulo/RightClickSearchInfo/releases/download/2.0.0/RightClickSearchInfo.zip",
"LastUpdate": "2024-11-13"
}
]
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests

0 comments on commit 04686a2

Please sign in to comment.