🔧 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:
47
.github/workflows/renovate-app-version.yml
vendored
47
.github/workflows/renovate-app-version.yml
vendored
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user