跳至主要内容

使用 GitHub Actions 导入器自动执行迁移

使用 GitHub Actions 导入器来计划和自动执行您到 GitHub Actions 的迁移。

法律声明

关于 GitHub Actions 导入器

您可以使用 GitHub Actions 导入器来计划并自动将支持的 CI/CD 管道迁移到 GitHub Actions。

GitHub Actions 导入器以 Docker 容器的形式分发,并使用 GitHub CLI 扩展与容器进行交互。

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

支持的 CI 平台

您可以使用 GitHub Actions 导入器从以下平台迁移

  • Azure DevOps
  • Bamboo
  • Bitbucket Pipelines
  • CircleCI
  • GitLab(云端和自托管)
  • Jenkins
  • Travis CI

先决条件

GitHub Actions 导入器具有以下要求

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

    注意

    GitHub Actions 导入器容器和 CLI 不需要安装在与您的 CI 平台相同的服务器上。

安装 GitHub Actions 导入器 CLI 扩展

  1. 安装 GitHub Actions 导入器 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 导入器 CLI

为了确保您正在运行最新版本的 GitHub Actions 导入器,您应该定期运行 update 命令

gh actions-importer update

在命令行进行身份验证

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

gh actions-importer configure

使用 GitHub Actions 导入器 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 导入器的 CLI 命令。这允许您在不安装本地机器上的软件的情况下迁移您的 CI/CD 工作流。这种方法对于希望启用到 GitHub Actions 的自助迁移的组织特别有用。配置 IssueOps 后,用户可以使用相关的模板打开问题以将管道迁移到 GitHub Actions。

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

使用 GitHub Actions 导入器实验室存储库

GitHub Actions 导入器实验室存储库包含特定于平台的学习路径,这些路径将教您如何使用 GitHub Actions 导入器以及如何处理迁移到 GitHub Actions 的问题。您可以使用此存储库来学习如何使用 GitHub Actions 导入器来帮助规划、预测和自动化您迁移到 GitHub Actions 的过程。

要了解更多信息,请参阅 GitHub Actions 导入器实验室存储库

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

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.