Why doesn’t this work:
contains(github.event.inputs.translated_content || env.DEFAULT_TRANSLATED_CONTENT, 'true')
It evaluates to falsy if ${{ github.event.inputs.translated_content }}
is ‘true’ and env.DEFAULT_TRANSLATED_CONTENT
is ‘true’.
I’m using this logic to be able to use the dispatch inputs or the cron schedule.
When the cron job runs, I think github.event.inputs.translated_content
becomes some form of null
or unset. So in those cases it goes into the ||
or-case and env.DEFAULT_TRANSLATED_CONTENT
is true so the whole expression ultimately evaluates to truthy.
My use case is that I want the workflow to be driven either by cron or by manual trigger. If it’s running in ccron job, it should default back to the env default set at the top of the YAML file. If it’s run manually, I only care about what the output of github.event.inputs.translated_content
is (because the user had a chance to type “false” in the little UI that pops up).
I don’t even know if this syntax is possible, but this would be WRONG:
contains(github.event.inputs.translated_content, 'true') || contains(env.DEFAULT_TRANSLATED_CONTENT, 'true)
If this was Python (for example) I would have typed something like this:
if inputs.translated_content is None or inputs.translated_content == '':
# rely on env vars
verdict = os.environ.get('DEFAULT_TRANSLATED_CONTENT') == 'true'
else:
# rely on the input
verdict = inputs.translated_content == 'true'
I’m trying to cram ^ that logic into the if:
statement on a workflow step.