杜老师复刻了 70 多个库,每次源库更新后都需要一一手动同步,太过麻烦。今天分享一个自动同步脚本,有需要的小伙伴可以试一下。注意如对本地库有修改,建议使用 PR 来同步,避免代码覆盖。
代码同步 {#代码同步}
不太清楚小伙伴们同步代码方式,有人习惯用 PR,有人喜欢用下图同步的方式。不管哪种方式,都需要手动操作的。如有仓库过多,每个都要同步一遍,想想是多大工作量。杜老师分享了 GitHub 库自动同步脚本,供有需要的小伙伴参考:
脚本分享 {#脚本分享}
进入要同步的库中,切换至 Actions,点击 New workflow 项:
打开新页面后,点击篮字的 set up a workflow yourself:
设置文件名 sync.yml
「可自定义,不与其它脚本同名即可」
将下面的脚本填到输入框中,点击右上方 Commit changes 即可:
|------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| name: Upstream Sync permissions: contents: write on: schedule: - cron: "0 0 * * *" # every day workflow_dispatch: jobs: sync_latest_from_upstream: name: Sync latest commits from upstream repo runs-on: ubuntu-latest if: ${{ github.event.repository.fork }} steps: # Step 1: run a standard checkout action - name: Checkout target repo uses: actions/checkout@v4 # Step 2: run the sync action - name: Sync upstream changes id: sync uses: aormsby/Fork-Sync-With-Upstream-action@v3.4 with: upstream_sync_repo: arnidan/nsfw-api upstream_sync_branch: main target_sync_branch: main target_repo_token: ${{ secrets.GITHUB_TOKEN }} # automatically generated, no need to set # Set test_mode true to run tests instead of the true action!! test_mode: false - name: Sync check if: failure() run: | echo "[Error] 由于上游仓库的 workflow 文件变更,导致 GitHub 自动暂停了本次自动更新,您需要手动 Sync Fork 一次。" echo "[Error] Due to a change in the workflow file of the upstream repository, GitHub has automatically suspended the scheduled automatic update. You need to manually sync your fork." exit 1
|