Sky*_*rth 5 continuous-integration yaml github-actions
我正在为市场开发 GitHub Action。它有各种带有默认值的输入。这些输入之一恰好是boolean我用来切换调试状态的输入。
这是我的布尔输入定义:
inputs:
debug_mode:
description: "Controls the debug mode, boolean, true is for on. When turned on, it'll output certain information on certain steps. Mainly used for development, but use it as you please to inspect your env and variables."
type: boolean
required: false
default: false
Run Code Online (Sandbox Code Playgroud)
boolean正如您所看到的,它具有带默认值的类型false。然后,在其中一个步骤中,我检查debug_mode以确定是否运行该步骤。但是,它没有按预期工作:
steps:
- name: Dump debug_mode
run: echo "debug_mode is ${{ inputs.debug_mode }}"
shell: bash
- name: Dump context
if: ${{ inputs.debug_mode}}
uses: crazy-max/ghaction-dump-context@v2
- name: Dump build_path
if: ${{ inputs.debug_mode}}
run: echo "build_path is ${{ inputs.build_path }}"
Run Code Online (Sandbox Code Playgroud)
当操作运行时,我看到它debug_mode is false是通过 打印的echo。尽管如此,“转储上下文”步骤即使为debug_mode假也会运行。我尝试显式给出此输入值true或false,也尝试在不分配值的情况下(使用默认值),仍然没有得到一致的结果。我在某处读到这可能是由于我正在 via 运行的事实workflow_run。
为了便于参考和更轻松地检测问题,以下是原始来源:
debug_mode在间隙中,我的目标是仅在时才运行某些步骤true。如果可能的话,我想使用boolean类型,因为字符串在语义上是不正确的。
先感谢您。
对于操作,type不支持参数inputs。
也许,您认为它会相同,on.workflow_dispatch.inputs.<input_id>.type但事实并非如此。
至于default,它需要一个string值,而不是布尔值。请在此处查看其 JSON 架构。VS Code 使用此 JSON 架构自动突出显示这些问题。您可能必须安装其GitHub Actions扩展。
如果您想在布尔上下文下处理它,请使用'true'或'false'作为字符串并相应地使用它。
所以,inputs将是:
inputs:
debug_mode:
description: '...'
required: false
default: 'false'
Run Code Online (Sandbox Code Playgroud)
对于true这种情况,if条件是:
if: ${{ inputs.debug_mode == 'true' }}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12442 次 |
| 最近记录: |