actions / runner

The Runner for GitHub Actions :rocket:
https://github.com/features/actions
MIT License
4.93k stars 971 forks source link

Reusable workflow input with default string is not used when the calling input passed an empty string. #2907

Open sqin2019 opened 1 year ago

sqin2019 commented 1 year ago

Describe the bug Reusable workflow input (string) with default is not used when the calling input passed an empty string. To Reproduce Steps to reproduce the behavior:

  1. reusable workflow
    
    name: 'reusable_workflow'
    on:
    workflow_call:
    inputs:
      message:
        description: 'message.'
        type: 'string'
        default: 'default message'
        required: false
    jobs:
    print-inputs:
    runs-on: ubuntu-latest
    steps:
      - name: job summary
        run: |
          echo "message: ${{ inputs.message }}" >> $GITHUB_STEP_SUMMARY
2. create a caller workflow that calls 1

name: 'caller' on: workflow_dispatch: inputs: message: description: 'message' type: 'string' required: false jobs: call-reusable-workflow: uses: '.../reusable-workflow.yml@main' with: message: ${{ inputs.message }}


3. trigger the caller workflow without providing a message input

**Expected behavior**
should print `message: default message`

## Job Log Output
But print `message:`

## Runner Version and Platform
Version of your runner?

ubuntu-latest
orphefs commented 9 months ago

I am experiencing the same issue. Are there any updates on this?

EstartuPrime commented 9 months ago

I searched for the documentation online of the inputs default values. But i'm sorry, i can not find them. In VSCode and the Github Actions extension installed, i will see this as documentation for the default values of the different types of inputs:

If a default parameter is not set, the default value of the input is false for boolean, 0 for a number, and "" for a string.

So your workflow call (named: "caller") will pass an empty string to the reusable workflow (named: "reusable_workflow") and that's why the output is empty.

HTH Alex

rakkarage commented 2 months ago

Same :)

If a default parameter is not set, the default value of the input is false for boolean, 0 for a number, and "" for a string.

That does seem to be how it is currently working. But it doesn't make sense because it removes the whole reason for using default values? Must be a bug?

Works if you move default handling from called to caller. can then remove default from called and set required to true. Idk.

guillermo-ampie commented 1 month ago

Default values are not working for me in the caller/called workflow setting. A year later, this feature still does not work!

EstartuPrime commented 1 month ago

Works if you move default handling from called to caller. can then remove default from called and set required to true

I would recommend using this solution. When changing the handling to your expected/suggested behavior. They will probably break a lot of other workflows that has a default value but have also the option to supress this by passing an empty string.

Moving the default to a proper place (where user inputs are possible and optional) is in my opinion the better way to solve this.

I ran into the same problem, thats why i found this issue. But after thinking about, how it works and what i tried to do, i saw that my first approach was simply not correct, because an empty string is an empty string and not nothing/NULL/void/undefined.

JM2C ☺️