😇
workflow_dispatch で boolean の input を使う際にアクセスするコンテキストによる型の違い
TL;DR
inputs.hoge
はそのまま boolean として扱われて、 github.event.inputs.hoge
は string で扱われる!
なのでそれらは、
if: ${{ inputs.hoge }}
または
if: ${{ github.event.inputs.hoge == 'true' }}
で評価すると期待した動作をする。
内容
こういう Issue があって、ほんとかぁ〜?と思って実験してみた。
こういうワークフローを用意
name: workflow dispatch boolean inputs
on:
workflow_dispatch:
inputs:
boolean_input:
description: 'A boolean input'
type: boolean
required: true
default: true
jobs:
job:
runs-on: ubuntu-latest
timeout-minutes: 5
env:
GITHUB_EVENT_BOOLEAN_INPUT: ${{ github.event.inputs.boolean_input }}
INPUTS_BOOLEAN_INPUT: ${{ inputs.boolean_input }}
steps:
- name: Check value
run: |
echo "GITHUB_EVENT_BOOLEAN_INPUT is: $GITHUB_EVENT_BOOLEAN_INPUT"
echo "INPUTS_BOOLEAN_INPUT is: $INPUTS_BOOLEAN_INPUT"
- name: Run if github.event.inputs.boolean_input
if: ${{ github.event.inputs.boolean_input }}
run: |
echo "github.event.inputs.boolean_input is true"
- name: Run if inputs.boolean_input
if: ${{ inputs.boolean_input }}
run: |
echo "inputs.boolean_input is true"
- name: Don't run if github.event.inputs.boolean_input
if: ${{ ! github.event.inputs.boolean_input }}
run: |
echo "github.event.inputs.boolean_input is true"
- name: Don't run if inputs.boolean_input
if: ${{ ! inputs.boolean_input }}
run: |
echo "inputs.boolean_input is true"
- name: Run if github.event.inputs.boolean_input == 'true'
if: ${{ github.event.inputs.boolean_input == 'true' }}
run: |
echo "github.event.inputs.boolean_input == 'true' is true"
- name: Run if inputs.boolean_input == 'true'
if: ${{ inputs.boolean_input == 'true' }}
run: |
echo "inputs.boolean_input == 'true' is true"
input が true の場合
input が false の場合
結論
inputs.*
のコンテキストからアクセスする場合、その値は boolean ( true
or false
) である。
github.event.inputs.*
のコンテキストからアクセスする場合、その値は string ('true'
or 'false'
) である。
なので、
if: ${{ inputs.hoge }}
または、
if: ${{ github.event.inputs.hoge == 'true' }}
で評価すると期待した動作になる。
Discussion