GitHub 操作 workflow_call 没有使用最新的输入值
GitHub Action workflow_call does not use up to date input values
我遇到了 GitHub 操作 workflow_call
的奇怪行为。
基本上,初始设置后一切正常,但当我编辑工作流文件的输入参数时,它不使用更新的值。很难用语言来解释,所以让我举个例子。
考虑这个基本设置:
文件:开始-pipeline.yml
name: Start Pipeline
on:
workflow_dispatch:
inputs:
release_type:
required: true
default: dev
type: choice
options:
- patch
- minor
- major
jobs:
call-sub-workflow:
uses: mbongard/workflow-call-issue/.github/workflows/sub-workflow.yml@main
with:
release_type: ${{ github.event.inputs.release_type }}
文件:sub-workflow.yml
name: Sub Workflow
on:
workflow_call:
inputs:
release_type:
type: string
required: true
jobs:
my-job:
runs-on: ubuntu-latest
steps:
- name: Print Inputs
run: |
echo "Release Type: ${{ github.event.inputs.release_type }}"
然后我用值 patch 启动管道,子工作流打印输入就好了:
然后我更新工作流文件并添加一个额外的输入值,如下所示:
文件:开始-pipeline.yml
...
jobs:
call-sub-workflow:
uses: mbongard/workflow-call-issue/.github/workflows/sub-workflow.yml@main
with:
release_type: ${{ github.event.inputs.release_type }}
some_other_value: ${{ github.event.inputs.release_type }}
文件:sub-workflow.yml
...
inputs:
...
some_other_value:
type: string
required: true
jobs:
...
run: |
echo "Release Type: ${{ github.event.inputs.release_type }}"
echo "Release Type: ${{ github.event.inputs.some_other_value }}"
然后我再次 运行 管道,一次使用 release_type patch,一次使用 minor。
但是缺少值 some_other_value,请参阅:
.
我已经研究这个问题好几个小时了,但我不明白哪里出了问题。因为它似乎确实使用了文件的最新 SHA 版本,只是输入参数导致了问题。
有人知道这里发生了什么吗?
根据 documentation: "When a workflow is triggered with the workflow_call
event, the event payload in the called workflow is the same event payload from the calling workflow." In other words, the event
parameter in the github
context 调用的工作流与原始工作流相同。
因此,没有 github.event.input.some_other_value
参数,因为原始工作流程没有此输入。对于在 可重用工作流 中定义的输入,您可以使用 inputs
context,其中包含传递给可重用工作流的输入属性。
总结一下,这是一个有效的 sub-workflow.yml 文件:
name: Sub Workflow
on:
workflow_call:
inputs:
release_type:
type: string
required: true
some_other_value:
type: string
required: true
jobs:
my-job:
runs-on: ubuntu-latest
steps:
- name: Print Inputs
run: |
echo "Release Type: ${{ inputs.release_type }}"
echo "Release Type: ${{ inputs.some_other_value }}"
结果:
我遇到了 GitHub 操作 workflow_call
的奇怪行为。
基本上,初始设置后一切正常,但当我编辑工作流文件的输入参数时,它不使用更新的值。很难用语言来解释,所以让我举个例子。
考虑这个基本设置:
文件:开始-pipeline.yml
name: Start Pipeline
on:
workflow_dispatch:
inputs:
release_type:
required: true
default: dev
type: choice
options:
- patch
- minor
- major
jobs:
call-sub-workflow:
uses: mbongard/workflow-call-issue/.github/workflows/sub-workflow.yml@main
with:
release_type: ${{ github.event.inputs.release_type }}
文件:sub-workflow.yml
name: Sub Workflow
on:
workflow_call:
inputs:
release_type:
type: string
required: true
jobs:
my-job:
runs-on: ubuntu-latest
steps:
- name: Print Inputs
run: |
echo "Release Type: ${{ github.event.inputs.release_type }}"
然后我用值 patch 启动管道,子工作流打印输入就好了:
然后我更新工作流文件并添加一个额外的输入值,如下所示:
文件:开始-pipeline.yml
...
jobs:
call-sub-workflow:
uses: mbongard/workflow-call-issue/.github/workflows/sub-workflow.yml@main
with:
release_type: ${{ github.event.inputs.release_type }}
some_other_value: ${{ github.event.inputs.release_type }}
文件:sub-workflow.yml
...
inputs:
...
some_other_value:
type: string
required: true
jobs:
...
run: |
echo "Release Type: ${{ github.event.inputs.release_type }}"
echo "Release Type: ${{ github.event.inputs.some_other_value }}"
然后我再次 运行 管道,一次使用 release_type patch,一次使用 minor。 但是缺少值 some_other_value,请参阅:
我已经研究这个问题好几个小时了,但我不明白哪里出了问题。因为它似乎确实使用了文件的最新 SHA 版本,只是输入参数导致了问题。
有人知道这里发生了什么吗?
根据 documentation: "When a workflow is triggered with the workflow_call
event, the event payload in the called workflow is the same event payload from the calling workflow." In other words, the event
parameter in the github
context 调用的工作流与原始工作流相同。
因此,没有 github.event.input.some_other_value
参数,因为原始工作流程没有此输入。对于在 可重用工作流 中定义的输入,您可以使用 inputs
context,其中包含传递给可重用工作流的输入属性。
总结一下,这是一个有效的 sub-workflow.yml 文件:
name: Sub Workflow
on:
workflow_call:
inputs:
release_type:
type: string
required: true
some_other_value:
type: string
required: true
jobs:
my-job:
runs-on: ubuntu-latest
steps:
- name: Print Inputs
run: |
echo "Release Type: ${{ inputs.release_type }}"
echo "Release Type: ${{ inputs.some_other_value }}"
结果: