GitHub Action with Concurrency

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

GitHub Action with Concurrency

问题

“如果github.head_ref未定义”是指在特定事件中未设置或未传递github.head_ref参数。在GitHub Actions中,github.head_ref是仅在pull_request事件中定义的属性。如果你的工作流程不仅响应pull_request事件,而且还涉及其他事件,那么可能会遇到github.head_ref未定义的情况。为了避免语法错误,你可以使用这个例子中提到的回退值来设置并运行并发组。

英文:

My query is for the example given here: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency

Example: Using a fallback value

I understood how concurrency works. But this example for the fallback value is not clear to me.

> If you build the group name with a property that is only defined for specific events, you can use a fallback value. For example, github.head_ref is only defined on pull_request events. If your workflow responds to other events in addition to pull_request events, you will need to provide a fallback to avoid a syntax error. The following concurrency group cancels in-progress jobs or runs on pull_request events only; if github.head_ref is undefined, the concurrency group will fallback to the run ID, which is guaranteed to be both unique and defined for the run.

concurrency:
  group: ${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

Can someone please explain this part "if github.head_ref is undefined"?

答案1

得分: 2

在这个表达式中:

```yaml
github.head_ref || github.run_id

github.head_ref 可能不可用。

根据 github 上下文

> github.head_ref
>
> "工作流运行中拉取请求的 head_ref 或源分支。此属性仅在触发工作流运行的事件为 pull_requestpull_request_target 时可用。"

因此,github.head_ref 仅对于 pull_requestpull_request_target 而定义,在未定义时,后备机制将是 github.run_id


<details>
<summary>英文:</summary>

In this expression:

```yaml
github.head_ref || github.run_id

github.head_ref may not be available.

According to github context:

> github.head_ref
>
> "The head_ref or source branch of the pull request in a workflow run. This property is only available when the event that triggers a workflow run is either pull_request or pull_request_target."

So, github.head_ref is only defined for pull_request or pull_request_target and where it is undefined the fallback mechanism will be the github.run_id.

huangapple
  • 本文由 发表于 2023年2月19日 19:52:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75499942.html
匿名

发表评论

匿名网友

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

确定