Files
wangdage12 ec6c1a2377 Add workflow to sync fork with original repository
This workflow syncs the main branch of a forked repository with the original repository. It includes steps for checking out the original repository, cloning the fork, displaying commits, syncing files while excluding specific directories, and pushing changes if any are detected.
2026-08-15 21:46:59 +08:00

109 lines
2.8 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: Sync from Fork
on:
# 每天 UTC 00:00 执行
schedule:
- cron: "0 0 * * *"
# GitHub 页面手动执行
workflow_dispatch:
permissions:
contents: write
concurrency:
group: sync-from-fork
cancel-in-progress: false
jobs:
sync:
name: Sync Fork main to Original main
runs-on: ubuntu-latest
steps:
# ==========================================
# 1. Checkout 原仓库
# ==========================================
- name: Checkout original repository
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
# ==========================================
# 2. Clone Fork
# ==========================================
- name: Clone fork repository
run: |
git clone \
--depth 1 \
--branch main \
"https://github.com/SnapHutaoRemasteringProject/Snap.Metadata.Work.git" \
../fork
# ==========================================
# 3. 显示同步前后的 Commit
# ==========================================
- name: Show source commit
working-directory: ../fork
run: |
echo "Fork commit:"
git log -1 --oneline
- name: Show original commit
run: |
echo "Original commit:"
git log -1 --oneline
# ==========================================
# 4. 同步文件
#
# --delete:
# Fork 删除的文件,原仓库也删除
#
# 排除 .git:
# 不复制 Git 元数据
#
# 排除 .github/workflows:
# 原仓库自己的 Workflow 永远保留
# ==========================================
- name: Sync files
run: |
rsync -av --delete \
--exclude='.git/' \
--exclude='.github/workflows/' \
../fork/ ./
# ==========================================
# 5. 查看变化
# ==========================================
- name: Show changes
run: |
git status --short
git diff --stat
# ==========================================
# 6. 如果有变化则提交
# ==========================================
- name: Commit changes
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if git diff --quiet; then
echo "No changes detected."
exit 0
fi
git add -A
git commit \
-m "chore: sync from fork"
# ==========================================
# 7. Push 到原仓库 main
# ==========================================
- name: Push changes
run: |
git push origin HEAD:main