ci(sync): add HTTP sync workflow
- add new `http-sync` job for syncing to remote repositories via HTTPS - configure git user and authentication using PAT secrets - implement branch detection and tracking for all remote branches - add force push with pruning for all branches and tags - include success/failure summary logging for workflow runs
This commit is contained in:
parent
f2c11a2a5b
commit
bf66ce9591
|
|
@ -88,4 +88,63 @@ jobs:
|
|||
- name: 记录失败摘要
|
||||
if: failure()
|
||||
run: |
|
||||
echo "❌ $(date +"%Y-%m-%d %H:%M:%S %:z") 未能同步到 **${{ matrix.remote.https-url }}**" >> $GITHUB_STEP_SUMMARY
|
||||
echo "❌ $(date +"%Y-%m-%d %H:%M:%S %:z") 未能同步到 **${{ matrix.remote.https-url }}**" >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
http-sync:
|
||||
name: 同步到 ${{ matrix.remote.name }}
|
||||
if: false # 禁用
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
remote:
|
||||
- name:
|
||||
https-url:
|
||||
pat-secret:
|
||||
|
||||
steps:
|
||||
- name: 检出完整仓库
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: 检测默认分支
|
||||
run: |
|
||||
echo "默认分支: ${{ github.event.repository.default_branch }}"
|
||||
echo "当前分支 (pushed): ${{ github.ref_name }}"
|
||||
|
||||
- name: 配置本地仓库
|
||||
run: |
|
||||
git config --global --add safe.directory ${{ github.workspace }}
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email ${{ secrets.SYNC_EMAIL }}
|
||||
BASE_PATH="${{ matrix.remote.https-url }}"
|
||||
BASE_PATH="${BASE_PATH#https://}"
|
||||
if [[ ! "$BASE_PATH" =~ \.git$ ]]; then
|
||||
BASE_PATH="${BASE_PATH}.git"
|
||||
fi
|
||||
git remote add ${{ matrix.remote.name }} "https://git:${{ secrets[matrix.remote.pat-secret] }}@${BASE_PATH}"
|
||||
git branch -r | grep -v '\->' | while read remote; do
|
||||
branch=${remote#origin/}
|
||||
git branch --track "$branch" "$remote" 2>/dev/null && echo "创建本地分支: $branch" || echo "分支 $branch 已存在"
|
||||
done
|
||||
|
||||
- name: 列出所有本地分支
|
||||
run: git branch
|
||||
|
||||
- name: 强制推送所有分支和所有标签到 ${{ matrix.remote.name }}
|
||||
run: |
|
||||
echo "将所有分支推送到 ${{ matrix.remote.name }} (修剪模式)..."
|
||||
git push --force --prune ${{ matrix.remote.name }} --all
|
||||
echo "将所有 tags 推送到 ${{ matrix.remote.name }}..."
|
||||
git push --force ${{ matrix.remote.name }} --tags
|
||||
|
||||
- name: 记录成功摘要
|
||||
if: success()
|
||||
run: |
|
||||
echo "✅ $(date +"%Y-%m-%d %H:%M:%S %:z") 成功同步到 **${{ matrix.remote.https-url }}**" >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
- name: 记录失败摘要
|
||||
if: failure()
|
||||
run: |
|
||||
echo "❌ $(date +"%Y-%m-%d %H:%M:%S %:z") 未能同步到 **${{ matrix.remote.https-url }}**" >> $GITHUB_STEP_SUMMARY
|
||||
|
|
|
|||
Loading…
Reference in New Issue