问题:我需要引号来替换字符串中的 Github 工作流替换吗?

我像这样定义了 Github 工作流操作的输入。为了创建字符串值,我将替换用双引号括起来,以遵循它在 Bash 中的情况:

 uses: dmnemec/copy_file_to_another_repo_action@v1.0.4
    env:
      API_TOKEN_GITHUB: ${{ secrets.GH_API_TOKEN }}
    with:
      source_file: "${{ steps.create-copy-file.outputs.filename }}.yaml"
      destination_repo: "${{ github.repository_owner }}/repo"
      destination_folder: "releases/${{ steps.create-copy-file.outputs.target_folder }}"
      user_email: "user@mail.com"
      user_name: "User Name"

但是,Github](https://docs.github.com/en/actions/learn-github-actions/expressions)中的[示例表明我可以替换该值而无需将其括在引号中。我尝试在不带引号的情况下定义上面的值,它们似乎可以工作,即文件被正确复制到目标存储库和文件夹。

 uses: dmnemec/copy_file_to_another_repo_action@v1.0.4
    env:
      API_TOKEN_GITHUB: ${{ secrets.GH_API_TOKEN }}
    with:
      source_file: ${{ steps.create-copy-file.outputs.filename }}.yaml
      destination_repo: ${{ github.repository_owner }}/repo
      destination_folder: releases/${{ steps.create-copy-file.outputs.target_folder }}
      user_email: user@mail.com
      user_name: "User Name"

我尝试在 Github 中查找示例以了解是否允许或建议这种做法,但找不到任何示例。我发现的一个示例来自此 Azure 开发人员页面(示例编号 6):https://docs.microsoft.com/en-us/azure/developer/github/github-variable-substitution。

另一个示例将字符串用双引号括起来。

我的问题是,是否有必要将 Github 工作流程中的字符串替换用单引号/双引号括起来?这是官方支持的功能还是非预期功能?

解答

不,通常您不需要引号。工作流文件是 YAML,这都是关于 YAML 中的引号的:

YAML:YAML 中的字符串是否需要引号?

Logo

ModelScope旨在打造下一代开源的模型即服务共享平台,为泛AI开发者提供灵活、易用、低成本的一站式模型服务产品,让模型应用更简单!

更多推荐