Can you implicitly pass inputs from workflows to actions? I’d like to not clobber defaults #118925
Replies: 1 comment
-
Hello there, Yes, you can implicitly pass inputs from workflows to actions in GitHub Actions. However, it's important to note that if an action has default input values and you want to use them, you should avoid specifying those inputs in your workflow file. Here's an example: name: My Workflow
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run my action
uses: username/myaction@v1
with:
input1: value1
# Don't specify input2 here if you want to use the default value
In this example, input1 is explicitly passed a value, while input2 (assuming it has a default in the action’s action.yml file) will use its default value.
Remember, the with keyword in the workflow file is used to specify the inputs for an action. If an input is not specified in the with section, and that input has a default value in the action’s action.yml file, then the default value will be used.
I also got this example from chatgpt, you also can find further information from it.
I think this might help you!
Happy coding! |
Beta Was this translation helpful? Give feedback.
-
Disclaimer undocumented easter egg (since second half of 2019, inherited from azure pipelines) of actions/runner allows to trigger the default on empty var - name: test with possibly no value
uses: ./
with:
${{ insert }}: |-
${{ vars.something
&& fromjson(format('{{"test": {0}}}', tojson(vars.something)))
|| fromjson('{}') }} Trivia the much better to read Just replace
then you might have what you want. Should also pass the official GitHub Actions VSCode Extension, but doesn't work with third party tools like actionlint and act. |
Beta Was this translation helpful? Give feedback.
-
I have several actions, each of which have some inputs and many of them have default values. I have a few workflows which call different subsets of those actions. I'd like the workflows to also have some optional inputs that correspond to some of the action inputs, but I can't figure out how to do this in a clean way.
I could add the default value to the workflow as well, but this creates a maintenance nightmare in case it needs to change later.
If I leave the default blank, then the action gets an empty string instead of its own default value.
Is there some other option I'm missing? Can an action access the inputs of the workflow or action that invoked it? Then at least I could use an expression in case the current input is an empty string.
In most cases, the values for these inputs are going to be constant for an entire repo or organization. Are repo/org variables a good solution? Can you set the default value for workflow inputs to be one of the repo variables?
This seems like it could be helpful. I do wish the default values were bubbled up to the top, because it's better for self-documenting code for people using the workflows and actions: https://dev.to/mrmike/github-action-handling-input-default-value-5f2g And of course it makes the action code itself less readable.
Beta Was this translation helpful? Give feedback.
All reactions