diff --git a/.github/workflows/add_mod_port.yml b/.github/workflows/add_mod_port.yml index 593993b..0fce037 100644 --- a/.github/workflows/add_mod_port.yml +++ b/.github/workflows/add_mod_port.yml @@ -8,6 +8,9 @@ on: mod: description: "Mod ID (as it appears in config.toml)" required: true + modloader: + description: "Mod loader (fabric or neoforge)" + required: true mod_version: description: "Mod version (without v or -MC)" required: true @@ -15,8 +18,8 @@ on: description: "Minecraft version" required: true fapi_version: - description: "Fabric API version" - required: true + description: "Fabric API version (if modloader is fabric)" + required: false file_id: description: "CurseForge file ID" required: true @@ -44,9 +47,10 @@ jobs: run: | python _scripts/add_mod_port.py \ "${{ github.event.inputs.mod }}" \ + "${{ github.event.inputs.modloader }}" \ "${{ github.event.inputs.mod_version }}" \ "${{ github.event.inputs.mc_version }}" \ - "${{ github.event.inputs.fapi_version }}" \ + ${{ github.event.inputs.modloader == 'fabric' && format('--fapi-version {0}', github.event.inputs.fapi_version) || '' }} \ "${{ github.event.inputs.file_id }}" - name: Commit changes @@ -54,8 +58,9 @@ jobs: MOD="${{ github.event.inputs.mod }}" MOD_VERSION="${{ github.event.inputs.mod_version }}" MC_VERSION="${{ github.event.inputs.mc_version }}" + MODLOADER="${{ github.event.inputs.modloader }}" git config --local user.email "contact.wurstimperium@gmail.com" git config --local user.name "Wurst-Bot" git add . - git commit -m "[Wurst-Bot] Port $MOD $MOD_VERSION to Minecraft $MC_VERSION" + git commit -m "[Wurst-Bot] Port $MOD $MOD_VERSION to Minecraft $MC_VERSION ($MODLOADER)" git push diff --git a/scripts/add_mod_port.py b/scripts/add_mod_port.py index f6d7aa7..312e532 100644 --- a/scripts/add_mod_port.py +++ b/scripts/add_mod_port.py @@ -68,7 +68,7 @@ def find_mod_update_post(mod, version): raise ValueError(f"Could not find post for mod {mod} version {version}") -def update_mod_post(mod, mod_version, mc_version): +def update_mod_post(mod, modloader, mod_version, mc_version): """Add a new Minecraft version to a mod update post.""" mc_version_type = version_info[mc_version]["type"] front_matter, post_path = find_mod_update_post(mod, mod_version) @@ -89,6 +89,16 @@ def update_mod_post(mod, mod_version, mc_version): reverse=True, ) + if modloader == "neoforge": + if "neoforge" not in front_matter: + front_matter["neoforge"] = [] + if mc_version not in front_matter["neoforge"]: + front_matter["neoforge"].insert(0, mc_version) + front_matter["neoforge"].sort( + key=lambda v: version_info[v]["releaseTime"], + reverse=True, + ) + write_front_matter(post_path, front_matter) @@ -122,7 +132,7 @@ def update_fabric_api_data(mod, mod_version, mc_version, fapi_version): json.dump(data, f, indent=2) -def update_curseforge_data(mod, mod_version, mc_version, file_id: int, modloader="fabric"): +def update_curseforge_data(mod, modloader, mod_version, mc_version, file_id): """Add a new entry to the CurseForge data file for a mod.""" data_file = os.path.join("data", "curseforge", f"{mod}", f"{modloader}.json") with open(data_file, "r") as f: @@ -132,7 +142,7 @@ def update_curseforge_data(mod, mod_version, mc_version, file_id: int, modloader if mod_version not in data: data[mod_version] = {} if mc_version not in data[mod_version]: - data[mod_version][mc_version] = file_id + data[mod_version][mc_version] = int(file_id) # Sort curseforge IDs by release time and version type for mod_version in data: @@ -174,26 +184,41 @@ def add_download_category(mod, new_mcversion, old_mcversion): write_front_matter(new_page_path, front_matter) +def main(mod, modloader, mod_version, mc_version, fapi_version, file_id): + # Update post + update_mod_post(mod, modloader, mod_version, mc_version) + + # Update data files + update_curseforge_data(mod, modloader, mod_version, mc_version, file_id) + if modloader == "fabric": + update_fabric_api_data(mod, mod_version, mc_version, fapi_version) + + # Add download category + mc_version_type = version_info[mc_version]["type"] + if mc_version_type == "release" and mc_version == manifest["latest"]["release"]: + old_latest = sorted( + [v for v in manifest["versions"] if v["type"] == "release"], + key=lambda v: v["releaseTime"], + reverse=True, + )[1]["id"] + add_download_category(mod, mc_version, old_latest) + + if __name__ == "__main__": parser = ArgumentParser( description="Adds the necessary Hugo metadata when an existing mod update is ported to a new Minecraft version" ) parser.add_argument("mod", help="Mod ID (as it appears in config.toml)") + parser.add_argument("modloader", help="Mod loader (fabric or neoforge)") parser.add_argument("mod_version", help="Mod version (without v or -MC)") parser.add_argument("mc_version", help="Minecraft version") - parser.add_argument("fapi_version", help="Fabric API version") + parser.add_argument("--fapi_version", help="Fabric API version") parser.add_argument("file_id", help="CurseForge file ID") args = parser.parse_args() - update_mod_post(args.mod, args.mod_version, args.mc_version) - update_fabric_api_data(args.mod, args.mod_version, args.mc_version, args.fapi_version) - update_curseforge_data(args.mod, args.mod_version, args.mc_version, args.file_id) + if args.modloader == "fabric" and not args.fapi_version: + parser.error("--fapi-version is required for Fabric builds") - mc_version_type = version_info[args.mc_version]["type"] - if mc_version_type == "release" and args.mc_version == manifest["latest"]["release"]: - old_latest = sorted( - [v for v in manifest["versions"] if v["type"] == "release"], - key=lambda v: v["releaseTime"], - reverse=True, - )[1]["id"] - add_download_category(args.mod, args.mc_version, old_latest) + main( + args.mod, args.modloader, args.mod_version, args.mc_version, args.fapi_version, args.file_id + )