Skip to content

Sync upstream

Sync upstream #222

Workflow file for this run

name: Sync upstream
on:
schedule:
- cron: '0 2 * * *' # 每天凌晨2点自动运行
workflow_dispatch: # 支持手动触发
jobs:
check:
runs-on: ubuntu-latest
outputs:
need_sync: ${{ steps.compare.outputs.need_sync }}
upstream_hash: ${{ steps.compare.outputs.upstream_hash }}
current_hash: ${{ steps.compare.outputs.current_hash }}
steps:
- name: Checkout up-sync branch
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
ref: up-sync
- name: Add upstream remote
run: git remote add upstream https://github.com/ddnet/ddnet-maps
- name: Fetch upstream
run: git fetch upstream
- name: Compare commit hashes
id: compare
run: |
# 获取当前 up-sync 分支的 commit hash
CURRENT_HASH=$(git rev-parse HEAD)
echo "current_hash=$CURRENT_HASH" >> $GITHUB_OUTPUT
echo "当前 up-sync 分支 commit hash: $CURRENT_HASH"
# 获取 upstream/master 的 commit hash
UPSTREAM_HASH=$(git rev-parse upstream/master)
echo "upstream_hash=$UPSTREAM_HASH" >> $GITHUB_OUTPUT
echo "upstream/master commit hash: $UPSTREAM_HASH"
# 比较两个 hash 是否相同
if [ "$CURRENT_HASH" = "$UPSTREAM_HASH" ]; then
echo "need_sync=false" >> $GITHUB_OUTPUT
echo "✅ commit hash 相同,无需同步"
else
echo "need_sync=true" >> $GITHUB_OUTPUT
echo "🔄 commit hash 不同,需要同步"
fi
sync:
runs-on: ubuntu-latest
needs: check
if: needs.check.outputs.need_sync == 'true'
permissions:
contents: write
steps:
- name: Checkout up-sync branch
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
ref: up-sync
- name: Add upstream remote
run: git remote add upstream https://github.com/ddnet/ddnet-maps
- name: Fetch upstream
run: git fetch upstream
- name: Show sync information
run: |
echo "🔄 开始同步..."
echo "当前分支: $(git rev-parse HEAD)"
echo "目标分支: $(git rev-parse upstream/master)"
- name: Hard reset up-sync to upstream/master
run: |
git reset --hard upstream/master
- name: Push to origin up-sync branch (force)
run: |
git push origin up-sync --force
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Sync completed
run: |
echo "✅ 同步完成!"
echo "新的 commit hash: $(git rev-parse HEAD)"