简体   繁体   English

有没有办法在 Github Actions 的 main.workflow 中的不同密钥下传递秘密?

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

My Github Action requires "GITHUB_TOKEN" from secrets but I want to be able to declare my own key and pass it in.我的 Github Action 需要来自机密的“GITHUB_TOKEN”,但我希望能够声明我自己的密钥并将其传入。

This is only an issue in .github/main.workflow .这只是.github/main.workflow一个问题。 Inside .github/workflows/my-workflow.yml you can declare environment variables yourself:.github/workflows/my-workflow.yml您可以自己声明环境变量:

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

and below is how they expect main.workflow to be configured:以下是他们期望main.workflow配置方式:

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

and this is how I want to be able to do:这就是我希望能够做到的:

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

The Github Actions docu doesn't seem to cover this topic and most of its content is based around their workflow.yml format. Github Actions 文档似乎没有涵盖这个主题,它的大部分内容都基于它们的工作流.yml 格式。 I don't know if this is a simple syntax error but if anybody has any idea on what to do, I'd very much appreciate it.我不知道这是否是一个简单的语法错误,但如果有人知道该怎么做,我将非常感激。

According to https://help.github.com/en/articles/about-github-actions#migrating-github-actions-from-hcl-to-yaml-syntax ,根据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. GitHub Actions 中对 HCL 语法的支持将于 2019 年 9 月 30 日弃用。

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.如果您参与了有限公开测试版并使用 HCL 语法 GitHub Actions 创建了工作流,则需要升级到使用 YAML 语法的新有限公开测试版。 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.您使用 HCL 语法创建的任何工作流都需要更新为新的 YAML 语法。 To automatically convert your workflows and actions, see " Migrating GitHub Actions from HCL syntax to YAML syntax ."要自动转换您的工作流程和操作,请参阅“将GitHub 操作从 HCL 语法迁移到 YAML 语法”

So you'll need to convert your main.workflow file to a YAML syntax file under .github/workflows .因此,您需要将main.workflow文件转换为.github/workflows下的 YAML 语法文件。 You can name it anything you like, but I'd probably call it main.yml if I were you.您可以随意命名它,但如果我是您,我可能会称其为main.yml This will allow you to use other secrets besides GITHUB_TOKEN , and since you have to do it anyway before the end of the month, you might as well get started on the conversion process.这将允许您使用其他秘密之外GITHUB_TOKEN ,既然你有这个月的月底前做,你还不如坐上转换过程开始。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM