一给 发表于 2024-10-17 03:45:12

Github使用github Actions自动同步fork的项目

GitHub 是一个流行的代码托管平台,允许开发职员分享和协作他们的代码。当您在 GitHub 上 fork 一个项目时,您会创建一个该项目标副本,您可以对其进行修改和贡献,而不会影响原始项目。但是,如果您想将您的更改同步回原始项目,您必要创建一个 pull request。
打开打开Actions页面

起首打开你Fork的项目,打开Actions页面
https://i-blog.csdnimg.cn/blog_migrate/5d8ad342902a509279d3979157a79d16.png#pic_center
新建workflow

点击new workflow,选择set up a workflow yourself进入编辑页面。
https://i-blog.csdnimg.cn/blog_migrate/517a2f2e108725c43c250f2087a0843f.png#pic_center
编辑文件

文件取名为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 " 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项目标的名字下方能看到。
https://i-blog.csdnimg.cn/blog_migrate/3ae34ad9500e6a2c7685a10a27a4bdca.png#pic_center
3.同步分支名称

修改upstream_sync_branch和target_sync_branch项,填写你要同步的分钟名称,比方我填的main,一般来说fork的分支名称都一样。
提交保持文件

https://i-blog.csdnimg.cn/blog_migrate/baada0af8a19ece1415512806c89b086.png#pic_center
填写完成后点右上角commit changes,然后确认。
测试运行

回到Actions页面,点击你刚刚创建的workflow,点击Run workflow
https://i-blog.csdnimg.cn/blog_migrate/ebb934ed048702f6ea89c2ede2406aa5.png#pic_center
运行成功

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: Github使用github Actions自动同步fork的项目