简体   繁体   English

从 Docker GitHub 将二进制文件添加到 PATH 供后续工作流步骤使用的操作

[英]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.我正在尝试创建一个基于 Dockerfile 的操作,该操作将程序添加到$PATH以便以后的操作可以使用它。 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.这失败了,因为当程序已添加到$GITHUB_WORKSPACE/bin/hello-world时, $GITHUB_WORKSPACE的值在操作和工作区步骤中是不同的。

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.在动作中是/github/workspace/ ,而在工作流中是/home/runner/work/setup-gleam/setup-gleam/ ,所以动作设置的$PATH添加不正确。

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?如何将文件从基于 dockerfile 的 GitHub 操作添加到目录,以便它位于工作流的 rest 的路径上? It seems that there is no writable $PATH directory shared between dockerfile actions and non-dockerfile actions.似乎 dockerfile 操作和非 dockerfile 操作之间没有共享可写的$PATH目录。

Runner path is stored in $RUNNER_WORKSPACE environment variable and can be used to get the right path. Runner 路径存储在$RUNNER_WORKSPACE环境变量中,可用于获取正确的路径。

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.但它看起来更像是一种解决方法而不是解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将值传递给 docker 组成从 GitHub 操作工作流 - How do I pass values to docker compose from GitHub Action workflow 使用 GitHub 操作在自定义 docker 容器内运行步骤时出现问题 - Problem running steps inside custom docker container using GitHub Action 如何从 GitHub 操作缓存 docker 图像 - How to cache a docker image from a GitHub Action 如何在 Google Cloud Build 中构建 Docker 映像并在后续构建步骤中使用? - How can I build a Docker Image in Google Cloud Build and use in later Build Steps? 有没有办法使用 github 操作插件 docker/build-push-action@v1 为 docker build 设置路径 - Is there a way to set path for docker build with the github action plugin docker/build-push-action@v1 无法从 Github Action 将 docker 镜像推送到 docker hub - Cannot push docker image into docker hub from Github Action 带有 selenium 和 docker 的 Github Action - Github Action with selenium and docker 如何使用私有 docker 镜像作为自定义 Github 操作? - How do you use a private docker image as a custom Github action? 在 CircleCI 工作流或作业之后触发 Github 动作 - Trigger Github Action after CircleCI workflow or job 如何使用 GitHub Packages 中的 Docker 镜像? - How to use Docker image from GitHub Packages?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM