Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INPUT_* environment variables are missing in composite actions #665

Open
airtower-luna opened this issue Aug 17, 2020 · 16 comments
Open

INPUT_* environment variables are missing in composite actions #665

airtower-luna opened this issue Aug 17, 2020 · 16 comments
Labels
enhancement New feature or request

Comments

@airtower-luna
Copy link

According to the documentation actions should receive their input values as environment variables prefixed with INPUT_ in addition to the inputs context. These environment variables are missing for composite actions.

To Reproduce
Steps to reproduce the behavior:

  1. Create a composite action with one or more inputs, and a step that outputs the associated INPUT variables:
inputs:
  foo:
    description: 'Test input'
    required: yes
runs:
  using: composite
  steps:
    - run: |
        echo "FOO: ${INPUT_FOO}"
      shell: bash
  1. Use the action in a workflow:
steps:
  - uses: ./example-action
    with:
      foo: 'bar'
  1. Observe the lack of value after the FOO: prefix.

I have an example action and workflow (the uses: ./composite-action step) that demonstrate the issue and the obvious workaround. There's a workflow run as well (check the "Run /./composite-action" step).

Expected behavior
Steps should be able to read inputs via environment variables, INPUT_FOO in the example above, INPUT_NUM1 (to 4) in my reproducer.

Runner Version and Platform

Version of your runner?

  • 2.272.0

OS of the machine running the runner? OSX/Windows/Linux/...

  • Ubuntu 20.04.1 LTS (Github hosted runner VM)

Job Log Output

From the workflow run linked above:

Run ./composite-action
  with:
    num1: 1
    num2: 4
    num3: 0
    num4: 0
Show INPUT vars
  INPUT_NUM1 = 
  INPUT_NUM2 = 
  INPUT_NUM3 = 
  INPUT_NUM4 = 
Add numbers

Credit

I became aware of the issue thanks to a post on the Github community forum and tried to reproduce the issue out of curiosity.

@airtower-luna airtower-luna added the bug Something isn't working label Aug 17, 2020
@ericsciple
Copy link
Collaborator

When authoring a composite action, inputs must be mapped into inner steps using GitHub Actions expressions.

For example, map into the script directly:

inputs:
  foo:
    description: 'Test input'
    required: yes
runs:
  using: composite
  steps:
    - run: |
        echo "FOO: ${{inputs.foo}}"
      shell: bash

Or for example, map into the script indirectly via env var:

inputs:
  foo:
    description: 'Test input'
    required: yes
runs:
  using: composite
  steps:
    - run: |
        echo "FOO: $MY_VAR"
      shell: bash
      env:
        MY_VAR: ${{ inputs.foo }}

@ericsciple
Copy link
Collaborator

We need to update the referenced doc

@ericsciple ericsciple added documentation and removed bug Something isn't working labels Aug 19, 2020
@airtower-luna
Copy link
Author

airtower-luna commented Aug 19, 2020

Fair enough, but wouldn't it be simpler to have the same behavior across all kinds of actions? Or is there a technical reason not to provide the INPUT_ environment variables?

@amis92
Copy link

amis92 commented Aug 20, 2020

I've hit that as well.

After some thought I imagine it's because if, in future, they enable composite steps to contain other uses actions (not just shell runs), this would cause confusion in those sub-actions which inputs are theirs, and which are the parent composite action's.

Better documentation definitely will help there. :) edit I think it's also important to include the inputs context in the Contexts documentation, because currently it's not there.

@thepwagner
Copy link

👋 I've been using a workaround like _ericsciple's:

inputs:
  branches:
    description: 'Branches to update'
    required: false
runs:
  using: "composite"
  steps:
    - run: my-awesome-action.sh
      shell: bash
      env:
        INPUT_BRANCHES: ${{ inputs.branches }}

I want to map the variable as INPUT_BRANCHES so I can reuse getInput() from the Actions SDK in my implementation.
Using ${{input.branches}} directly in the command doesn't work (Actions SDK can't find it).

I'd dig a way to say "please forward ALL my action.yml:inputs to this step" without mapping every key. env: actionInputs(), actionInputs: true?
Forwarding them without special configuration is 👍 too, but changing the exposure of existing composite actions is, as noted, bad.

(I wound up here after adding an input and forgetting about needing this hack to forward it. ~10% of my current action.yaml is input forwarding boilerplate)

expipiplus1 added a commit to expipiplus1/action-automation that referenced this issue Oct 29, 2020
mbr added a commit to 49nord/nix-container-build that referenced this issue Nov 1, 2020
mearns added a commit to mearns/node-template that referenced this issue Nov 20, 2020
BYK added a commit to getsentry/action-prepare-release that referenced this issue Dec 9, 2020
They don't work in composite actions, and this is not documented because why not? See actions/runner#665
wdconinc added a commit to cvmfs-contrib/github-action-cvmfs that referenced this issue Dec 15, 2020
wdconinc added a commit to cvmfs-contrib/github-action-cvmfs that referenced this issue Dec 15, 2020
petricm pushed a commit to petricm/github-action-cvmfs that referenced this issue Dec 16, 2020
zregvart added a commit to syndesisio/backport-action that referenced this issue Dec 22, 2020
zregvart added a commit to syndesisio/backport-action that referenced this issue Dec 22, 2020
iainjreid added a commit to emphori/actions that referenced this issue Dec 30, 2020
As per the documentation, we were using INPUT_* variables to pass the
action input parameters to the scripts that expected them.

But there seems to be either a mistake in the documentation, or a bug in
the runners, as can be found here:

actions/runner#665
jtdor added a commit to jtdor/build-deb-action that referenced this issue Feb 5, 2021
fabriciomurta added a commit to fabriciomurta/docs that referenced this issue Mar 2, 2021
Adds information regarding the INPUT_ environment variable conversion as discussed at actions/runner#665.
tomgoren pushed a commit to wistia/github-action-build-workflow-images that referenced this issue Apr 7, 2021
siong-chin added a commit to ccdc-opensource/commit-hooks that referenced this issue Apr 19, 2021
siong-chin added a commit to ccdc-opensource/commit-hooks that referenced this issue Apr 20, 2021
CSchoel added a commit to CSchoel/release-notes-from-changelog that referenced this issue May 25, 2021
@nathanblair
Copy link

The documentation here should also reflect the special behavior mentioned at the top of the page. Probably more importantly in the section more explicitly dedicated to with.

toniedzwiedz pushed a commit to wttech/AEM-Rules-for-SonarQube that referenced this issue Apr 6, 2022
elgohr added a commit to elgohr/Publish-Docker-Github-Action that referenced this issue Apr 9, 2022
matthewbauer added a commit to matthewbauer/dle-github-actions that referenced this issue May 4, 2022
@maxsxu
Copy link

maxsxu commented May 27, 2022

The issue still exists but thanks to the above workaround, which works.

Wondering any updates or plans on this?

@diepes
Copy link

diepes commented Sep 5, 2022

I seem to have stumbled on another corner case in an action.

The inputs.xyz seem to disappear after a step that uses a with:, they (inputs.) are no longer available for other steps.

ci.yaml. (steps: uses action1 passing inputs in with:)
action1.yaml ( halfway through uses action2 passing inputs in with:)
after this step in action1.yaml all the input.xyz seem to be empty.

Work around by adding all to env.
echo "password=${{ inputs.password }}" |tee -a $GITHUB_ENV

@perj
Copy link

perj commented Feb 15, 2023

Note that Github recommends to not use ${{ inputs.x }} directly in shell scripts, due to quoting issues.
It's better to always first set them to environment variables. Why not one called INPUT_x such that if this is ever fixed that is the same variable name...

https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#example-of-a-script-injection-attack

@y-nk
Copy link

y-nk commented Jan 11, 2024

there's an issue with this, is that we can't use @actions/core's getInput because it relies on process.env.INPUT_xxx to function.

https://github.com/actions/toolkit/blob/1b5a6e26f42769414fe2302e6a6e8b5ac7bf9600/packages/core/src/core.ts#L126-L138

For people interested in fixing the above, an easy fix is to manually provide the env var such as:

env:
  INPUT_FOO: ${{ inputs.foo }}

it's not ideal, but i'll fix the glue with what's expected from @actions/github-script

melMass added a commit to melMass/actions that referenced this issue Jun 1, 2024
this is a known thing with composite:
- actions/runner#665 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

14 participants