Skip to main content

此版本的 GitHub Enterprise Server 已于以下日期停止服务 2024-03-26. 即使针对重大安全问题,也不会发布补丁。 为了获得更好的性能、更高的安全性和新功能,请升级到最新版本的 GitHub Enterprise。 如需升级帮助,请联系 GitHub Enterprise 支持

手动从 GitHub.com 同步操作

对于需要访问 GitHub.com 上操作的用户,您可以将特定操作同步到企业。

注意:GitHub Enterprise Server 目前不支持 GitHub 托管的运行器。 可以在 GitHub public roadmap 上查看有关未来支持计划的更多信息。

GitHub Enterprise Server 上的 GitHub Actions 设计为在无法完全访问互联网的环境中工作。 默认情况下,工作流不能使用直接来自 GitHub.com 和 GitHub Marketplace 的操作。

推荐的允许从 GitHub.com 访问操作的方法是启用自动访问所有操作。 为此,可使用 GitHub Connect 将 GitHub Enterprise Server 与 GitHub Enterprise Cloud 集成。 有关详细信息,请参阅“使用 GitHub Connect 启用对 GitHub.com 操作的自动访问”。

但是,如果想更严格地控制企业中允许的操作,可以按照本指南使用 GitHub 的开源 actions-sync 工具将各个操作存储库从 GitHub.com 同步到企业。

关于 actions-sync 工具

actions-sync 工具必须在可以访问 GitHub.com API 和 GitHub Enterprise Server 实例的 API 的计算机上运行。 计算机不需要同时连接到两者。

如果计算机可以同时访问这两个系统,则可以使用单一 actions-sync sync 命令进行同步。 如果一次只能访问一个系统,可以使用 actions-sync pullpush 命令。

actions-sync 工具只能从存储在公共存储库中的 GitHub.com 下载操作。

注意:actions-sync 工具适用于未启用 GitHub Connect 的系统。 如果在启用了 GitHub Connect 的系统上运行该工具,则可能会看到错误 The repository <repo_name> has been retired and cannot be reused。 这表示工作流已直接在 GitHub.com 上使用了该操作,并且命名空间已在 你的 GitHub Enterprise Server 实例上停用。 有关详细信息,请参阅“使用 GitHub Connect 启用对 GitHub.com 操作的自动访问”。

先决条件

  • 在使用 actions-sync 工具之前,必须确保所有目标组织已经存在于企业中。 以下示例演示如何将操作同步到名为 synced-actions 的组织。 有关详细信息,请参阅“从头开始创建新组织”。

  • 必须在企业上创建可以创建并写入目标组织中的存储库的personal access token。 有关详细信息,请参阅“管理个人访问令牌”。

  • 如果想同步 你的 GitHub Enterprise Server 实例上 actions 组织中的捆绑操作,你需要是 actions 组织的所有者。

    注意:默认情况下,即使站点管理员也不是捆绑的 actions 组织的所有者。

    站点管理员可以在管理 shell 中使用 ghe-org-admin-promote 命令将用户升级为捆绑的 actions 组织的所有者。 有关详细信息,请参阅“访问管理 shell (SSH)”和“命令行实用程序”。

    ghe-org-admin-promote -u USERNAME -o actions
    

Example: Using the actions-sync tool

This example demonstrates using the actions-sync tool to sync an individual action from GitHub.com to an enterprise instance.

Note: This example uses the actions-sync sync command, which requires concurrent access to both the GitHub.com API and your enterprise instance's API from your machine. If you can only access one system at a time, you can use the actions-sync pull and push commands. For more information, see the actions-sync README.

  1. Download and extract the latest actions-sync release for your machine's operating system.

  2. Create a directory to store cache files for the tool.

  3. In your terminal, change to the bin directory within the release directory you just extracted. For example:

    cd PATH/TO/gh_DATETIME_OS_ARCHITECTURE/bin
    
  4. 运行 actions-sync sync 命令:

    ./actions-sync sync \
      --cache-dir "cache" \
      --destination-token "aabbccddeeffgg" \
      --destination-url "https://my-ghes-instance" \
      --repo-name "actions/stale:synced-actions/actions-stale"
    

    上述命令使用以下参数:

    • --cache-dir:运行命令的计算机上的缓存目录。

    • --destination-token:目标企业实例的personal access token。

    • --destination-url:目标企业实例的 URL。

    • --repo-name:要同步的操作存储库。其采用格式 owner/repository:destination_owner/destination_repository

      • 上面的示例将 actions/stale 存储库同步到目标企业实例上的 synced-actions/actions-stale 存储库。 在运行上述命令之前,必须在企业中创建名为 synced-actions 的组织。
      • 如果省略 :destination_owner/destination_repository,工具将使用企业的原始所有者和存储库名称。 在运行命令之前,必须在企业中创建一个与操作的所有者名称匹配的新组织。 考虑使用一个中心组织来存储企业中同步的操作,因为这样在同步来自不同所有者的操作时,将无需创建多个新的组织。
      • 可以通过将 --repo-name 参数替换为 --repo-name-list--repo-name-list-file 来同步多个操作。 有关详细信息,请参阅 actions-sync README
  5. 在企业中创建操作仓库后,企业中的人员可以使用目标仓库在其工作流程中引用操作。 对于上面显示的示例操作:

    uses: synced-actions/actions-stale@v1
    

    有关详细信息,请参阅“GitHub Actions 的工作流语法”。