英文:
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_request
或 pull_request_target
时可用。"
因此,github.head_ref
仅对于 pull_request
或 pull_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
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论