Parcourir la source

update action

Nattiden il y a 2 ans
Parent
commit
b57115f9dd
2 fichiers modifiés avec 42 ajouts et 19 suppressions
  1. 23 14
      .github/workflows/check_mcversion.yml
  2. 19 5
      Actions/check_mcv.py

+ 23 - 14
.github/workflows/check_mcversion.yml

@@ -10,29 +10,38 @@ jobs:
       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
+       - name: 运行更新脚本
+         id: run_script
+         run: |
+            python Actions/check_mcv.py >> "$GITHUB_ENV"
+            printf '● 最新 %s 版:%s %s\n' "$latest_release_type" "$latest_release_id" "latest_release_act"
+            printf '● 最新 %s 版:%s %s\n' "$latest_snapshot_type" "$latest_snapshot_id" "latest_snapshot_act"
        - name: 配置 Git 信息
+         if: ${{ env.require_update == true }}
          run: |
             git config --local user.email "[email protected]"
             git config --local user.name "Hilda Bot"
        - name: 配置 GPG 信息
+         if: ${{ env.require_update == true }}
          uses: crazy-max/ghaction-import-gpg@v6
          with:
             gpg_private_key: ${{ secrets.BOT_GPG_PRIVATE_KEY }}
             git_user_signingkey: true
             git_commit_gpgsign: true
-       - name: 配置 Python 环境
-         uses: actions/setup-python@v4
-         with:
-           python-version: 3.11
-       - name: 安装依赖
-         run: |
-            python -m pip install --upgrade pip
-            pip install requests
-       - name: 运行更新脚本
-         run: python Actions/check_mcv.py
-       - name: 提交更改
+       - name: 提交与推送更改
+         if: ${{ env.require_update == true }}
          run: |
             git add *
-            git diff-index --quiet HEAD || git commit -S -m "preloaded new version"
-       - name: 推送更改
-         run: git push
+            git diff-index --quiet HEAD || git commit -S -m "preloaded new version" && git push
+       - name: 显示报错信息
+         if: ${{ failure() && steps.run_script.conclusion == 'failure' }}
+         run: |
+            printf '获取版本列表失败: %s' "$error_log" 

+ 19 - 5
Actions/check_mcv.py

@@ -12,6 +12,8 @@ RELEASE_PATTERN = re.compile(r'^1\.[0-9]+(\.[0-9]+)?$')
 
 INIT_MARKDOWN = '---\nversion-image-link: https://example.com\nnot_finished: true\n---\n'
 
+require_update = False
+
 def get_version_type(vid:str):
     if re.match(SNAPSHOT_PATTERN,vid):
         return 'Snapshot'
@@ -26,16 +28,18 @@ def get_version_type(vid:str):
 def update_library(version_libloc:str,ver_type:str,ver_id:str):
     filepath = f'{version_libloc}{ver_type}{os.sep}{ver_id}.md'
     if os.path.exists(filepath):
-        print(f'- {ver_id:} 已存在于版本库,无需更改') 
+        return False,'存在于版本库,无需更改'
     else:
         with open(filepath, "w") as file:
             file.write(INIT_MARKDOWN)
+        require_update = True
+        return True,'版本库内未找到,已添加'
 
 try:
     response = requests.get(LAUNCHER_MANIFSET_URL)
     version_mainfest = json.loads(response.content)
 except Exception as e:
-    print(f'获取版本列表失败:{e.with_traceback()}')
+    print(f'error_log={e.with_traceback()}')
     exit(1)
 
 latest_snapshot_id = version_mainfest['latest']['snapshot']
@@ -44,11 +48,21 @@ 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}') 
+#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}'
 
+release_require_update,latest_release_act = \
 update_library(version_lib_location,latest_release_type,latest_release_id)
-update_library(version_lib_location,latest_snapshot_type,latest_snapshot_id)
+snapshot_require_update,latest_snapshot_act = \
+update_library(version_lib_location,latest_snapshot_type,latest_snapshot_id)
+
+print(f'latest_release_type={latest_release_type}')
+print(f'latest_snapshot_type={latest_snapshot_type}')
+print(f'latest_release_id={latest_release_id}')
+print(f'latest_snapshot_id={latest_snapshot_id}')
+print(f'latest_release_act={latest_release_act}')
+print(f'latest_snapshot_act={latest_snapshot_act}')
+print(f'require_update={release_require_update or snapshot_require_update}')