toolkit icon indicating copy to clipboard operation
toolkit copied to clipboard

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

Open estahn opened this issue 5 years ago • 5 comments

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 https://github.com/actions/toolkit/blob/e7eb2c741847a05686a1b8df93dea4b244640b17/packages/core/src/core.ts#L86

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 avatar Nov 10 '20 12:11 estahn

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

luketomlinson avatar May 19 '21 19:05 luketomlinson

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

thboop avatar Jun 01 '21 19:06 thboop

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()

dvargas92495 avatar Jun 01 '21 20:06 dvargas92495

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 avatar Jun 01 '21 22:06 thboop

As mentioned in https://github.com/actions/toolkit/pull/1740, since the GHA Runner doesn't perform - to _ conversion when setting the INPUT_* environment variables for NodeJS actions, performing this conversion on the client side would prevent those inputs from being read. Any change in this behavior needs to be made solely in the runner code.

rindeal avatar Aug 31 '24 22:08 rindeal