Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading