跳至主要内容

使用 GitHub 操作导入程序自动执行迁移

使用 GitHub 操作导入程序计划和自动执行您向 GitHub 操作的迁移。

法律声明

关于 GitHub Actions Importer

你可以使用 GitHub Actions Importer 规划并自动将你支持的 CI/CD 管道迁移到 GitHub Actions。

GitHub Actions Importer 作为 Docker 容器分发,并使用 GitHub CLI 扩展与容器进行交互。

GitHub Actions Importer 转换的任何工作流在用作生产工作负载之前都应检查其正确性。目标是为每个工作流实现 80% 的转换率,但实际转换率将取决于转换的每个单独管道的构成。

支持的 CI 平台

你可以使用 GitHub Actions Importer 从以下平台迁移

  • Azure DevOps
  • Bamboo
  • Bitbucket Pipelines
  • CircleCI
  • GitLab
  • Jenkins
  • Travis CI

先决条件

GitHub Actions Importer 具有以下要求

  • 你可以运行基于 Linux 的容器并安装必要工具的环境。

    注意:GitHub Actions Importer 容器和 CLI 不需要安装在与你的 CI 平台相同的服务器上。

安装 GitHub Actions Importer CLI 扩展

  1. 安装 GitHub Actions Importer CLI 扩展

    Bash
    gh extension install github/gh-actions-importer
    
  2. 验证扩展是否已安装

    $ gh actions-importer -h
    Options:
      -?, -h, --help  Show help and usage information
    
    Commands:
      update     Update to the latest version of GitHub Actions Importer.
      version    Display the version of GitHub Actions Importer.
      configure  Start an interactive prompt to configure credentials used to authenticate with your CI server(s).
      audit      Plan your CI/CD migration by analyzing your current CI/CD footprint.
      forecast   Forecast GitHub Actions usage from historical pipeline utilization.
      dry-run    Convert a pipeline to a GitHub Actions workflow and output its yaml file.
      migrate    Convert a pipeline to a GitHub Actions workflow and open a pull request with the changes.
    

更新 GitHub Actions Importer CLI

为了确保你正在运行最新版本的 GitHub Actions Importer,你应该定期运行 update 命令

gh actions-importer update

在命令行进行身份验证

您必须配置允许 GitHub Actions Importer 与 GitHub 和您当前的 CI 服务器通信的凭据。您可以使用环境变量或 .env.local 文件配置这些凭据。可以通过运行以下命令在交互式提示符中配置环境变量

gh actions-importer configure

使用 GitHub Actions Importer CLI

使用 gh actions-importer 的子命令开始向 GitHub Actions 迁移,包括 auditforecastdry-runmigrate

审核您现有的 CI 管道

audit 子命令可用于通过分析您当前的 CI/CD 占用情况来规划您的 CI/CD 迁移。此分析可用于规划迁移到 GitHub Actions 的时间表。

要运行审核,请使用以下命令确定您的可用选项

$ gh actions-importer audit -h
Description:
  Plan your CI/CD migration by analyzing your current CI/CD footprint.

[...]

Commands:
  azure-devops  An audit will output a list of data used in an Azure DevOps instance.
  bamboo        An audit will output a list of data used in a Bamboo instance.
  circle-ci     An audit will output a list of data used in a CircleCI instance.
  gitlab        An audit will output a list of data used in a GitLab instance.
  jenkins       An audit will output a list of data used in a Jenkins instance.
  travis-ci     An audit will output a list of data used in a Travis CI instance.

预测使用情况

forecast 子命令审查历史管道使用情况,以创建 GitHub Actions 使用情况的预测。

要运行预测,请使用以下命令确定您的可用选项

$ gh actions-importer forecast -h
Description:
  Forecasts GitHub Actions usage from historical pipeline utilization.

[...]

Commands:
  azure-devops  Forecasts GitHub Actions usage from historical Azure DevOps pipeline utilization.
  bamboo        Forecasts GitHub Actions usage from historical Bamboo pipeline utilization.
  jenkins       Forecasts GitHub Actions usage from historical Jenkins pipeline utilization.
  gitlab        Forecasts GitHub Actions usage from historical GitLab pipeline utilization.
  circle-ci     Forecasts GitHub Actions usage from historical CircleCI pipeline utilization.
  travis-ci     Forecasts GitHub Actions usage from historical Travis CI pipeline utilization.
  github        Forecasts GitHub Actions usage from historical GitHub pipeline utilization.

测试迁移过程

dry-run 子命令可用于将管道转换为其 GitHub Actions 等效项,然后将工作流写入您的本地文件系统。

要执行试运行,请使用以下命令确定您的可用选项

$ gh actions-importer dry-run -h
Description:
  Convert a pipeline to a GitHub Actions workflow and output its yaml file.

[...]

Commands:
  azure-devops  Convert an Azure DevOps pipeline to a GitHub Actions workflow and output its yaml file.
  bamboo        Convert a Bamboo pipeline to GitHub Actions workflows and output its yaml file.
  circle-ci     Convert a CircleCI pipeline to GitHub Actions workflows and output the yaml file(s).
  gitlab        Convert a GitLab pipeline to a GitHub Actions workflow and output the yaml file.
  jenkins       Convert a Jenkins job to a GitHub Actions workflow and output its yaml file.
  travis-ci     Convert a Travis CI pipeline to a GitHub Actions workflow and output its yaml file.

将管道迁移到 GitHub Actions

migrate 子命令可用于将管道转换为其 GitHub Actions 等效项,然后使用内容创建拉取请求。

要运行迁移,请使用以下命令确定您的可用选项

$ gh actions-importer migrate -h
Description:
  Convert a pipeline to a GitHub Actions workflow and open a pull request with the changes.

[...]

Commands:
  azure-devops  Convert an Azure DevOps pipeline to a GitHub Actions workflow and open a pull request with the changes.
  bamboo        Convert a Bamboo pipeline to GitHub Actions workflows and open a pull request with the changes.
  circle-ci     Convert a CircleCI pipeline to GitHub Actions workflows and open a pull request with the changes.
  gitlab        Convert a GitLab pipeline to a GitHub Actions workflow and open a pull request with the changes.
  jenkins       Convert a Jenkins job to a GitHub Actions workflow and open a pull request with the changes.
  travis-ci     Convert a Travis CI pipeline to a GitHub Actions workflow and open a pull request with the changes.

使用 IssueOps 执行自助迁移

您可以使用 GitHub Actions 和 GitHub Issues 为 GitHub Actions Importer 运行 CLI 命令。这允许您迁移 CI/CD 工作流,而无需在本地计算机上安装软件。此方法对于希望启用到 GitHub Actions 的自助迁移的组织特别有用。配置 IssueOps 后,用户可以使用相关模板打开一个问题,以将管道迁移到 GitHub Actions。

有关使用 IssueOps 设置自助迁移的更多信息,请参阅 actions/importer-issue-ops 模板存储库。

使用 GitHub Actions Importer labs 存储库

GitHub Actions Importer labs 存储库包含特定于平台的学习路径,教您如何使用 GitHub Actions Importer 以及如何迁移到 GitHub Actions。您可以使用此存储库了解如何使用 GitHub Actions Importer 来帮助规划、预测和自动化您向 GitHub Actions 的迁移。

要了解更多信息,请参阅 GitHub Actions Importer labs 存储库

部分内容已根据 MIT 许可从 https://github.com/github/gh-actions-importer/ 改编

MIT License

Copyright (c) 2022 GitHub

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.