1
0
mirror of https://gitlink.org.cn/pooneyy/1Panel-Appstore.git synced 2026-04-24 10:41:42 +08:00

♻️ refactor(workflow): enhance version extraction and workflow reliability

- add type hints to functions for better code clarity
- fix version extraction logic to correctly access version from dictionary
- improve error handling in workflow with better debugging information
- update workflow to use pull request head ref for accurate file detection
- add fallback to 'latest' version when extraction fails
- enhance logging with old and new version display
- rename script reference from .sh to .py in workflow step
- modify checkout action to use head ref instead of default
This commit is contained in:
pooneyy 2025-10-06 21:40:27 +08:00
parent deae7397a8
commit 60513cb920
No known key found for this signature in database
2 changed files with 22 additions and 9 deletions

View File

@ -5,7 +5,7 @@ import shutil
import sys import sys
import yaml import yaml
def extract_version_from_string(input_string): def extract_version_from_string(input_string) -> dict:
""" """
从字符串中提取版本号支持镜像名和文件夹名 从字符串中提取版本号支持镜像名和文件夹名
@ -66,7 +66,7 @@ def extract_version_from_string(input_string):
return {"success": False, "version": original_candidate} return {"success": False, "version": original_candidate}
def replace_version_in_dirname(old_ver_dir, new_version): def replace_version_in_dirname(old_ver_dir : str, new_version : str) -> str:
""" """
将旧版本文件夹名中的版本号替换为新版本号 将旧版本文件夹名中的版本号替换为新版本号
@ -80,7 +80,7 @@ def replace_version_in_dirname(old_ver_dir, new_version):
version_info = extract_version_from_string(old_ver_dir) version_info = extract_version_from_string(old_ver_dir)
if version_info["success"]: if version_info["success"]:
old_version = version_info["original"] old_version = version_info["version"]
new_ver_dir = old_ver_dir.replace(old_version, new_version) new_ver_dir = old_ver_dir.replace(old_version, new_version)
return new_ver_dir return new_ver_dir
else: else:
@ -107,10 +107,10 @@ def main():
image = services[first_service].get('image', '') image = services[first_service].get('image', '')
print(f"该服务的镜像: {image}") print(f"该服务的镜像: {image}")
new_version = extract_version_from_string(image) new_version = extract_version_from_string(image).get("version", "latest")
print(f"版本号: {new_version}") old_version = extract_version_from_string(old_ver_dir).get("version", "latest")
print(f"旧版本号: {old_version}")
old_version = extract_version_from_string(old_ver_dir) print(f"新版本号: {new_version}")
new_ver_dir = replace_version_in_dirname(old_ver_dir, new_version) new_ver_dir = replace_version_in_dirname(old_ver_dir, new_version)
if old_version != new_version: if old_version != new_version:
old_path = f"apps/{app_name}/{old_ver_dir}" old_path = f"apps/{app_name}/{old_ver_dir}"

View File

@ -46,6 +46,7 @@ jobs:
uses: actions/checkout@v5.0.0 uses: actions/checkout@v5.0.0
with: with:
fetch-depth: 0 fetch-depth: 0
ref: ${{ github.head_ref }}
- uses: actions/setup-python@main - uses: actions/setup-python@main
with: with:
@ -60,9 +61,21 @@ jobs:
- name: Get list of updated files by the last commit in this branch separated by space - name: Get list of updated files by the last commit in this branch separated by space
id: updated-files id: updated-files
run: | run: |
echo "files=$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }} | tr '\n' ' ')" >> $GITHUB_OUTPUT # 当触发工作流的事件为 pull_request 时github.sha 值为 github.ref 分支上的最后一次合并提交
files=$(git diff-tree --no-commit-id --name-only -r ${{ github.event.pull_request.head.sha }} | tr '\n' ' ')
if [ -z "$files" ]; then
echo "❌ 错误:没有检测到文件变更"
echo "github.sha = ${{ github.sha }}"
echo "github.event.pull_request.head.sha = ${{ github.event.pull_request.head.sha }}"
echo "当前分支最新的提交SHA: $(git rev-parse HEAD)"
echo "💡 最近三次提交:"
echo " $(git log -3)"
exit 1
else
echo "files=$files" >> $GITHUB_OUTPUT
fi
- name: Run renovate-app-version.sh on updated files - name: Run renovate-app-version.py on updated files
run: | run: |
IFS=' ' read -ra files <<< "${{ steps.updated-files.outputs.files }}" IFS=' ' read -ra files <<< "${{ steps.updated-files.outputs.files }}"