【问题标题】:Periodically clone external repo with github actions and set it as a private repo使用 github 操作定期克隆外部 repo 并将其设置为私有 repo
【发布时间】:2022-01-04 12:18:53
【问题描述】:

我正在尝试设置一个定期克隆外部存储库的 GitHub 操作(例如,targetuser/targetrepo 并且我有一个个人访问令牌)。

GitHub 操作运行顺利,但我不知道在哪里克隆了存储库:我在我的 GitHub 帐户中看不到它。
另外,我希望将克隆的存储库设置为私有。

这是我基于this responsemain.yml 文件:

name: mainAction
on:
  schedule:
    - cron:  "*/5 * * * *"
  workflow_dispatch:
    
jobs: 
  copyRepo:
    runs-on: macOS-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Copy repo
      env:
        ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
      run: git clone "https://"$ACCESS_TOKEN"@github.com/targetuser/targetrepo.git"

编辑
我想在我的帐户中拥有 GitHub 存储库的副本,而不仅仅是在跑步者的“容器”中。

【问题讨论】:

  • 当您使用 Github Action 运行器克隆 repo 时,克隆的 repo 将位于存储库工作流程的 github.workspace(又名存储库根)(通过 action/checkout 操作启用)。但由于您不执行任何其他操作,因此它不会在工作流运行结束时持久化。
  • @GuiFalourd 我对 github 很陌生,但我想我明白你的意思。从那时起,有没有办法执行位于克隆存储库中的工作流?
  • 您希望在克隆另一个存储库后在工作流运行中从另一个存储库运行工作流;我理解正确吗?根据您想要实现的目标,也许可以在不必克隆存储库的情况下执行相同的操作,例如使用调度事件。
  • 当你执行一个动作时,就会创建一个运行。那个跑步者是一个 Docker 容器。当您 git clone 时,您正在将文件复制到容器中。当运行程序完成执行时,文件将被删除。您必须将 git clone 的结果保存在某个地方。您的问题不清楚 将其设置为私人回购 的含义。你想每次都创建一个新的 repo 还是更新一个现有的 repo?使用详细信息编辑您的问题。
  • @JohnHanley 我更新了帖子以指定我要查找的内容。感谢您的投入!

标签: github github-actions


【解决方案1】:

我想在我的帐户中拥有 github 存储库的副本,而不仅仅是在跑步者的“容器”中。

通过镜像 GitHub Action 更好地解决问题,例如wearerequired/git-mirror-action,或者更好的是,在您的情况下(使用令牌):pkgstore/github-action-mirror

name: "Repository Mirror: GitHub"

on:
  schedule:
    - cron:  "*/5 * * * *"
  workflow_dispatch:

jobs:
  mirror:
    runs-on: ubuntu-latest
    name: "Mirror"
    steps:
      - uses: pkgstore/github-action-mirror@main
        with:
          source_repo: "https://github.com/${{ github.repository }}.git"
          source_user: "${{ secrets.MIRROR_SOURCE_USER_GITHUB }}"
          source_token: "${{ secrets.MIRROR_SOURCE_TOKEN_GITHUB }}"
          target_repo: "${{ secrets.MIRROR_TARGET_URL_GITHUB }}"
          target_user: "${{ secrets.MIRROR_TARGET_USER_GITHUB }}"
          target_token: "${{ secrets.MIRROR_TARGET_TOKEN_GITHUB }}"

这样,您可以将源存储库发送到您的私有存储库。

【讨论】:

    猜你喜欢
    • 2022-12-20
    • 2023-01-31
    • 2013-08-14
    • 2021-07-16
    • 2013-11-07
    • 2022-09-29
    • 2020-11-24
    • 2014-03-03
    • 1970-01-01
    相关资源
    最近更新 更多