GitHub actions 拆分工作流程文件

Soh*_*med 6 github-actions

是否可以拆分 GitHub Actions 工作流程文件并从其他文件引用它?我需要将应用程序部署到多个环境(即暂存和生产)中,并且希望共享一半的步骤以最大程度地减少维护。

小智 7

您可以将每个操作拆分为以下文件格式:

名为“测试操作”的文件夹

.github/test-action/action.yml

有内容

  name: test-action
  description: test action
  inputs:
    test_input:
      description: key
      required: true
  runs:
    using: composite
    steps:
      - name: echo test
        shell: bash
        run: |
          echo ${{inputs.test_input}}
Run Code Online (Sandbox Code Playgroud)

然后你可以从任何 yml 引用该操作:

  - name: test-action
    uses: ./.github/test-action
    with:
      test_input: "test-string-value"
Run Code Online (Sandbox Code Playgroud)

这里的关键是确保指定的操作文件夹中的文件名为“action.yml”


ban*_*yan 1

似乎没有办法,因为 CircleCI 允许定义一组步骤的命令:https://github.community/t5/GitHub-Actions/reusing-sharing-inheriting-steps- Between-jobs-declarations/td-p /37849

此时此刻,我想我们可以repository_dispatch作为一种解决方法。在这个示例中,它处理存储库之间的事件,但我认为我们可以在同一个存储库中应用它: https: //blog.marcnuri.com/triggering-github-actions-across- Different-repositories/