Nattiden пре 2 година
родитељ
комит
27834045b9
2 измењених фајлова са 70 додато и 0 уклоњено
  1. 21 0
      .github/workflows/check_mcv.yml
  2. 49 0
      Actions/check_mcv.py

+ 21 - 0
.github/workflows/check_mcv.yml

@@ -0,0 +1,21 @@
+name: Check Minecraft Version
+on:
+   schedule:
+    - cron:  '0/20 * * * *'
+jobs:
+   check_mcv:
+   strategy:
+      runs-on: ubuntu-latest
+      steps:
+       - name: 签出储存库
+         uses: actions/checkout@v4
+       - name: 配置 Python 环境
+         uses: actions/setup-python@v4
+         with:
+           python-version: 3.11
+       - name: 安装依赖
+         run: |
+            python -m pip install --upgrade pip
+            pip install requests && pip install json
+       - name: 运行更新脚本
+         run: python Actions/check_mcv.py

+ 49 - 0
Actions/check_mcv.py

@@ -0,0 +1,49 @@
+# https://piston-meta.mojang.com/mc/game/version_manifest.json
+import json
+import requests
+import re
+import os
+
+LAUNCHER_MANIFSET_URL = 'https://piston-meta.mojang.com/mc/game/version_manifest.json'
+
+SNAPSHOT_PATTERN = re.compile(r'^[0-9]{2}[w|W][0-9]{2}[A-Fa-f]$')
+PRE_RELEASE_PATTERN = re.compile(r'^.*-pre[0-9]+$')
+RELEASE_CANDIDATE_PATTERN = re.compile(r'^.*-rc[0-9]+$')
+RELEASE_PATTERN = re.compile(r'^1\.[0-9]+(\.[0-9]+)?$')
+
+def get_version_type(vid:str):
+    if re.match(SNAPSHOT_PATTERN,vid):
+        return 'Snapshot'
+    if re.match(PRE_RELEASE_PATTERN,vid):
+        return 'Pre-Release'
+    if re.match(RELEASE_CANDIDATE_PATTERN,vid):
+        return 'Release-Candidate'
+    if re.match(RELEASE_PATTERN,vid):
+        return 'Release'
+    return ''
+
+def update_library(version_libloc:str,ver_type:str,ver_id:str):
+    if os.path.exists(f'{version_libloc}{ver_type}{os.sep}{ver_id}.md'):
+        print(f'- {ver_id:} 已存在于版本库,无需更改') 
+
+try:
+    response = requests.get(LAUNCHER_MANIFSET_URL)
+    version_mainfest = json.loads(response.content)
+except Exception as e:
+    print(f'获取版本列表失败:{e.with_traceback()}')
+    exit(1)
+
+latest_snapshot_id = version_mainfest['latest']['snapshot']
+latest_release_id = version_mainfest['latest']['release']
+
+latest_snapshot_type = get_version_type(latest_snapshot_id)
+latest_release_type = get_version_type(latest_release_id)
+
+print(f'● 最新 {latest_release_type} 版: {latest_release_id}') 
+print(f'● 最新 {latest_snapshot_type} 版: {latest_snapshot_id}') 
+
+dir_location = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+version_lib_location = f'{dir_location}{os.sep}Libraries{os.sep}Versions{os.sep}'
+
+update_library(version_lib_location,latest_release_type,latest_release_id)
+update_library(version_lib_location,latest_snapshot_type,latest_snapshot_id)