Skip to main content

补充参数和设置

GitHub Actions Importer 有多个补充参数和设置,可根据需要定制迁移过程。

法律通告

本文提供有关配置 GitHub Actions Importer 的补充参数和设置(例如可选参数、路径参数和网络设置)的一般信息。

可选参数

GitHub Actions Importer 有多个可选参数,可用于自定义迁移过程。

限制允许的操作

以下选项可用于限制转换工作流中允许的操作。 当组合使用时,这些选项扩大了允许的操作列表。 如果没有提供这些选项,则允许所有操作。

  • --allowed-actions 指定要在转换后的工作流中允许的操作的列表。 支持通配符。 除已提供的操作外,其他任何操作都将被禁止。

    例如:

    --allowed-actions actions/checkout@v4 actions/upload-artifact@* my-org/*
    

    可以提供一个空列表来禁止所有操作。 例如 --allowed-actions=

  • --allow-verified-actions 指定允许来自已验证创建者的所有操作。

  • --allow-github-created-actions 指定允许从 githubactions 组织发布的操作。

    例如,此类操作包括 github/super-linteractions/checkout

    此选项等同于 --allowed-actions actions/* github/* 命令。

使用凭据文件进行身份验证

--credentials-file 参数指定一个文件的路径,该文件包含 GitHub Actions Importer 可以进行身份验证的不同服务器的凭据。 当生成脚本(如 .travis.ymljenkinsfile)存储在多个 GitHub Enterprise Server 实例中时,这非常有用。

凭据文件必须是包含服务器和访问令牌组合的列表的 YAML 文件。 GitHub Actions Importer 使用与发出的网络请求最匹配的 URL 的凭据。

例如:

- url: https://github.com
  access_token: ghp_mygeneraltoken
- url: https://github.com/specific_org/
  access_token: ghp_myorgspecifictoken
- url: https://jenkins.org
  access_token: abc123
  username: marty_mcfly

对于上述凭据文件,GitHub Actions Importer 使用访问令牌 ghp_mygeneraltoken 对向 https://github.com 发出的所有网络请求进行身份验证,除非网络请求是面向 specific_org 组织中的存储库。 在这种情况下,ghp_myorgspecifictoken 令牌用于进行身份验证。

备用源代码提供程序

GitHub Actions Importer 可以从非 GitHub 存储库自动提取源代码。 凭据文件可以指定 provider、提供程序 URL 以及检索源代码所需的凭据。

例如:

- url: https://gitlab.com
  access_token: super_secret_token
  provider: gitlab

对于上述示例,GitHub Actions Importer 使用令牌 super_secret_token 检索托管在 https://gitlab.com 上的任何源代码。

provider 支持的值有:

  • github(默认值)
  • gitlab
  • bitbucket_server
  • azure_devops

控制可选功能

可以使用 --features 选项来限制 GitHub Actions Importer 创建的工作流中使用的功能。 这可用于在迁移到较旧的 GitHub Enterprise Server 实例时,从工作流中排除较新的 GitHub Actions 语法。 使用 --features 选项时,必须指定要迁移到的 GitHub Enterprise Server 的版本。

例如:

gh actions-importer dry-run ... --features ghes-3.3

--features 支持的值如下:

  • all(默认值)
  • ghes-latest
  • ghes-<number>,其中 <number> 是 GitHub Enterprise Server 的版本(3.0 或更高版本)。 例如 ghes-3.3

可以通过运行 list-features 命令按 GitHub Actions Importer 查看可用功能标志的列表。 例如:

Shell
gh actions-importer list-features

此时会看到类似下面的输出。

Available feature flags:

actions/cache (disabled):
        Control usage of actions/cache inside of workflows. Outputs a comment if not enabled.
        GitHub Enterprise Server >= ghes-3.5 required.

composite-actions (enabled):
        Minimizes resulting workflow complexity through the use of composite actions. See https://docs.github.com/en/actions/creating-actions/creating-a-composite-action for more information.
        GitHub Enterprise Server >= ghes-3.4 required.

reusable-workflows (disabled):
        Avoid duplication by re-using existing workflows. See https://docs.github.com/en/actions/using-workflows/reusing-workflows for more information.
        GitHub Enterprise Server >= ghes-3.4 required.

workflow-concurrency-option-allowed (enabled):
        Allows the use of the `concurrency` option in workflows. See https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#concurrency for more information.
        GitHub Enterprise Server >= ghes-3.2 required.

Enable features by passing --enable-features feature-1 feature-2
Disable features by passing --disable-features feature-1 feature-2

若要切换功能标志,可以使用以下任一方法:

  • 运行 gh actions-importer 命令时使用 --enable-features--disable-features 选项。
  • 为每个功能标志使用环境变量。

可以使用 --enable-features--disable-features 选项选择要在命令执行期间启用或禁用的特定功能。 例如,以下命令禁用 actions/cachecomposite-actions

gh actions-importer dry-run ... --disable-features=composite-actions actions/cache

可以使用 configure --features 命令以交互方式配置功能标志,并自动将其写入环境:

$ gh actions-importer configure --features

✔ Which features would you like to configure?: actions/cache, reusable-workflows
✔ actions/cache (disabled): Enable
? reusable-workflows (disabled):
› Enable
  Disable

禁用网络响应缓存

默认情况下,GitHub Actions Importer 会缓存来自网络请求的响应,以减少网络负载并减少运行时。 可以使用 --no-http-cache 选项来禁用网络缓存。 例如:

gh actions-importer forecast ... --no-http-cache

路径参数

运行 GitHub Actions Importer 时,路径参数与容器的磁盘相关,因此相对于容器的主机的绝对路径不受支持。 运行 GitHub Actions Importer 时,容器的 /data 目录会装载到运行 GitHub Actions Importer 的目录。

例如,以下命令(在 /Users/mona 目录中使用时)将 GitHub Actions Importer 审核摘要输出到 /Users/mona/out 目录:

gh actions-importer audit --output-dir /data/out

使用代理

若要访问配置了 HTTP 代理的服务器,必须使用代理的 URL 设置以下环境变量:

  • OCTOKIT_PROXY:适用于任何 GitHub 服务器。
  • HTTP_PROXY(或 HTTPS_PROXY):适用于任何其他服务器。

例如:

export OCTOKIT_PROXY=https://proxy.example.com:8443
export HTTPS_PROXY=$OCTOKIT_PROXY

如果代理需要身份验证,必须在代理 URL 中包含用户名和密码。 例如 https://username:password@proxy.url:port

禁用 SSL 证书验证

默认情况下,在发出网络请求时,GitHub Actions Importer 会验证 SSL 证书。 可以使用 --no-ssl-verify 选项禁用 SSL 证书验证。 例如:

gh actions-importer audit --output-dir ./output --no-ssl-verify

部分内容改编自 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.