Common Mistakes
Multi Line Expressions in if
Wrong
if: |
${{
success()
&& needs.test.result == 'success'
}}
this ends up like "${{ format('{0}\n', success() && needs.test.result == 'success') }}"
and is equivalent to "always()"
Correct
if: |-
${{
success()
&& needs.test.result == 'success'
}}
if: |
success()
&& needs.test.result == 'success'
if: |-
success()
&& needs.test.result == 'success'
Multi Line Expressions with non string type
Wrong
matrix: |
${{
fromjson('{
"Hello": ["World"]
}')
}}
this ends up like "${{ format('{0}\n', fromjson('{\n "Hello": ["World"]\n }')) }}"
and is equivalent to "Object\n"
Correct
matrix: |-
${{
fromjson('{
"Hello": ["World"]
}')
}}
Passing parameter as boolean in Reusable Workflows
Wrong for push
on:
push:
workflow_dispatch:
inputs:
BOOLEAN:
type: boolean
jobs:
test:
uses: ./.github/workflows/workflow.yml
with:
BOOLEAN: ${{ inputs.BOOLEAN }}
Correct
on:
push:
workflow_dispatch:
inputs:
BOOLEAN:
type: boolean
jobs:
test:
uses: ./.github/workflows/workflow.yml
with:
BOOLEAN: ${{ inputs.BOOLEAN || false }}
Passing string as number in Reusable Workflows
Wrong
on:
push:
workflow_dispatch:
inputs:
NUMBER: {}
jobs:
test:
uses: ./.github/workflows/workflow.yml
with:
NUMBER: ${{ inputs.NUMBER }}
Wrong for push
on:
push:
workflow_dispatch:
inputs:
NUMBER: {}
jobs:
test:
uses: ./.github/workflows/workflow.yml
with:
NUMBER: ${{ fromJson(inputs.NUMBER) }}
Correct
on:
push:
workflow_dispatch:
inputs:
NUMBER: {}
jobs:
test:
uses: ./.github/workflows/workflow.yml
with:
NUMBER: ${{ fromJson(inputs.NUMBER || '0') }}
on:
push:
workflow_dispatch:
inputs:
NUMBER: {}
jobs:
test:
uses: ./.github/workflows/workflow.yml
with:
NUMBER: ${{ inputs.NUMBER && fromJson(inputs.NUMBER) || 0 }}
Accessing index by actions context in if
Wrong
if: steps[${{ steps.token.outputs.y }}].outputs.test == 'ok'
This ends up as ${{ success() && format('steps[{0}].outputs.test == ''ok''', steps.token.outputs.y) }}
and is similar to ${{ success() }}
or ${{ success() && 'Non Empty String' }}
.
Correct
if: steps[steps.token.outputs.y].outputs.test == 'ok'