GitHub 是一个流行的代码托管平台,允许开发人员分享和协作他们的代码。当您在 GitHub 上 fork 一个项目时,您会创建一个该项目的副本,您可以对其进行修改和贡献,而不会影响原始项目。但是,如果您想将您的更改同步回原始项目,您需要创建一个 pull request。
打开打开Actions页面
首先打开你Fork的项目,打开Actions页面
新建workflow
点击new workflow,选择set up a workflow yourself进入编辑页面。
编辑文件
文件取名为sync.yml,然后输入以下代码
name: Upstream Sync
permissions:
contents: write
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
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@v3
- name: Sync Upstream
uses: aormsby/Fork-Sync-With-Upstream-action@v3.4
with:
target_repo_token: ${{ secrets.GITHUB_TOKEN }}
upstream_sync_repo: HackJava/HackJava
upstream_sync_branch: main
target_sync_branch: main
test_mode: false
- name: Check for Failure
if: failure()
run: |
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
修改配置
1.定时任务执行间隔
修改cron项,这里是0 0 * * *,代表每天0点执行一次
2.要同步的仓库路径
修改upstream_sync_repo项,这里要填你fork的仓库路径,在你fork项目的的名字下方能看到。
3.同步分支名称
修改upstream_sync_branch和target_sync_branch项,填写你要同步的分钟名称,例如我填的main,一般来说fork的分支名称都一样。
提交保持文件
填写完成后点右上角commit changes,然后确认。
测试运行
回到Actions页面,点击你刚刚创建的workflow,点击Run workflow
运行成功