can github composite action inputs use self inputs as default values?

Advertisements

does this work?

name: "test"
description: "test"
inputs:
  a:
    description: "Description of a"
    required: false
    default: ${{ inputs.b }}
  b:
    description: "Description of b"

runs:
  using: "composite"
  steps:
    - name: docker-login-build-push
      run: |
        echo {{ inputs.a }}
        echo {{ inputs.b }}

      shell: bash

I want if the value of a is not set the value of b be set as the value of a.

>Solution :

Yep, in GitHub Actions, you can totally use self inputs as default values for other inputs in composite actions. The example you shared looks good to go!

You defined two inputs: a and b. The default value for a is set to ${{ inputs.b }}. This means that if you don’t explicitly provide a value for a, it’ll default to the value of b.

In the runs section, you’ve got a step called docker-login-build-push. Inside that step, you’re printing out the values of a and b using echo. Sweet! That should give you the expected output when you run the composite action.

Just a small note: The syntax you used (echo {{ inputs.a }}) isn’t quite right for referencing inputs in a composite action. Instead, use ${{ inputs.a }} and ${{ inputs.b }}.

All in all, your code snippet looks solid, and it should do the trick. The value of b will serve as the default value for a if you don’t explicitly provide a.

Leave a ReplyCancel reply