Github Actions: 在 “uses” 上下文中是否可以引用存储库变量或环境变量?

huangapple go评论57阅读模式
英文:

Github Actions: Is it possible to reference a repository variable or environment variable within "uses" context?

问题

我的目标是在环境变量或我可以在GitHub Web界面中设置的存储库 secrets 中设置所使用的 GitHub Actions 的版本。

例如:

example-job:
  runs-on: ubuntu-latest
  steps:
    - name: example-step
      uses: example-repo/example-composite-action@${{ secrets.ACTION_VERSION }}

如果我尝试这样做,我得到一个 Unrecognized named-value: 'secrets'. 我尝试了相同的方法,使用 env 得到了类似的结果。

有没有办法更动态地设置组合操作的版本,而不必每次都进行 PR?

英文:

My goal is to set the version of used github actions within either environment variables or repository secrets I can set within the github web interface.

For example:

example-job:
  runs-on: ubuntu-latest
  steps:
    - name: example-step
      uses: example-repo/example-composite-action@${{ vars.ACTION_VERSION }}

If I try this I'm getting a Unrecognized named-value: 'vars'. I tried the same with env with a similar result.

Is it somehow possible to set the version of composite action more dynamically without doing a PR everytime?

答案1

得分: 2

在复合操作的URL中无法使用变量。这样做是为了避免在使用流水线中的操作时引发任何破坏性变更。

作为替代方案,您可以使用actions/checkout@v3来检出您的复合操作存储库,并在流水线中引用本地存储库,例如:

- uses: actions/checkout@v3
- name: Checkout actions repo
  uses: actions/checkout@v3
  with:
    repository: my-org/my-actions
    path: my-actions
    ref: @${{ vars.ACTION_VERSION }}

- uses: ./my-actions/.github/actions/example-composite-action
英文:

It is not possible to use variables in composite action URLs. And that's to avoid any breaking changes from actions in consuming pipelines.

As an alternative you can use the actions/checkout@v3 to checkout your composite action repository and reference it locally in your pipeline, for example:

- uses: actions/checkout@v3
- name: Checkout actions repo
  uses: actions/checkout@v3
  with:
    repository: my-org/my-actions
    path: my-actions
    ref: @${{ vars.ACTION_VERSION }}

- uses: ./my-actions/.github/actions/example-composite-action

huangapple
  • 本文由 发表于 2023年3月15日 20:39:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75744834.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定