Dashes in Docker action inputs produce unreadable env vars

When using a Docker action with inputs containing dashes in names, resulting env var names also contain dashes, but afaik these env vars cannot be read in sh / bash. Is it possible to replace ‘-’-s with ‘_’-s in env vars?

I’m using dashes because this seems to be a common convention for action input names.

Sample action:

# action.yml
name: 'Sample action'
inputs:
  build-options:
    description: "Additional options."
    default: "--compress"
  registry-url:
    description: 'Registry URL'
    default: 'docker.pkg.github.com/etc'
runs:
  using: 'docker'
  image: 'Dockerfile'
  entrypoint: '/main.sh'

Generated env vars:

-e INPUT_BUILD-OPTIONS -e INPUT_REGISTRY-URL

Hi @zmeyc,

Could you please explain more about your sh / bash script? Where’s it and how you write the code?
As doc mentioned, to pass inputs to the Docker container, you must declare the input using inputs and pass the input in the args keyword.

inputs:
  who-to-greet:  # id of input
    description: 'Who to greet'
    required: true
    default: 'World'
outputs:
  time: # id of output
    description: 'The time we greeted you'
runs:
  using: 'docker'
  image: 'Dockerfile'
  args:
    - ${{ inputs.who-to-greet }}

And in entrypoint.sh, use format below to read the input value.

#!/bin/sh -l

echo "Hello $1"
....

Thanks

1 Like

Passing inputs as ‘args’ is inconvenient, because they aren’t named. If there are many inputs, mapping them to $1 $2 $3 etc and syncing their order with script’s is error-prone.

I see that for each input a corresponding INPUT_UPPERCASED-INPUT-NAME environment variable is passed to docker, but variable names contain dashes, which makes impossible reading multiword ones from script.

So I’m asking if it would be possible to adjust env var name mangling to replace dashes with underscores? It should be a trivial change but would make passing vars to scripts much more convenient.

UPD: I’m currently using this workaround:

# Convert input names to POSIX-compatible
INPUT_BUILD_OPTIONS="$(env | sed -n 's/^INPUT_BUILD-OPTIONS=\(.*\)/\1/p')"
INPUT_REGISTRY_URL="$(env | sed -n 's/^INPUT_REGISTRY-URL=\(.*\)/\1/p')"
...etc...

Hi @zmeyc,

Thanks for your reply!

As doc mentioned, the environment variable created converts input names to uppercase letters and replaces spaces with _ characters, while it will not convert dash - to _ automatically.

Your workaround is great, can read the env var with _ instead.

But in my mind, you can directly use _ instead of dash - in the action.yaml for the inputs, no need to convert in the sh file then.

Regards

1 Like

Hi @weide-zhou ,

Thanks for the link! It’s possible to use _-s in action.yaml, but I’m using dashes because most other actions (including official ones) also use dashes and it seems to be a common convention. As POSIX disallows '-'s in env var names, I think it’s worth adding - to _ conversion on Github side as well.

Hi @zmeyc,

After further checking, i realize that they are different for the two inputs: ‘INPUT_WHO_TO_GREET’ and ‘INPUT_WHO-TO-GREET’. Both are accepted in the action.yaml and if conversion happens, it could cause error. Hence, as you shown, can read the input from env as a workaround.

Thanks.

edited- correct the description.

1 Like

I’m sorry, but I really don’t think that is the solution here. This should really solved by having the toolkit update parse these inputs and create variables based on the POSIX standard.

Sure I could create actions with inputs that don’t have -, but now I’m creating a library that’s unlike official actions and other popular ones.

Like @zmeyc said:


What I’d really like to do is open the discussion is to how we can move forward, without changing the inputs. And if it’s reasonable to change the toolkit to provide that functionality.

Here is a related issue: https://github.com/actions/toolkit/issues/219