为什么我不用设置就可以在github actions中运行cargo?
我有一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您在 Ubuntu-20.04 虚拟上看到的环境,它提供了一些已安装的 Rust 工具:
因此,在这种情况下,您不需要任何额外的设置来安装它们。
您可以在此处检查用作运行器的可用虚拟环境及其配置。
As you can see on the Ubuntu-20.04 virtual environment, it is provided with some Rust Tools installed:
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.