简体   繁体   中英

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:
    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.

Runner path is stored in $RUNNER_WORKSPACE environment variable and can be used to get the right path.

echo "::add-path::$GITHUB_WORKSPACE/bin" # Make it accessible from docker containers
echo "::add-path::$RUNNER_WORKSPACE/$(basename $GITHUB_REPOSITORY)/bin" # Make it accessible from runner

But it looks more like a workaround than solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM