Adding a binary to the PATH from a Docker GitHub Action for use by later workflow steps

I am trying to create a Dockerfile based action that adds a program to the $PATH so that it can be used by later actions. My action runs code like this:

mkdir -p $GITHUB_WORKSPACE/bin
echo "echo Hello, world!" > $GITHUB_WORKSPACE/bin/hello-world
echo "::add-path::$GITHUB_WORKSPACE/bin"

My test workflow uses this like so:

jobs:
test:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1.0.0
      - name: Add program to path
        uses: ./
      - name: Use program
        run: hello-world

This fails because while the program has been added to $GITHUB_WORKSPACE/bin/hello-world the value of $GITHUB_WORKSPACE is different in the action and in the workspace step.

In the action it is /github/workspace/, while in the workflow it is /home/runner/work/setup-gleam/setup-gleam/, so the $PATH addition set by the action is not correct.

How can I add a file to a directory from a dockerfile based GitHub action so that it is on the path for the rest of the workflow? It seems that there is no writable $PATH directory shared between dockerfile actions and non-dockerfile actions.

As you said : In the action it is /github/workspace/, while in the workflow it is /home/runner/work/setup-gleam/setup-gleam/, so the $PATH addition set by the action is not correct. Yes, Actions that run in Docker containers have static directories under the /github path. https://help.github.com/en/actions/automating-your-workflow-with-github-actions/virtual-environments-for-github-hosted-runners#docker-container-filesystem

I would suggest you to run add path scripts directly in bash scripts. Please check my example below.

add path.png

If this work around could not reach your requirement, please let me know your scenario and why you need to run add path command inside a docker action .

1 Like