1
0
mirror of https://github.com/pooneyy/1Panel-Appstore.git synced 2026-03-18 03:21:12 +08:00

🔧 chore(workflow): enhance version update process with better error handling

- add commits counter to track successful commits
- implement directory existence checks before operations
- add git reset and proper file staging with git rm and git add
- check for actual file changes before committing
- improve error messages and exit conditions
- add success status reporting only when commits are pushed
This commit is contained in:
pooneyy 2025-10-10 12:00:41 +08:00
parent 218ffaa84a
commit 265a899c2d
No known key found for this signature in database
2 changed files with 44 additions and 15 deletions

View File

@ -104,10 +104,10 @@ def safe_rename_directory(old_path: str, new_path: str) -> bool:
def write_version_file(file_path: str, version: str) -> bool:
"""
写入版本文件
写入版本标记文件
Args:
file_path (str): 版本文件路径
file_path (str): 版本标记文件路径
version (str): 版本号
Returns:
@ -117,10 +117,10 @@ def write_version_file(file_path: str, version: str) -> bool:
os.makedirs(os.path.dirname(file_path), exist_ok=True)
with open(file_path, 'w') as f:
f.write(version)
print(f"✓ 版本文件已更新: {file_path}")
print(f"✓ 版本标记文件已更新: {file_path}")
return True
except Exception as e:
print(f"✗ 写入版本文件失败: {e}")
print(f"✗ 写入版本标记文件失败: {e}")
return False
def main():
@ -154,10 +154,10 @@ def main():
new_path = f"apps/{app_name}/{new_ver_dir}"
if safe_rename_directory(old_path, new_path):
# 更新版本文件
# 更新版本标记文件
version_file = f"apps/{app_name}/{old_version}.version"
if not write_version_file(version_file, new_version):
print("版本文件更新失败,但目录重命名成功")
print("版本标记文件更新失败,但目录重命名成功")
else:
print("错误: 目录重命名失败")
sys.exit(1)

View File

@ -91,7 +91,7 @@ jobs:
- name: Commit & Push Changes
run: |
IFS=' ' read -ra files <<< "${{ steps.updated-files.outputs.files }}"
commits_counter=0
for file in "${files[@]}"; do
if [[ $file == *"docker-compose.yml"* ]]; then
app_name=$(echo $file | cut -d'/' -f 2)
@ -99,17 +99,46 @@ jobs:
if [ -f "apps/$app_name/${old_version}.version" ]; then
new_version=$(cat "apps/$app_name/${old_version}.version")
rm -f "apps/$app_name/${old_version}.version"
git add "apps/$app_name/*" && git commit -m "🔧 chore($app_name): update app version from $old_version to $new_version" --no-verify && git push
gh api --silent --method POST -H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/statuses/$(git show -s --format=%H) \
-f 'state=success' \
-f 'target_url=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' \
-f 'description=CI/CD' \
-f 'context=${{ github.workflow}}'
echo "处理: $app_name - $old_version → $new_version"
# 检查目录是否存在
if [ ! -d "apps/$app_name/$old_version" ]; then
echo "✅ 旧目录不存在: apps/$app_name/$old_version"
fi
if [ -d "apps/$app_name/$new_version" ]; then
echo "✅ 新目录存在: apps/$app_name/$new_version"
else
echo "⚠️ 新目录不存在: apps/$app_name/$new_version"
exit 1
fi
git reset
git rm -r "apps/$app_name/$old_version"
git add "apps/$app_name/$new_version"
if git diff --cached --quiet; then
echo "⚠️ 没有检测到文件变更,跳过提交"
else
git commit -m "🔧 chore($app_name): update app version from $old_version to $new_version" --no-verify
echo "✅ 已提交: $old_version → $new_version"
((commits_counter++))
fi
else
echo "⚠️ 没有找到版本标记文件: apps/$app_name/${old_version}.version"
exit 1
fi
fi
done
if [ $commits_counter -gt 0 ]; then
echo "推送 $commits_counter 个提交到远程仓库..."
git push
gh api --silent --method POST -H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/statuses/$(git show -s --format=%H) \
-f 'state=success' \
-f 'target_url=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' \
-f 'description=CI/CD' \
-f 'context=${{ github.workflow}}'
else
echo "没有提交需要推送"
fi
check-labels:
name: Check labels