Handling different input sources from workflow_dispatch and repository_dispatch

I have a test job that is supposed to be triggered in one of three ways: Automatically on Pull Request, manually by workflow dispatch, and automatically by a separate job that uses repository dispatch.*

Both workflow dispatch and repository dispatch should carry the same input information, while automatic pull request triggers don’t carry any input information at all. But the workflow dispatch has the input in the context github.events.input while repository dispatch has it at github.events.client_payload.

I tried and failed to coalesce these values into environment variables with bash:

echo "foo=${${{ github.event.client_payload.foo }}:-${{ github.event.input.foo }}:-default}" >> $GITHUB_ENV

This returns an error for bad substitution. I’m not entirely sure what that means, and can’t find much pertinent information, but it seems that bash coalescence is intended to be run on variables, not values.

Maybe I misunderstood the above error, but the more general question is:

Is there a viable best practice to handle these different input sources and funnel whichever one applies into my final config? And is there a way to also handle default values in case of pull requests?

So, mixing ${{...}} with ${...} is asking for pain.

There are various ways to approach this.

One is to use

   client_payload_foo: ${{ github.event.client_payload.foo }}
   input_foo: ${{ github.event.input.foo }}
   - run: |
        echo ${client_payload_foo:-${input_foo:-default}}

Another would be to use jq and just get all the pieces from the $GITHUB_EVENT_PATH file (esp. using the // operator)