为什么我不用设置就可以在github actions中运行cargo?

发布于 2025-01-14 03:01:26 字数 1115 浏览 1 评论 0原文

我有一个 GitHub 工作流程,其工作如下:

docker:
    name: Docker image
    needs: test-n-build
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v1

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1

      - name: Set docker image tag
        if: startsWith(github.ref, 'refs/tags/')
        run: echo "DOCKER_TAG=:$(cargo read-manifest | sed 's/.*"version":"\{0,1\}\([^,"]*\)"\{0,1\}.*/\1/')" >> $GITHUB_ENV

      - name: Login to DockerHub
        uses: docker/login-action@v1

      - name: Build and push
        uses: docker/build-push-action@v2
        with:
          push: ${{ startsWith(github.ref, 'refs/tags/') }}

此工作流程构建 docker 映像,如果标签推送到分支,则将其推送到注册表。如所见,有一个使用货物命令的 Set docker image tag 步骤,但是当我复制粘贴内容时,我忘记添加设置 rust 操作。但是该步骤成功执行,并且没有出现诸如 command Cargo not found 之类的错误。

是因为该作业需要我实际设置 Rust 的 test-n-build 作业,还是 QEMU 安装 Rust?它如何找到 cargo 命令?

I have a GitHub workflow with job like this:

docker:
    name: Docker image
    needs: test-n-build
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v1

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1

      - name: Set docker image tag
        if: startsWith(github.ref, 'refs/tags/')
        run: echo "DOCKER_TAG=:$(cargo read-manifest | sed 's/.*"version":"\{0,1\}\([^,"]*\)"\{0,1\}.*/\1/')" >> $GITHUB_ENV

      - name: Login to DockerHub
        uses: docker/login-action@v1

      - name: Build and push
        uses: docker/build-push-action@v2
        with:
          push: ${{ startsWith(github.ref, 'refs/tags/') }}

This workflow builds docker image and pushes it to registry if tag pushed to branch. As seen there are a Set docker image tag step with cargo command used, but when I'm copy-pasted things I forgot to add setup rust action. But that step successfully executed and no error like command cargo not found not appears.

Is it because that job needs test-n-build job where I actually setup Rust, or QEMU installs Rust? How it finds cargo command?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

原野 2025-01-21 03:01:27

正如您在 Ubuntu-20.04 虚拟上看到的环境,它提供了一些已安装的 Rust 工具:

### Rust Tools
Cargo 1.58.0
Rust 1.58.1
Rustdoc 1.58.1
Rustup 1.24.3

因此,在这种情况下,您不需要任何额外的设置来安装它们。

您可以在此处检查用作运行器的可用虚拟环境及其配置。

As you can see on the Ubuntu-20.04 virtual environment, it is provided with some Rust Tools installed:

### Rust Tools
Cargo 1.58.0
Rust 1.58.1
Rustdoc 1.58.1
Rustup 1.24.3

Therefore, you wouldn't need any extra setup to install them in that case.

You can check the available virtual environment used as runners and their configurations here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文