GameServerManager/.github/workflows/sync-to-feature.yml
2025-08-15 22:47:50 +08:00

74 lines
2.5 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: 标准同步main分支到feature分支
on:
push:
branches:
- main
jobs:
sync-to-feature:
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v4
with:
fetch-depth: 0 # 获取完整的git历史
token: ${{ secrets.ACTIONS_PAT }}
- name: 配置Git用户信息
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "actions@github.com"
- name: 同步到feature分支
run: |
# 检查feature分支是否存在
if git ls-remote --heads origin feature | grep -q feature; then
echo "feature分支存在开始同步"
# 切换到feature分支
git fetch origin feature
git checkout -b feature origin/feature
# 尝试合并main分支
echo "正在将main分支合并到feature分支..."
if git merge origin/main --no-edit; then
echo "✅ 合并成功,推送到远程仓库"
git push origin feature
else
echo "❌ 合并冲突detected"
echo "冲突文件列表:"
git status --porcelain | grep "^UU\|^AA\|^DD" || echo "无法确定冲突文件"
echo ""
echo "请手动解决冲突后再次推送到main分支"
echo "或者联系仓库维护者处理冲突"
exit 1
fi
else
echo "feature分支不存在从main分支创建"
git checkout -b feature
git push origin feature --set-upstream
echo "✅ 成功创建feature分支"
fi
env:
GITHUB_TOKEN: ${{ secrets.ACTIONS_PAT }}
- name: 输出同步结果
if: success()
run: |
echo "✅ 成功将main分支同步到feature分支"
echo "📝 同步的提交: ${{ github.sha }}"
echo "👤 推送者: ${{ github.actor }}"
echo "🔄 同步方式: 标准合并(非强制推送)"
- name: 冲突处理提示
if: failure()
run: |
echo "⚠️ 同步失败 - 检测到合并冲突"
echo "🔧 解决方案:"
echo "1. 本地克隆仓库"
echo "2. 切换到feature分支: git checkout feature"
echo "3. 合并main分支: git merge main"
echo "4. 手动解决冲突文件"
echo "5. 提交解决结果: git commit"
echo "6. 推送到远程: git push origin feature"