Skip to content

希望能增强 sync 脚本 #297

@runoneall

Description

@runoneall
git fetch upstream && git reset --hard upstream/main && git push origin main --force && git clean -fd

使用这个命令可以完全同步上游 main 到本地 main
目前的 fork-sync 实测会有落后的更改,但我也不知道怎么产生的
大概是以下的效果(未测试)

name: Fork Sync

on:
  schedule:
    - cron: "0 19 * * *"
  workflow_dispatch:

permissions:
  contents: write

jobs:
  sync_with_upstream:
    name: Sync with Upstream
    runs-on: ubuntu-latest
    if: ${{ github.event.repository.fork }}

    steps:
      - name: Checkout target repo
        uses: actions/checkout@v4
        with:
          token: ${{ secrets.SYNC_PAT != '' && secrets.SYNC_PAT || secrets.GITHUB_TOKEN }}
          fetch-depth: 0
          ref: main

      - name: Force Sync with Upstream
        env:
          SYNC_PAT: ${{ secrets.SYNC_PAT }}
        run: |
          set -e
          
          git config user.name "GitHub Actions Bot"
          git config user.email "github-actions[bot]@users.noreply.github.com"

          if git remote get-url upstream >/dev/null 2>&1; then
            git remote set-url upstream https://github.com/imzyb/MiSub.git
          else
            git remote add upstream https://github.com/imzyb/MiSub.git
          fi

          if [ -n "${SYNC_PAT:-}" ]; then
            git remote set-url origin "https://x-access-token:${SYNC_PAT}@github.com/${{ github.repository }}.git"
          fi

          git fetch upstream main
          git reset --hard upstream/main
          git clean -fd
          git push origin main --force

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions