From f320422bafc30684e9fbcabfc8837f0883d0b018 Mon Sep 17 00:00:00 2001 From: Evan Goode Date: Tue, 2 Jul 2024 20:28:18 -0400 Subject: [PATCH] Rebase on PrismLauncher/meta --- .github/workflows/update.yml | 28 ++++++ .gitignore | 1 - config.sh | 11 +++ meta/common/authlib_injector.py | 7 ++ meta/model/__init__.py | 6 ++ meta/run/generate_authlib_injector.py | 135 ++++++++++++++++++++++++++ meta/run/update_authlib_injector.py | 49 ++++++++++ nix/pkgs/blockgame-meta.nix | 2 + poetry.lock | 27 +++++- pyproject.toml | 3 + update.sh | 4 + 11 files changed, 271 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/update.yml create mode 100644 config.sh create mode 100644 meta/common/authlib_injector.py create mode 100755 meta/run/generate_authlib_injector.py create mode 100755 meta/run/update_authlib_injector.py diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml new file mode 100644 index 0000000..6894269 --- /dev/null +++ b/.github/workflows/update.yml @@ -0,0 +1,28 @@ +name: "update" +on: + schedule: + - cron: '0 0 * * *' + workflow_dispatch: + push: + branches: + - main + pull_request: + branches: + - main +jobs: + update: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: cachix/install-nix-action@v20 + with: + github_access_token: ${{ secrets.GITHUB_TOKEN }} + - uses: DeterminateSystems/magic-nix-cache-action@main + - uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: | + ${{ secrets.UPSTREAM_KEY }} + ${{ secrets.LAUNCHER_KEY }} + - run: | + nix shell -c init + nix shell -c update diff --git a/.gitignore b/.gitignore index 7f7232c..6eb78c8 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,5 @@ caches/ !caches/*/.keep cache/ __pycache__ -config.sh launcher upstream diff --git a/config.sh b/config.sh new file mode 100644 index 0000000..0c9bc79 --- /dev/null +++ b/config.sh @@ -0,0 +1,11 @@ +export META_UPSTREAM_URL=git@github.com:unmojang/meta-upstream.git +export META_LAUNCHER_URL=git@github.com:unmojang/meta-launcher.git + +export META_UPSTREAM_DIR=upstream +export META_LAUNCHER_DIR=launcher + +export DEPLOY_TO_GIT=true +export GIT_AUTHOR_NAME="github-actions" +export GIT_AUTHOR_EMAIL="mail@unmojang.org" +export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME" +export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL" diff --git a/meta/common/authlib_injector.py b/meta/common/authlib_injector.py new file mode 100644 index 0000000..78bd956 --- /dev/null +++ b/meta/common/authlib_injector.py @@ -0,0 +1,7 @@ +from os.path import join + +BASE_DIR = "authlib-injector" + +ARTIFACTS_DIR = join(BASE_DIR, "artifacts") + +AGENT_COMPONENT = "moe.yushi.authlibinjector" diff --git a/meta/model/__init__.py b/meta/model/__init__.py index 3d06f99..7fe03e4 100644 --- a/meta/model/__init__.py +++ b/meta/model/__init__.py @@ -291,6 +291,7 @@ class Library(MetaBase): natives: Optional[Dict[str, str]] rules: Optional[MojangRules] url: Optional[str] + absoluteUrl: Optional[str] = Field(None, alias="MMC-absoluteUrl") mmcHint: Optional[str] = Field(None, alias="MMC-hint") @@ -300,6 +301,10 @@ class Dependency(MetaBase): suggests: Optional[str] +class Agent(Library): + argument: Optional[str] + + class MetaVersion(Versioned): name: str version: str @@ -323,6 +328,7 @@ class MetaVersion(Versioned): additional_traits: Optional[List[str]] = Field(alias="+traits") additional_tweakers: Optional[List[str]] = Field(alias="+tweakers") additional_jvm_args: Optional[List[str]] = Field(alias="+jvmArgs") + additional_agents: Optional[List[Agent]] = Field(alias="+agents") class MetaPackage(Versioned): diff --git a/meta/run/generate_authlib_injector.py b/meta/run/generate_authlib_injector.py new file mode 100755 index 0000000..4a5c737 --- /dev/null +++ b/meta/run/generate_authlib_injector.py @@ -0,0 +1,135 @@ +import json +import os + +import dateutil.parser + +from meta.common import ( + ensure_component_dir, + launcher_path, + upstream_path, +) +from meta.common.authlib_injector import BASE_DIR, ARTIFACTS_DIR, AGENT_COMPONENT +from meta.model import Agent, MetaVersion, Library, MetaPackage, GradleSpecifier + +LAUNCHER_DIR = launcher_path() +UPSTREAM_DIR = upstream_path() + +ensure_component_dir(AGENT_COMPONENT) + + +LEGACY_RELEASE_TIMES = { + 1: "2018-06-28T21:14:02+08:00", + 2: "2018-06-28T21:14:02+08:00", + 3: "2018-06-28T21:14:02+08:00", + 4: "2018-06-28T21:14:02+08:00", + 6: "2018-06-28T21:14:02+08:00", + 7: "2018-06-28T21:15:12+08:00", + 8: "2018-06-28T21:26:23+08:00", + 9: "2018-06-28T21:28:04+08:00", + 10: "2018-06-28T21:28:14+08:00", + 11: "2018-06-28T21:28:23+08:00", + 12: "2018-06-28T21:28:29+08:00", + 13: "2018-06-28T21:28:35+08:00", + 14: "2018-06-28T21:28:42+08:00", + 15: "2018-06-28T21:28:49+08:00", + 16: "2018-06-28T21:28:55+08:00", + 17: "2018-06-28T21:29:00+08:00", + 18: "2018-06-29T13:25:41+00:00", + 19: "2018-09-30T13:17:16+00:00", + 20: "2018-10-20T13:43:43+00:00", + 21: "2018-10-20T13:49:31+00:00", + 22: "2018-11-23T16:11:54+00:00", + 23: "2018-11-24T17:16:56+00:00", + 24: "2018-12-31T13:03:32+00:00", + 25: "2019-01-19T15:40:25+00:00", + 26: "2019-02-14T05:26:31+00:00", + 27: "2020-04-10T16:05:12+00:00", + 28: "2020-04-29T02:46:56+00:00", + 29: "2020-06-20T14:30:17Z", + 30: "2020-08-15T03:08:38Z", + 31: "2020-08-23T07:06:55Z", + 32: "2020-08-27T04:21:52Z", + 33: "2020-09-11T23:27:27Z", + 34: "2020-10-17T17:18:31Z", + 35: "2021-05-14T06:55:24Z", + 36: "2021-06-11T10:34:18Z", + 37: "2021-06-11T19:55:54Z", + 38: "2021-06-13T22:05:49Z", + 39: "2021-08-20T20:30:11Z", + 40: "2021-11-18T13:49:40Z", + 41: "2022-03-11T05:48:00Z", + 42: "2022-03-15T18:07:46Z", + 43: "2022-04-20T17:21:18Z", + 44: "2022-05-03T13:42:48Z", + 45: "2022-06-06T18:02:59Z", + 46: "2022-07-02T06:06:24Z", + 47: "2022-07-14T11:37:08Z", + 48: "2022-08-04T16:53:00Z", + 49: "2022-08-05T17:11:21Z", + 50: "2023-03-25T10:42:43Z", + 51: "2023-06-11T18:47:31Z", +} + + +def main(): + latest_version: Optional[str] = None + + with open( + os.path.join(UPSTREAM_DIR, BASE_DIR, "artifacts.json"), "r", encoding="utf-8" + ) as artifacts_file: + artifacts = json.load(artifacts_file) + latest_build = 0 + for artifact_info in artifacts["artifacts"]: + build_number = artifact_info["build_number"] + print(f"Processing agent {build_number}") + with open( + os.path.join(UPSTREAM_DIR, ARTIFACTS_DIR, f"{build_number}.json"), + "r", + encoding="utf-8", + ) as artifact_file: + artifact = json.load(artifact_file) + + version = artifact["version"] + + latest_build = max(latest_build, build_number) + if latest_build == build_number: + latest_version = version + + if "release_time" in artifact: + release_time = dateutil.parser.isoparse(artifact["release_time"]) + elif build_number in LEGACY_RELEASE_TIMES: + release_time = LEGACY_RELEASE_TIMES[build_number] + else: + continue + + v = MetaVersion( + name="authlib-injector", + uid=AGENT_COMPONENT, + version=version, + release_time=release_time, + ) + v.type = "release" + v.additional_agents = [ + Agent( + name=GradleSpecifier( + group="moe.yushi", + artifact="authlibinjector", + version=version, + ), + absoluteUrl=artifact["download_url"], + ) + ] + v.write( + os.path.join(LAUNCHER_DIR, AGENT_COMPONENT, f"{v.version}.json") + ) + + package = MetaPackage(uid=AGENT_COMPONENT, name="authlib-injector") + package.recommended = [latest_version] + package.description = "authlib-injector enables you to build a Minecraft authentication system offering all the features that genuine Minecraft has." + package.project_url = "https://github.com/yushijinhun/authlib-injector" + package.authors = ["Haowei Wen"] + package.write(os.path.join(LAUNCHER_DIR, AGENT_COMPONENT, "package.json")) + + +if __name__ == "__main__": + main() diff --git a/meta/run/update_authlib_injector.py b/meta/run/update_authlib_injector.py new file mode 100755 index 0000000..dd96913 --- /dev/null +++ b/meta/run/update_authlib_injector.py @@ -0,0 +1,49 @@ +import json +import os +import zipfile + +import requests + +from meta.common import ( + upstream_path, + ensure_upstream_dir, + default_session, +) +from meta.common.authlib_injector import BASE_DIR, ARTIFACTS_DIR +from meta.model.fabric import FabricJarInfo + +UPSTREAM_DIR = upstream_path() + +ensure_upstream_dir(BASE_DIR) +ensure_upstream_dir(ARTIFACTS_DIR) + +sess = default_session() + + +def get_json_file(path, url): + with open(path, "w", encoding="utf-8") as f: + r = sess.get(url) + r.raise_for_status() + print(f"AUTHLIB-INJECTOR DEBUG {r.headers}") + version_json = r.json() + json.dump(version_json, f, sort_keys=True, indent=4) + return version_json + + +def main(): + artifacts = get_json_file( + os.path.join(UPSTREAM_DIR, BASE_DIR, "artifacts.json"), + "https://authlib-injector.yushi.moe/artifacts.json", + ) + + for artifact in artifacts["artifacts"]: + build_number = artifact["build_number"] + print(f"Processing artifact {build_number}") + get_json_file( + os.path.join(UPSTREAM_DIR, ARTIFACTS_DIR, f"{build_number}.json"), + f"https://authlib-injector.yushi.moe/artifact/{build_number}.json", + ) + + +if __name__ == "__main__": + main() diff --git a/nix/pkgs/blockgame-meta.nix b/nix/pkgs/blockgame-meta.nix index 8409c37..367bf30 100644 --- a/nix/pkgs/blockgame-meta.nix +++ b/nix/pkgs/blockgame-meta.nix @@ -10,6 +10,7 @@ openssh, packaging, pydantic_1, + python-dateutil, python, rsync, }: @@ -46,6 +47,7 @@ buildPythonApplication { filelock packaging pydantic_1 + python-dateutil ]; postInstall = '' diff --git a/poetry.lock b/poetry.lock index f87bed9..0f0f675 100644 --- a/poetry.lock +++ b/poetry.lock @@ -285,6 +285,20 @@ typing-extensions = ">=4.2.0" dotenv = ["python-dotenv (>=0.10.4)"] email = ["email-validator (>=1.0.3)"] +[[package]] +name = "python-dateutil" +version = "2.9.0.post0" +description = "Extensions to the standard Python datetime module" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" +files = [ + {file = "python-dateutil-2.9.0.post0.tar.gz", hash = "sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3"}, + {file = "python_dateutil-2.9.0.post0-py2.py3-none-any.whl", hash = "sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427"}, +] + +[package.dependencies] +six = ">=1.5" + [[package]] name = "requests" version = "2.32.3" @@ -306,6 +320,17 @@ urllib3 = ">=1.21.1,<3" socks = ["PySocks (>=1.5.6,!=1.5.7)"] use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] +[[package]] +name = "six" +version = "1.16.0" +description = "Python 2 and 3 compatibility utilities" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" +files = [ + {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, + {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, +] + [[package]] name = "typing-extensions" version = "4.11.0" @@ -337,4 +362,4 @@ zstd = ["zstandard (>=0.18.0)"] [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "2a2fe996845675e1cdf7d80834919eabb819353f394f00a3adbaf0f42e7351b0" +content-hash = "f81f2b8ccc78137ad82fa9a022f0444ae272ef0cdf54d2402e511b5840f72af6" diff --git a/pyproject.toml b/pyproject.toml index 10cf5dd..c37c77e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,6 +17,7 @@ generateMojang = "meta.run.generate_mojang:main" generateNeoForge = "meta.run.generate_neoforge:main" generateQuilt = "meta.run.generate_quilt:main" generateJava = "meta.run.generate_java:main" +generateAuthlibInjector = "meta.run.generate_authlib_injector:main" updateFabric = "meta.run.update_fabric:main" updateForge = "meta.run.update_forge:main" updateLiteloader = "meta.run.update_liteloader:main" @@ -24,6 +25,7 @@ updateMojang = "meta.run.update_mojang:main" updateNeoForge = "meta.run.update_neoforge:main" updateQuilt = "meta.run.update_quilt:main" updateJava = "meta.run.update_java:main" +updateAuthlibInjector = "meta.run.update_authlib_injector:main" index = "meta.run.index:main" [tool.poetry.dependencies] @@ -33,6 +35,7 @@ requests = "^2.31.0" filelock = "^3.13.1" packaging = "^24.0" pydantic = "^1.10.13" +python-dateutil = "^2.9.0.post0" [build-system] requires = ["poetry-core>=1.0.0"] diff --git a/update.sh b/update.sh index 8e0fe38..0f38b4f 100755 --- a/update.sh +++ b/update.sh @@ -34,6 +34,7 @@ currentDate=$(date -I) upstream_git reset --hard HEAD || exit 1 +python -m meta.run.update_authlib_injector || fail_in python -m meta.run.update_mojang || fail_in python -m meta.run.update_forge || fail_in python -m meta.run.update_neoforge || fail_in @@ -43,6 +44,7 @@ python -m meta.run.update_liteloader || fail_in python -m meta.run.update_java || fail_in if [ "${DEPLOY_TO_GIT}" = true ]; then + upstream_git add authlib-injector/artifacts/*.json || fail_in upstream_git add mojang/version_manifest_v2.json mojang/java_all.json mojang/versions/* || fail_in upstream_git add forge/*.json forge/version_manifests/*.json forge/installer_manifests/*.json forge/files_manifests/*.json forge/installer_info/*.json || fail_in upstream_git add neoforge/*.json neoforge/version_manifests/*.json neoforge/installer_manifests/*.json neoforge/files_manifests/*.json neoforge/installer_info/*.json || fail_in @@ -58,6 +60,7 @@ fi launcher_git reset --hard HEAD || exit 1 +python -m meta.run.generate_authlib_injector || fail_out python -m meta.run.generate_mojang || fail_out python -m meta.run.generate_forge || fail_out python -m meta.run.generate_neoforge || fail_out @@ -68,6 +71,7 @@ python -m meta.run.generate_java || fail_out python -m meta.run.index || fail_out if [ "${DEPLOY_TO_GIT}" = true ]; then + launcher_git add moe.yushi.authlibinjector/* || fail_out launcher_git add index.json org.lwjgl/* org.lwjgl3/* net.minecraft/* || fail_out launcher_git add net.minecraftforge/* || fail_out launcher_git add net.neoforged/* || fail_out