有没有办法在 Github 操作中的 main.workflow 中以不同的密钥传递秘密?

Is there a way to pass secrets under a different key in main.workflow in Github Actions?

我的 Github 操作需要 "GITHUB_TOKEN" 来自秘密,但我希望能够声明我自己的密钥并将其传入。

这只是 .github/main.workflow 中的一个问题。在.github/workflows/my-workflow.yml里面你可以自己声明环境变量:

jobs:
  my-job:
    ...
    env:
      TOKEN_KEY_THEY_WANT: ${{ secrets.HOW_I_NAMED_IT }}

以下是他们期望 main.workflow 的配置方式:

action "My Job" {
  uses = "my_repo/action_folder@branch-name"
  secrets = ["GITHUB_TOKEN"]
}

这就是我希望能够做到的:

action "My Job" {
  uses = "my_repo/action_folder@branch-name"
  env = {GITHUB_TOKEN = "$MY_CUSTOM_TOKEN"}
  secrets = ["MY_CUSTOM_TOKEN"]
}

Github 动作文档似乎没有涵盖这个主题,它的大部分内容都是基于他们的 workflow.yml 格式。我不知道这是否是一个简单的语法错误,但如果有人知道该怎么做,我将不胜感激。

根据https://help.github.com/en/articles/about-github-actions#migrating-github-actions-from-hcl-to-yaml-syntax,

Support for the HCL syntax in GitHub Actions will be deprecated on September 30, 2019.

If you participated in the limited public beta and created workflows with the HCL syntax GitHub Actions, you will need to upgrade to the new limited public beta that uses YAML syntax. When your repository is eligible to upgrade, you'll see an invitation in your repository. You must accept the invitation before you can use the new limited public beta.

Any workflows that you created with the HCL syntax will need to be updated to the new YAML syntax. To automatically convert your workflows and actions, see "Migrating GitHub Actions from HCL syntax to YAML syntax."

因此您需要将 main.workflow 文件转换为 .github/workflows 下的 YAML 语法文件。您可以随意命名,但如果我是您,我可能会将其命名为 main.yml。这将允许您使用除 GITHUB_TOKEN 之外的其他秘密,并且由于您必须在月底之前 无论如何 这样做,所以您不妨开始转换过程.