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

Inputs with - are hard to test due to shells not supporting env variables with - in the name #629

Open
estahn opened this issue Nov 10, 2020 · 4 comments · May be fixed by #1659
Open

Inputs with - are hard to test due to shells not supporting env variables with - in the name #629

estahn opened this issue Nov 10, 2020 · 4 comments · May be fixed by #1659
Labels
core enhancement New feature or request

Comments

@estahn
Copy link

estahn commented Nov 10, 2020

Describe the bug

I'm trying to test my action and according to the code the input variables seem to be injected through input variables. See

process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || ''

Given the GITHUB_TOKEN is provided via with:

with:
  repo-token: ...

This would result in INPUT_REPO-TOKEN as an environment variable. Which is invalid.

The following is therefore not possible:

INPUT_REPO-TOKEN=$GITHUB_TOKEN ts-node src/main.ts
@estahn estahn added the bug Something isn't working label Nov 10, 2020
el7cosmos added a commit to el7cosmos/toolkit that referenced this issue Apr 27, 2021
actions#629 Dashed environment variable is invalid in most system
@thboop thboop added the core label Apr 30, 2021
@luketomlinson
Copy link
Contributor

Hi @estahn thanks for opening an issue! Do you have a small example where this is failing for you? Is this OS specific?

@thboop
Copy link
Collaborator

thboop commented Jun 1, 2021

Going to close this, we can reopen once we understand the issue better!

@thboop thboop closed this as completed Jun 1, 2021
@dvargas92495
Copy link

INPUT_REPO-TOKEN is an invalid environment variable name and therefore you cannot test your actions locally. The proposed change I think would be to replace the - character to a character that's valid for environment variable names. For example:

name.replace(/ /g, '_').replace(/-/g, '_').toUpperCase()

@thboop thboop reopened this Jun 1, 2021
@thboop thboop added enhancement New feature or request and removed bug Something isn't working labels Jun 1, 2021
@thboop
Copy link
Collaborator

thboop commented Jun 1, 2021

I've tagged this as an enhancement to make testing easier.

Some shells don't support it, noticeably bash. But node does. If we made this change, we would also have to update it in the runner, which is where these values are set here. Unless we exported both values, this would be breaking for a lot of users, so we would need to have a grace period with this update.

For now, you can workaround this by setting the environment variable using env in bash, like env "INPUT_REPO-TOKEN=bar" bash -c "printenv | grep INPUT_REPO-TOKEN" or in node process.env["INPUT_REPO-TOKEN"]=bar

@thboop thboop changed the title getInput not working with repo-token Inputs with - are hard to test due to shells not supporting env variables with - in the name Jun 1, 2021
guyer added a commit to usnistgov/Docs4NIST that referenced this issue May 17, 2023
The GitHub Action docs
[illustrate](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs)
using hyphens in input names, and then document that names like
`octocat-eye-color` are converted to environment variables like
`INPUT_OCTOCAT-EYE-COLOR`, but these environment variable names
are [not POSIX compliant](https://stackoverflow.com/a/36992531/2019542)
and can't be accessed in many shells.
They've [known about this](actions/toolkit#629) for two years.
Grrrr.
guyer added a commit to usnistgov/Docs4NIST that referenced this issue May 17, 2023
The GitHub Action docs
[illustrate](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs)
using hyphens in input names, and then document that names like
`octocat-eye-color` are converted to environment variables like
`INPUT_OCTOCAT-EYE-COLOR`, but these environment variable names
are [not POSIX compliant](https://stackoverflow.com/a/36992531/2019542)
and can't be accessed in many shells.
They've [known about this](actions/toolkit#629) for two years.
Grrrr.
guyer added a commit to usnistgov/Docs4NIST that referenced this issue Jul 13, 2023
The GitHub Action docs
[illustrate](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs)
using hyphens in input names, and then document that names like
`octocat-eye-color` are converted to environment variables like
`INPUT_OCTOCAT-EYE-COLOR`, but these environment variable names
are [not POSIX compliant](https://stackoverflow.com/a/36992531/2019542)
and can't be accessed in many shells.
They've [known about this](actions/toolkit#629) for two years.
Grrrr.
guyer added a commit to usnistgov/Docs4NIST that referenced this issue Jul 13, 2023
The GitHub Action docs
[illustrate](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs)
using hyphens in input names, and then document that names like
`octocat-eye-color` are converted to environment variables like
`INPUT_OCTOCAT-EYE-COLOR`, but these environment variable names
are [not POSIX compliant](https://stackoverflow.com/a/36992531/2019542)
and can't be accessed in many shells.
They've [known about this](actions/toolkit#629) for two years.
Grrrr.
pdxjohnny added a commit to pdxjohnny/toolkit that referenced this issue Feb 12, 2024
Rather than just hyphens, eases calling from other contexts,
such as when testing.

Closes: actions#629
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@estahn @dvargas92495 @luketomlinson @thboop and others