Skip to content

Commit

Permalink
Add NeoForge support to add_mod_port workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed Dec 9, 2024
1 parent 2cf580f commit 9a5d2bb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 19 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/add_mod_port.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ 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
mc_version:
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
Expand Down Expand Up @@ -44,18 +47,20 @@ 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
run: |
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 "[email protected]"
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
55 changes: 40 additions & 15 deletions scripts/add_mod_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)


Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
)

0 comments on commit 9a5d2bb

Please sign in to comment.