Auto Sync Upstream (Rebase) #71
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Auto Sync Upstream (Rebase) | |
| permissions: | |
| contents: write # 必须给写权限,否则无法推送 | |
| on: | |
| schedule: | |
| - cron: '0 0 * * *' # 每天 UTC 时间 0点(北京时间早8点)自动运行 | |
| workflow_dispatch: # 允许你手动点击按钮触发 | |
| jobs: | |
| sync_latest_from_upstream: | |
| runs-on: ubuntu-latest | |
| name: Sync latest commits from upstream repo | |
| steps: | |
| # 1. 检出你的代码 | |
| - name: Checkout target repo | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main # 你的主分支名称,如果是 master 请修改 | |
| fetch-depth: 0 # 获取全部历史,否则无法 rebase | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| # 2. 配置 Git 用户信息(机器人假装是你) | |
| - name: Configure Git | |
| run: | | |
| git config --global user.name 'GitHub Actions' | |
| git config --global user.email 'actions@github.com' | |
| # 3. 添加上游仓库地址 | |
| - name: Add upstream | |
| run: git remote add upstream https://github.com/yahuisme/network-optimization.git | |
| # 4. 核心步骤:拉取 + 变基 (Rebase) | |
| - name: Sync upstream changes | |
| run: | | |
| git fetch upstream | |
| git checkout main | |
| git rebase upstream/main | |
| # 5. 强制推送 (Force Push) | |
| # 因为 rebase 改变了历史,必须强制推送 | |
| - name: Force push to origin | |
| run: git push origin main --force |