我如何将参数传递inputs.custom
给此操作代码:
jobs:
test-custom:
name: Test Custom
uses: ./.github/workflows/work4-${{ inputs.custom }}.yml
完全工作的示例:
第一个工作流程work1-build.yml
:
name: Start workflow fail
on: [push]
jobs:
build-fail:
name: Build with other workflow
uses: ./.github/workflows/work3-build-fail.yml
with:
custom: custom-name1
第二个工作流程work3-build-fail.yml
:
name: Build fail with input test
on:
workflow_call:
inputs:
custom:
description: Some custom string
required: true
type: string
jobs:
test-custom:
name: Test Custom
uses: ./.github/workflows/work4-${{ inputs.custom }}.yml
第三工作流程work4-custom-name1.yml
name: Custom 1
on:
workflow_call
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "IN CUSTOM 1"
上面的示例使 GitHub 响应错误:
Invalid workflow file
error parsing called workflow
".github/workflows/work1-build.yml"
-> "./.github/workflows/work3-build-fail.yml" (source branch with sha:720087c8794e76f52277f9b1229b44ea65ab89d5)
--> "./.github/workflows/work4-${{ inputs.custom }}.yml"
: failed to fetch workflow: workflow was not found.
我可以成功添加${{ inputs.custom }}
到:
test-print:
runs-on: ubuntu-latest
name: Print input
steps:
- name: Step print input
run: echo ${{ inputs.custom }}
文档不包含任何uses
参数化示例:
https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses
我找到了证明这是不可能的文档。没有支持信息表明该uses
密钥可以访问任何上下文。
请参阅:https ://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
我相信这是 GitHub Actions 的架构限制,看来他们希望在所有作业开始时解析所有工作流程/操作,因此动态解析是不可能的。
从uses: ./.github/actions/run-${{ inputs.custom }}看来,您正在重用驻留在同一存储库中的工作流程。根据调用可重用工作流程,“您可以使用uses关键字来调用可重用工作流程。与在工作流程中使用操作时不同,您可以直接在作业中调用可重用工作流程,而不是从作业步骤中调用。 ”。因此,您需要修复调用可重用工作流程的语法。
感谢您指出这一点 - 我更正了示例,因为我刚刚粘贴了 GitHub 文档中的示例。无论如何,在工作层面上这也不起作用:D
inputs请也更新您的工作流程。谢谢!
我的猜测是,您不能在 上使用输入uses:,如果您查看您的作业,所有可重用操作/工作流程都是在运行任何内容之前的源代码。既然您引用的是操作而不是工作流程,您的错误是否有所不同?
@aknosis 问题已更新为完整的工作示例,因此希望没有任何疑问