Pass result of expression to custom Github Action argument


My Github repositories for Docker images follow the convention of: author/docker-projectName, while images pushed to Docker Hub strip the docker- prefix for brevity reasons, leavig it with author/projectName.

I also made Github action that syncs README from Github to Docker Hub, which takes an optional slug: parameter.

The removal of the docker- prefix, is usually possible with a simple bash expression such as ${GITHUB_REPOSITORY/docker-}.

However, it seems it’s currently impossible to cimbine the two.

- name: Sync with Docker Hub
  uses: meeDamian/sync-readme@v1.0.5
    pass: ${{ secrets.DOCKER_PASS }}
    slug: ${GITHUB_REPOSITORY/docker-}

The above passes the literal string ${GITHUB_REPOSITORY/docker-} to my action, which isn’t very useful. I also tried with various other approaches of what to put there, but nothing seems to be working.

  1. Is it possible to pass a result of an expression to the action input?
  2. Is it possible to share variables across steps?
  3. When will the content of steps context be populated?  As access to \<step id\>.outputs.\<output name\> property could also help.
  4. Is the only way to pass arguments to actions now is to either hardcode them, or use one of the raw pre-defined ${{ github.* }} variables?

Thank you :blush: 

Actions are not process through a shell so shell expressions are not going to be executed on values passed to arguments.   

Outputs of steps are populated into the context after the step completes and should be available to pass into subsiquent steps using ${{ steps.<step id>.outputs.<output name> }} as the value for a given input.  Each step is run in its own process so you can’t share environment variables between processes, they would need to be explicitly mapped as outputs and passed in to the next step. 

Thank you @abjchr !

Are you actually  getting steps populated?  For me they always seem to be empty.

steps are always empty for me - maybe it’s only populated if an step runs an action that has outputs. Also I don’t think a “run:” step can set outputs, so you can’t send the output from simple shell commands as input to a following action step.

You would have to write a custom docker action that would build and run a container just to send ${GITHUB_REPOSITORY/docker-} to an output for use in the next step. Talk about overkill :slight_smile:

Actually you might be able to use to run a small script to .replace() on your string, the result of your script is an output on this action.

1 Like

I was almost able to get something working using the github-script action, but the show stopper is that it JSON encodes its outputs, so you end up with an extra set of quotes inside your variable

The best path forward I could think of is to ask the github-script maintains to add an option for how to encode the result:

1 Like