diff --git a/.github/workflows/lifecycle.yml b/.github/workflows/lifecycle.yml index ca12792..47d4cf4 100644 --- a/.github/workflows/lifecycle.yml +++ b/.github/workflows/lifecycle.yml @@ -82,19 +82,15 @@ jobs: - 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 }} run: | import os import json - import re build_matrix = {"include": []} run_matrix = {"version": []} 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"}, @@ -123,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"}, @@ -187,24 +182,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 ([0-9\.]*[0-9]*) in ([0-9_]*[0-9]*)' - match = re.search(pattern, comment_body) - 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 }}' @@ -224,8 +207,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 deleted file mode 100644 index b4195a2..0000000 --- a/.github/workflows/new-mc-version.yml +++ /dev/null @@ -1,57 +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 - actions: write - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - token: ${{ secrets.MC_VERSION_WORKFLOW_TOKEN }} - - - 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 Pull Request - 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 - 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: "Automatic commit: build and run ${{ env.LATEST_VERSION }} in ${{ env.LATEST_VERSION_DIR }}" 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/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 deleted file mode 100644 index a90c905..0000000 --- a/check-for-new-mc-versions.py +++ /dev/null @@ -1,170 +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_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 - - -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\": \"0-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: - 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) - 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") - else: - raise FileNotFoundError("Failed to find GITHUB_ENV file!") - - -if __name__ == '__main__': - check_latest_mc_version() 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