From 023ceb5d91b4958f2851cbd567be3f9ec713b38a Mon Sep 17 00:00:00 2001 From: Chip Wolf Date: Wed, 12 Nov 2025 20:11:42 +0000 Subject: [PATCH 01/11] Revert "chore(ci): modify README in new mc version workflow (#103)" This reverts commit db2ab3b13ff166028e1f6e2e21ed83b57c3d6f23. --- README.md | 2 +- check-for-new-mc-versions.py | 29 +---------------------------- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index ce608c2..a2d4923 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ jobs: - name: Run MC test client uses: headlesshq/mc-runtime-test@4.1.0 with: - mc: 1.21.5 + mc: 1.21.4 modloader: fabric regex: .*fabric.* mc-runtime-test: fabric diff --git a/check-for-new-mc-versions.py b/check-for-new-mc-versions.py index a90c905..0eacef6 100644 --- a/check-for-new-mc-versions.py +++ b/check-for-new-mc-versions.py @@ -16,32 +16,6 @@ def modify_file(file_path: str, func: Callable[[str], str]): f.write(content) -def modify_readme(last_major: int, last_minor: int, last_patch: int, major: int, minor: int, patch: int) -> str: - file_path = 'README.md' - with open(file_path, "r") as f: - lines = f.readlines() - - out = [] - prev_line = None - for i, line in enumerate(lines): - current_version = f"{major}.{minor}.{patch}" - if prev_line is not None and prev_line.startswith('|-----------------|----------------|----------------|----------------|'): - if last_major != major or last_minor != minor: - out.append(f"| {current_version} | ✔️ | ✔️ | ✔️ |\n") - else: - last_version = f"{last_major}.{last_minor}.{last_patch}" - if f"- {last_version}" in line: - line = line.replace(last_version, current_version) - elif last_version in line: - line = line.replace(last_version, f"{last_version} - {current_version}") - line = re.sub(r'mc:\s*.*', f'mc: {major}.{minor}.{patch}', line) - out.append(line) - prev_line = line - - with open(file_path, "w", encoding="utf-8") as f: - f.writelines(out) - - def modify_forge_mod(content: str, major: int, minor: int) -> str: content = re.sub(r'versionRange = "\[.*,\)"', f'versionRange = "[{major}.{minor}.0,)"', content) return content @@ -67,7 +41,7 @@ def modify_lifecycle(curr_dir: str, latest: str, lex: str): for i, line in enumerate(lines): out.append(line) if line.strip() == "# new-mc-version build data": - out.append(f" {{\"dir\": \"{curr_dir}\", \"mc\": \"{latest}\", \"lex\": \"{lex}\", \"neo\": \"0-beta\", \"java\": \"21\"}},\n") + out.append(f" {{\"dir\": \"{curr_dir}\", \"mc\": \"{latest}\", \"lex\": \"{lex}\", \"neo\": \"1-beta\", \"java\": \"21\"}},\n") elif line.strip() == "# new-mc-version run data": out.append(f" {{\"mc\": \"{latest}\", \"type\": \"lexforge\", \"modloader\": \"forge\", \"regex\": \".*forge.*\", \"java\": \"21\"}},\n") out.append(f" {{\"mc\": \"{latest}\", \"type\": \"neoforge\", \"modloader\": \"neoforge\", \"regex\": \".*neoforge.*\", \"java\": \"21\"}},\n") @@ -158,7 +132,6 @@ def check_latest_mc_version(): curr_dir = prepare_new_dir(curr_dir, latest_release, major, minor, patch, lex) modify_file(__file__, lambda c: modify_script_file(c, curr_dir, major, minor, patch)) modify_lifecycle(curr_dir, latest_release, lex) - modify_readme(current_major, current_minor, current_patch, major, minor, patch) with open(env_file, 'a') as f: f.write(f"LATEST_VERSION={latest_release}\n") f.write(f"LATEST_VERSION_DIR={curr_dir}\n") From e3b3078057b81bfde66f5a5333b112a34653934b Mon Sep 17 00:00:00 2001 From: Chip Wolf Date: Wed, 12 Nov 2025 20:12:19 +0000 Subject: [PATCH 02/11] Revert "chore(ci): Fixed regex for PR comments not matching zeros" This reverts commit 57f85f1b78d237e2c8ff297a4ffea9289e580299. --- .github/workflows/lifecycle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lifecycle.yml b/.github/workflows/lifecycle.yml index ca12792..b9517a1 100644 --- a/.github/workflows/lifecycle.yml +++ b/.github/workflows/lifecycle.yml @@ -197,7 +197,7 @@ jobs: comment_body = os.getenv('PR_COMMENT_BODY') print("PR-comment:", comment_body) if comment_body: - pattern = r'Automatic commit: build and run ([0-9\.]*[0-9]*) in ([0-9_]*[0-9]*)' + pattern = r'Automatic commit: build and run ([1-9\.]*[1-9]*) in ([1-9_]*[1-9]*)' match = re.search(pattern, comment_body) if match: mc_versions = [ match.group(1) ] From 846f8969ba4f823dceb4f104304095ce1610ebb1 Mon Sep 17 00:00:00 2001 From: Chip Wolf Date: Wed, 12 Nov 2025 20:12:36 +0000 Subject: [PATCH 03/11] Revert "chore(ci): Fixed regex for PR comment body matching" This reverts commit 16fc958468d523aba973ddab593c98533fb320ba. --- .github/workflows/lifecycle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lifecycle.yml b/.github/workflows/lifecycle.yml index b9517a1..1ee8014 100644 --- a/.github/workflows/lifecycle.yml +++ b/.github/workflows/lifecycle.yml @@ -197,7 +197,7 @@ jobs: comment_body = os.getenv('PR_COMMENT_BODY') print("PR-comment:", comment_body) if comment_body: - pattern = r'Automatic commit: build and run ([1-9\.]*[1-9]*) in ([1-9_]*[1-9]*)' + pattern = r'Automatic commit: build and run ([1-9\.]*[1-9]) in ([1-9_]*[1-9])' match = re.search(pattern, comment_body) if match: mc_versions = [ match.group(1) ] From 2960687120721f04a30d3c738255edbb76200dd2 Mon Sep 17 00:00:00 2001 From: Chip Wolf Date: Wed, 12 Nov 2025 20:12:52 +0000 Subject: [PATCH 04/11] Revert "chore(ci): log PR comment body matching" This reverts commit f4eb9a2ab47d3f2ad43a3a441c1b4ad476f6d408. --- .github/workflows/lifecycle.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/lifecycle.yml b/.github/workflows/lifecycle.yml index 1ee8014..7bdd94a 100644 --- a/.github/workflows/lifecycle.yml +++ b/.github/workflows/lifecycle.yml @@ -202,9 +202,6 @@ jobs: if match: mc_versions = [ match.group(1) ] dirs_to_filter = [ match.group(2) ] - print('Matched PR body', mc_versions, dirs_to_filter) - else: - print('PR body did not match') case 'workflow_dispatch': input_dirs = '${{ github.event.inputs.dirs }}' From 03f41442ca992aa7f54bdcb678c1c7f2c0bb1d3b Mon Sep 17 00:00:00 2001 From: Chip Wolf Date: Wed, 12 Nov 2025 20:13:04 +0000 Subject: [PATCH 05/11] Revert "chore(ci): use pull_request.body" This reverts commit aeb788619430c892368db5259cd7834af512cc00. --- .github/workflows/lifecycle.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lifecycle.yml b/.github/workflows/lifecycle.yml index 7bdd94a..fc795b3 100644 --- a/.github/workflows/lifecycle.yml +++ b/.github/workflows/lifecycle.yml @@ -79,11 +79,19 @@ jobs: with: filters: | ${{ steps.paths.outputs.filter }} + + - name: Find PR comment + if: github.event_name == 'pull_request' + uses: peter-evans/find-comment@v1 + id: find-comment + with: + issue-number: ${{ github.event.pull_request.number }} + body-includes: "Automatic commit: build and run " - id: matrices # TODO: build origin matrices dynamically, consider collapsing this into a .py name: Construct matrices env: - PR_COMMENT_BODY: ${{ github.event.pull_request.body }} + PR_COMMENT_BODY: ${{ steps.find-comment.outputs.comment-body }} run: | import os import json From fe8421dd604634a2f1cb53a7dde342519f547ea9 Mon Sep 17 00:00:00 2001 From: Chip Wolf Date: Wed, 12 Nov 2025 20:13:19 +0000 Subject: [PATCH 06/11] Revert "chore(ci): use find-comment action to find PR comment (#94)" This reverts commit e9c92e82a6ce0c2cbb747927ef7149848275d9e0. --- .github/workflows/lifecycle.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/lifecycle.yml b/.github/workflows/lifecycle.yml index fc795b3..9d7acac 100644 --- a/.github/workflows/lifecycle.yml +++ b/.github/workflows/lifecycle.yml @@ -79,19 +79,11 @@ jobs: with: filters: | ${{ steps.paths.outputs.filter }} - - - name: Find PR comment - if: github.event_name == 'pull_request' - uses: peter-evans/find-comment@v1 - id: find-comment - with: - issue-number: ${{ github.event.pull_request.number }} - body-includes: "Automatic commit: build and run " - id: matrices # TODO: build origin matrices dynamically, consider collapsing this into a .py name: Construct matrices env: - PR_COMMENT_BODY: ${{ steps.find-comment.outputs.comment-body }} + PR_COMMENT_BODY: ${{ github.event.comment.body }} run: | import os import json From c47835975a35bd6a69db465aed033d22b307ad4e Mon Sep 17 00:00:00 2001 From: Chip Wolf Date: Wed, 12 Nov 2025 20:13:37 +0000 Subject: [PATCH 07/11] Revert "chore(ci): run matrix based on PR message (#92)" This reverts commit f1db09f1c9004671566bbcd48a69a1d1bedadf2c. --- .github/workflows/lifecycle.yml | 16 ++-------------- .github/workflows/new-mc-version.yml | 2 +- check-for-new-mc-versions.py | 6 +++--- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/.github/workflows/lifecycle.yml b/.github/workflows/lifecycle.yml index 9d7acac..222235c 100644 --- a/.github/workflows/lifecycle.yml +++ b/.github/workflows/lifecycle.yml @@ -82,12 +82,9 @@ jobs: - id: matrices # TODO: build origin matrices dynamically, consider collapsing this into a .py name: Construct matrices - env: - PR_COMMENT_BODY: ${{ github.event.comment.body }} run: | import os import json - import re build_matrix = {"include": []} run_matrix = {"version": []} @@ -187,21 +184,12 @@ jobs: ] dirs_to_filter = [] - mc_versions = [] match os.getenv('GITHUB_EVENT_NAME'): case 'pull_request': if "${{ steps.filter.outcome }}" == "success": # Filter matrices based on the detected changes dirs_to_filter = json.loads('${{ steps.filter.outputs.changes }}') - comment_body = os.getenv('PR_COMMENT_BODY') - print("PR-comment:", comment_body) - if comment_body: - pattern = r'Automatic commit: build and run ([1-9\.]*[1-9]) in ([1-9_]*[1-9])' - match = re.search(pattern, comment_body) - if match: - mc_versions = [ match.group(1) ] - dirs_to_filter = [ match.group(2) ] case 'workflow_dispatch': input_dirs = '${{ github.event.inputs.dirs }}' @@ -221,8 +209,8 @@ jobs: build_matrix['include'], run_matrix['version'] = build_data, run_data if dirs_to_filter: - build_matrix['include'].extend([item for item in build_data if item["dir"] in dirs_to_filter and (item["mc"] in mc_versions or not mc_versions)]) - mc_versions = mc_versions if mc_versions else [item.get("mc") for item in build_matrix["include"] if "mc" in item] + build_matrix['include'].extend([item for item in build_data if item["dir"] in dirs_to_filter]) + mc_versions = [item.get("mc") for item in build_matrix["include"] if "mc" in item] run_matrix['version'].extend([item for item in run_data if item["mc"] in mc_versions]) with open(os.environ['GITHUB_OUTPUT'], 'a') as fh: diff --git a/.github/workflows/new-mc-version.yml b/.github/workflows/new-mc-version.yml index b4195a2..0c35865 100644 --- a/.github/workflows/new-mc-version.yml +++ b/.github/workflows/new-mc-version.yml @@ -54,4 +54,4 @@ jobs: token: ${{ secrets.MC_VERSION_WORKFLOW_TOKEN }} branch: version-${{ env.LATEST_VERSION }} title: "feat: ${{ env.LATEST_VERSION }}" - body: "Automatic commit: build and run ${{ env.LATEST_VERSION }} in ${{ env.LATEST_VERSION_DIR }}" + body: "This PR updates files for Minecraft version ${{ env.LATEST_VERSION }}." diff --git a/check-for-new-mc-versions.py b/check-for-new-mc-versions.py index 0eacef6..84c6b42 100644 --- a/check-for-new-mc-versions.py +++ b/check-for-new-mc-versions.py @@ -128,13 +128,13 @@ def check_latest_mc_version(): print("New Release found!") env_file = os.getenv('GITHUB_ENV') if env_file: + with open(env_file, 'a') as f: + f.write(f"LATEST_VERSION={latest_release}\n") if current_major != major or current_minor != minor: curr_dir = prepare_new_dir(curr_dir, latest_release, major, minor, patch, lex) + modify_file(__file__, lambda c: modify_script_file(c, curr_dir, major, minor, patch)) modify_lifecycle(curr_dir, latest_release, lex) - with open(env_file, 'a') as f: - f.write(f"LATEST_VERSION={latest_release}\n") - f.write(f"LATEST_VERSION_DIR={curr_dir}\n") else: raise FileNotFoundError("Failed to find GITHUB_ENV file!") From 04cb39f9874d125327d815f66b27e84326f77432 Mon Sep 17 00:00:00 2001 From: Chip Wolf Date: Wed, 12 Nov 2025 20:13:55 +0000 Subject: [PATCH 08/11] Revert "chore(ci): fix reviewers and syntax in new mc version workflow (#90)" This reverts commit ead39b577dbfcb6eddd6a258adc13940d14dfa0e. --- .github/workflows/new-mc-version.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/new-mc-version.yml b/.github/workflows/new-mc-version.yml index 0c35865..98bf68c 100644 --- a/.github/workflows/new-mc-version.yml +++ b/.github/workflows/new-mc-version.yml @@ -10,7 +10,6 @@ jobs: permissions: contents: write pull-requests: write - actions: write steps: - name: Checkout repository @@ -45,10 +44,9 @@ jobs: if: steps.git-check.outputs.changes == 'true' && env.LATEST_VERSION != '' uses: peter-evans/create-pull-request@v7 with: - # TODO: check if this works from the cron job, but it does not work from workflow_dispatch author: 'github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>' - assignees: okafke - #reviewers: okafke + assignees: [ okafke ] + reviewers: [ okafke ] commit-message: "feat: ${{ env.LATEST_VERSION }}" delete-branch: true token: ${{ secrets.MC_VERSION_WORKFLOW_TOKEN }} From 4c2e14e8e44527c40d6edb6d95dee9efbf3b312d Mon Sep 17 00:00:00 2001 From: Chip Wolf Date: Wed, 12 Nov 2025 20:14:13 +0000 Subject: [PATCH 09/11] Revert "chore(ci): fix new mc version workflow (#88)" This reverts commit 48022a52378d3348559fa541d93b6867211ebe62. --- .github/workflows/new-mc-version.yml | 29 ++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/.github/workflows/new-mc-version.yml b/.github/workflows/new-mc-version.yml index 98bf68c..9deaa8b 100644 --- a/.github/workflows/new-mc-version.yml +++ b/.github/workflows/new-mc-version.yml @@ -14,8 +14,6 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 - with: - token: ${{ secrets.MC_VERSION_WORKFLOW_TOKEN }} - name: Set up Python uses: actions/setup-python@v5 @@ -40,16 +38,23 @@ jobs: echo "changes=false" >> $GITHUB_OUTPUT fi + - name: Create new branch, commit and push + if: steps.git-check.outputs.changes == 'true' + id: push-branch + run: | + BRANCH_NAME="version-${LATEST_VERSION}" + git checkout -b "$BRANCH_NAME" + git add . + git commit -m "feat: ${LATEST_VERSION}" + git push origin "$BRANCH_NAME" + echo "branch=$BRANCH_NAME" >> $GITHUB_OUTPUT + - name: Create Pull Request if: steps.git-check.outputs.changes == 'true' && env.LATEST_VERSION != '' - uses: peter-evans/create-pull-request@v7 + uses: peter-evans/create-pull-request@v6 with: - author: 'github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>' - assignees: [ okafke ] - reviewers: [ okafke ] - commit-message: "feat: ${{ env.LATEST_VERSION }}" - delete-branch: true - token: ${{ secrets.MC_VERSION_WORKFLOW_TOKEN }} - branch: version-${{ env.LATEST_VERSION }} - title: "feat: ${{ env.LATEST_VERSION }}" - body: "This PR updates files for Minecraft version ${{ env.LATEST_VERSION }}." + token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ steps.push-branch.outputs.branch }} + base: main + title: "feat: ${LATEST_VERSION}" + body: "This PR updates files for Minecraft version ${LATEST_VERSION}." From c761bcd3ea7928eb1f3e727d0e1cb1b679b778f9 Mon Sep 17 00:00:00 2001 From: Chip Wolf Date: Wed, 12 Nov 2025 20:14:27 +0000 Subject: [PATCH 10/11] Revert "chore(ci): add requirements.txt" This reverts commit 9967de4383bda07928e1ee93597dcfeaeefcb44d. --- .github/workflows/new-mc-version.yml | 6 +++--- requirements.txt | 5 ----- 2 files changed, 3 insertions(+), 8 deletions(-) delete mode 100644 requirements.txt diff --git a/.github/workflows/new-mc-version.yml b/.github/workflows/new-mc-version.yml index 9deaa8b..06c780f 100644 --- a/.github/workflows/new-mc-version.yml +++ b/.github/workflows/new-mc-version.yml @@ -20,9 +20,9 @@ jobs: with: python-version: "3.11" - - name: Install dependencies - run: | - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + #- name: Install dependencies + # run: | + # if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Run Python script run: python check-for-new-mc-versions.py diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 80e01dd..0000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -certifi==2025.10.5 -charset-normalizer==3.4.4 -idna==3.11 -requests==2.32.5 -urllib3==2.5.0 From 49ab575ddcb753257814c31ce8a3f5bb701844c7 Mon Sep 17 00:00:00 2001 From: Chip Wolf Date: Wed, 12 Nov 2025 20:16:29 +0000 Subject: [PATCH 11/11] Revert "chore(ci): automatic PR when new Mc version is available (#85)" This reverts commit 8d58792e873f5343d49be1b177a1d15d20d72208. --- .github/workflows/lifecycle.yml | 2 - .github/workflows/new-mc-version.yml | 60 ----------- .gitignore | 1 - check-for-new-mc-versions.py | 143 --------------------------- 4 files changed, 206 deletions(-) delete mode 100644 .github/workflows/new-mc-version.yml delete mode 100644 check-for-new-mc-versions.py diff --git a/.github/workflows/lifecycle.yml b/.github/workflows/lifecycle.yml index 222235c..47d4cf4 100644 --- a/.github/workflows/lifecycle.yml +++ b/.github/workflows/lifecycle.yml @@ -91,7 +91,6 @@ jobs: build_data = [ {"dir": "api", "java": "8"}, - # new-mc-version build data {"dir": "1_21_10", "mc": "1.21.10", "lex": "60.0.0", "neo": "50-beta", "java": "21"}, {"dir": "1_21_6", "mc": "1.21.8", "lex": "58.0.0", "neo": "51", "java": "21"}, {"dir": "1_21_6", "mc": "1.21.7", "lex": "57.0.0", "neo": "25-beta", "java": "21"}, @@ -120,7 +119,6 @@ jobs: ] run_data = [ - # new-mc-version run data {"mc": "1.21.10", "type": "lexforge", "modloader": "forge", "regex": ".*forge.*", "java": "21"}, {"mc": "1.21.10", "type": "neoforge", "modloader": "neoforge", "regex": ".*neoforge.*", "java": "21"}, {"mc": "1.21.10", "type": "fabric", "modloader": "fabric", "regex": ".*fabric.*", "java": "21"}, diff --git a/.github/workflows/new-mc-version.yml b/.github/workflows/new-mc-version.yml deleted file mode 100644 index 06c780f..0000000 --- a/.github/workflows/new-mc-version.yml +++ /dev/null @@ -1,60 +0,0 @@ -name: Check for new mc version -on: - workflow_dispatch: - schedule: - - cron: "0 0 * * *" - -jobs: - check-for-new-mc-version: - runs-on: ubuntu-latest - permissions: - contents: write - pull-requests: write - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: "3.11" - - #- name: Install dependencies - # run: | - # if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - - name: Run Python script - run: python check-for-new-mc-versions.py - - - name: Check for changes - id: git-check - run: | - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - if [[ -n "$(git status --porcelain)" ]]; then - echo "changes=true" >> $GITHUB_OUTPUT - else - echo "changes=false" >> $GITHUB_OUTPUT - fi - - - name: Create new branch, commit and push - if: steps.git-check.outputs.changes == 'true' - id: push-branch - run: | - BRANCH_NAME="version-${LATEST_VERSION}" - git checkout -b "$BRANCH_NAME" - git add . - git commit -m "feat: ${LATEST_VERSION}" - git push origin "$BRANCH_NAME" - echo "branch=$BRANCH_NAME" >> $GITHUB_OUTPUT - - - name: Create Pull Request - if: steps.git-check.outputs.changes == 'true' && env.LATEST_VERSION != '' - uses: peter-evans/create-pull-request@v6 - with: - token: ${{ secrets.GITHUB_TOKEN }} - branch: ${{ steps.push-branch.outputs.branch }} - base: main - title: "feat: ${LATEST_VERSION}" - body: "This PR updates files for Minecraft version ${LATEST_VERSION}." diff --git a/.gitignore b/.gitignore index 341f238..10db306 100644 --- a/.gitignore +++ b/.gitignore @@ -41,4 +41,3 @@ replay_*.log /libs/ /logs/ /.architectury-transformer/ -/.venv/ diff --git a/check-for-new-mc-versions.py b/check-for-new-mc-versions.py deleted file mode 100644 index 84c6b42..0000000 --- a/check-for-new-mc-versions.py +++ /dev/null @@ -1,143 +0,0 @@ -import os -import re -import shutil -from typing import Callable - -import requests - - -def modify_file(file_path: str, func: Callable[[str], str]): - with open(file_path, "r") as f: - content = f.read() - - content = func(content) - - with open(file_path, "w") as f: - f.write(content) - - -def modify_forge_mod(content: str, major: int, minor: int) -> str: - content = re.sub(r'versionRange = "\[.*,\)"', f'versionRange = "[{major}.{minor}.0,)"', content) - return content - - -def modify_fabric_mod_json(content: str, major: int, minor: int) -> str: - content = re.sub(r'"minecraft": "~.*",', f'"minecraft": "~{major}.{minor}.0",', content) - return content - - -def modify_gradle_properties(content: str, latest: str, lex: str) -> str: - content = re.sub(r'minecraft_version\s*=\s*.*', f'minecraft_version = {latest}', content) - content = re.sub(r'lexforge_version\s*=\s*.*', f'lexforge_version = {lex}', content) - return content - - -def modify_lifecycle(curr_dir: str, latest: str, lex: str): - lifecycle_yml = '.github/workflows/lifecycle.yml' - with open(lifecycle_yml, "r", encoding="utf-8") as f: - lines = f.readlines() - - out = [] - for i, line in enumerate(lines): - out.append(line) - if line.strip() == "# new-mc-version build data": - out.append(f" {{\"dir\": \"{curr_dir}\", \"mc\": \"{latest}\", \"lex\": \"{lex}\", \"neo\": \"1-beta\", \"java\": \"21\"}},\n") - elif line.strip() == "# new-mc-version run data": - out.append(f" {{\"mc\": \"{latest}\", \"type\": \"lexforge\", \"modloader\": \"forge\", \"regex\": \".*forge.*\", \"java\": \"21\"}},\n") - out.append(f" {{\"mc\": \"{latest}\", \"type\": \"neoforge\", \"modloader\": \"neoforge\", \"regex\": \".*neoforge.*\", \"java\": \"21\"}},\n") - out.append(f" {{\"mc\": \"{latest}\", \"type\": \"fabric\", \"modloader\": \"fabric\", \"regex\": \".*fabric.*\", \"java\": \"21\"}},\n") - - with open(lifecycle_yml, "w", encoding="utf-8") as f: - f.writelines(out) - - -def modify_script_file(content: str, curr_dir: str, major: int, minor: int, patch: int) -> str: - content = re.sub(r'current_major\s*=\s*\d+', f'current_major = {major}', content) - content = re.sub(r'current_minor\s*=\s*\d+', f'current_minor = {minor}', content) - content = re.sub(r'current_patch\s*=\s*\d+', f'current_patch = {patch}', content) - content = re.sub(r'curr_dir\s*=\s*[\'"][^\'"]*[\'"]', f'curr_dir = \'{curr_dir}\'', content) - return content - - -def prepare_new_dir(curr_dir: str, latest: str, major: int, minor: int, patch: int, lex: str) -> str: - new_dir = f"{major}_{minor}" - shutil.copytree(curr_dir, new_dir, dirs_exist_ok=True) - - modify_file(os.path.join(new_dir, 'gradle.properties'), - lambda c: modify_gradle_properties(c, latest, lex)) - modify_file(os.path.join(new_dir, 'src', 'fabric', 'resources', 'fabric.mod.json'), - lambda c: modify_fabric_mod_json(c, major, minor)) - modify_file(os.path.join(new_dir, 'src', 'lexforge', 'resources', 'META-INF', 'mods.toml'), - lambda c: modify_forge_mod(c, major, minor)) - modify_file(os.path.join(new_dir, 'src', 'neoforge', 'resources', 'META-INF', 'neoforge.mods.toml'), - lambda c: modify_forge_mod(c, major, minor)) - - return new_dir - - -def get_lexforge_version(mc_version: str) -> str: - url = 'https://meta.prismlauncher.org/v1/net.minecraftforge/index.json' - response = requests.get(url) - data = response.json() - ''' - "versions": [ - { - "recommended": false, - "releaseTime": "2025-11-10T19:31:26+00:00", - "requires": [ - { - "equals": "1.21.10", - "uid": "net.minecraft" - } - ], - "sha256": "1562b8e42aae92b8b8f502b392841f3107e407257d14e419842660d8d51db26e", - "version": "60.0.18" - }, - ''' - for version in data['versions']: - for require in version['requires']: - if require['equals'] == mc_version and require['uid'] == 'net.minecraft': - return version['version'] - - raise Exception(f"Failed to find Lexforge version for {mc_version}") - - -def check_latest_mc_version(): - url = 'https://piston-meta.mojang.com/mc/game/version_manifest_v2.json' - current_major = 1 - current_minor = 21 - current_patch = 10 - curr_dir = '1_21_10' - - response = requests.get(url) - data = response.json() - - latest_release = data['latest']['release'] # (1.21.5) - print("Latest Release", latest_release) - major_minor_patch = latest_release.split('.') # (1, 21, 5) or (1, 21) - if len(major_minor_patch) < 2: - raise Exception(major_minor_patch, "Length < 2") - elif len(major_minor_patch) > 3: - raise Exception(major_minor_patch, "Length > 3") - - major = int(major_minor_patch[0]) - minor = int(major_minor_patch[1]) - patch = 0 if len(major_minor_patch) < 3 else int(major_minor_patch[2]) - if current_major != major or current_minor != minor or current_patch != patch: - lex = get_lexforge_version(latest_release) - print("New Release found!") - env_file = os.getenv('GITHUB_ENV') - if env_file: - with open(env_file, 'a') as f: - f.write(f"LATEST_VERSION={latest_release}\n") - if current_major != major or current_minor != minor: - curr_dir = prepare_new_dir(curr_dir, latest_release, major, minor, patch, lex) - - modify_file(__file__, lambda c: modify_script_file(c, curr_dir, major, minor, patch)) - modify_lifecycle(curr_dir, latest_release, lex) - else: - raise FileNotFoundError("Failed to find GITHUB_ENV file!") - - -if __name__ == '__main__': - check_latest_mc_version()