github动作在列表中运行的名称

发布于 2025-02-01 14:43:34 字数 352 浏览 2 评论 0 原文

我有一个github操作,该操作设置了一个名称并在拉动请求上运行:

name: Code Quality
on:
  workflow_dispatch:
  pull_request:
    branches: [ main, develop ]

当我手动触发运行时(因为 workflow_dispatch 也设置了),运行将在列表中获得标题“代码质量”跑步。

但是,当操作通过拉动请求运行时,列表中的运行名称设置为PR的名称。这可能是一个好的标题,这取决于公关的作者。有没有办法影响列表中动作的标题?

I have a Github action that sets a name and is run on pull requests:

name: Code Quality
on:
  workflow_dispatch:
  pull_request:
    branches: [ main, develop ]

When I trigger the run manually (because workflow_dispatch is also set), the run will get the title “Code Quality” in the list of runs.

But when the action is run on a pull request, the run name in the list is set to the name of the PR. That may or may not be a good title, very much depending on the PR’s author. Is there a way to influence the title of the action in the list?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

巨坚强 2025-02-08 14:43:34

自2022年9月以来,可能有一种方法可以设置运行本身的标题:

(2022年9月)

github操作客户现在可以动态地命名其工作流程。
新的 Run-name 功能将接受表达式并显示在工作流程列表中。

有关如何使用 run-name 的更多信息github-actions#名称“ rel =“ nofollow noreferrer”>访问文档

出于问题,访问github Actions社区

要查看动作的下一步,


您现在有:

工作流程从工作流生成的名称。
GitHub在存储库的“操作”选项卡上的工作流列表中显示工作流程名称。
如果省略 Run-name ,则将运行名称设置为“工作流程”的特定事件信息。
例如,对于通过推送或pull_request事件触发的工作流程,将其设置为提交消息。

此值可以包括表达式,可以引用 github inputs 上下文。

示例

  run-name:部署到$ {{inputs.deploy_target}}} by @$ {{github.actor}}}
 

在文档上进行扩展:

例如

,考虑一个涉及功能开发和错误修复的项目中的工作流程。
该项目使用两种主要类型的分支:

  • 功能分支:带有功能/
  • bugfix分支的前缀:前缀 bugfix/

该工作流是通过针对 main的拉请求触发的。 分支。您希望工作流程的名称可以反映正在集成的工作类型,它来自的特定分支以及启动运行的用户名称:这将有助于快速识别工作流程的性质,当GitHub存储库中的标签。

name: Integration CI

on:
  pull_request:
    branches: [ main ]

# Dynamically set the run name to include the type of branch (feature or bugfix), branch name, and the user
run-name: "${{ contains(github.head_ref, 'feature/') && 'Feature' || contains(github.head_ref, 'bugfix/') && 'Bugfix' || 'Update' }}: ${{ github.head_ref }} by @${{ github.actor }}"

jobs:
  build-and-test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Setup Node.js
      uses: actions/setup-node@v2
      with:
        node-version: '14'
    - name: Install dependencies
      run: npm install
    - name: Run tests
      run: npm test

该工作流程配置为触发针对 main 分支的拉动请求。

run-name 字段使用表达式基于分支类型( feature/ bugfix/),动态构建运行名称,以及发起跑步的演员的github用户名。

  • 如果分支是一个功能分支(以功能/前缀),则运行名称以“功能”开头。
  • 如果分支是一个BugFix分支(以 bugfix/前缀为前缀),则运行名称以“ BugFix”开头。
  • 对于与这些前缀不匹配的分支,默认为“更新”。
  • 运行名称还包括分支名称( github.head_ref )和启动运行的演员的用户名( github.actor )。

该示例包括一个名为 build-and Test 的简化作业,该作业设置了node.js环境,安装依赖项并运行测试。该部分是许多JavaScript项目的标准配置,但可以根据您的项目需求进行定制。

上下文:

run-name github操作中的属性工作流程使您可以动态设置每个工作流程的名称。该功能对于区分GitHub UI中的运行尤其有用,尤其是在各种事件触发或需要特定上下文以了解运行的目的或来源的复杂工作流程中。

它支持表达式,基于触发事件的上下文,输入或GitHub上下文中可用的任何其他相关信息启用动态运行名称。
以反映:

  • 触发的类型( push pull_request workflow_dispatch 等)
  • 您可以使用上下文和表达式来量身定制运行名称 命名或标记
  • Actor,为手动启动运行
  • 自定义输入的
  • 演员触发可用上下文信息的任何组合,以形成一个有意义的名称,

该名称将:

  • 更易于导航和理解“操作”选项卡中每个运行的目的。
  • 帮助维护者快速确定工作类型和工作流程的启动器,从而帮助进行故障排除和优先考虑工作流程评论。
  • 允许团队系统地管理和监视其CI/CD管道,尤其是在具有频繁和多种贡献类型的存储库中。

Since Sept. 2022, there might be a way to set the title of the run itself:

GitHub Actions: Dynamic names for workflow runs (Sep. 2022)

GitHub Actions customers can now dynamically name their workflow runs.
The new run-name feature will accept expressions and be displayed on the list of workflow runs.

For more information on how to use run-name, visit the documentation.

For questions, visit the GitHub Actions community.

To see what's next for Actions, visit our public roadmap.

You now have:

The name for workflow runs generated from the workflow.
GitHub displays the workflow run name in the list of workflow runs on your repository's "Actions" tab.
If you omit run-name, the run name is set to event-specific information for the workflow run.
For example, for a workflow triggered by a push or pull_request event, it is set as the commit message.

This value can include expressions and can reference the github and inputs contexts.

Example

run-name: Deploy to ${{ inputs.deploy_target }} by @${{ github.actor }}

To expand on the documentation:

Example

Consider, as an example, a workflow in a project that involves both feature development and bug fixes.
That project uses two primary types of branches:

  • Feature branches: Prefixed with feature/
  • Bugfix branches: Prefixed with bugfix/

The workflow is triggered by pull requests targeting the main branch. You want the workflow run's name to reflect the type of work being integrated, the specific branch it is coming from, and the name of the user who initiated the run: that would help quickly identify the nature of the workflow run when looking through the Actions tab in the GitHub repository.

name: Integration CI

on:
  pull_request:
    branches: [ main ]

# Dynamically set the run name to include the type of branch (feature or bugfix), branch name, and the user
run-name: "${{ contains(github.head_ref, 'feature/') && 'Feature' || contains(github.head_ref, 'bugfix/') && 'Bugfix' || 'Update' }}: ${{ github.head_ref }} by @${{ github.actor }}"

jobs:
  build-and-test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Setup Node.js
      uses: actions/setup-node@v2
      with:
        node-version: '14'
    - name: Install dependencies
      run: npm install
    - name: Run tests
      run: npm test

That workflow is configured to trigger on pull requests targeting the main branch.

The run-name field uses expressions to dynamically construct the run name based on the branch type (feature/ or bugfix/), the branch name, and the GitHub username of the actor who initiated the run.

  • If the branch is a feature branch (prefixed with feature/), the run name starts with "Feature".
  • If the branch is a bugfix branch (prefixed with bugfix/), the run name starts with "Bugfix".
  • For branches that do not match these prefixes, it defaults to "Update".
  • The run name also includes the branch name (github.head_ref) and the username of the actor who initiated the run (github.actor).

The example includes a simplified job called build-and-test that sets up a Node.js environment, installs dependencies, and runs tests. That part is standard for many JavaScript projects but can be customized based on your project's needs.

Context:

The run-name attribute in GitHub Actions workflows allows you to dynamically set the name of each workflow run. That feature is particularly useful for distinguishing between runs at a glance in the GitHub UI, especially in complex workflows triggered by various events or requiring specific context to understand the run's purpose or origin.

It supports expressions, enabling dynamic run names based on the context of the trigger event, inputs, or any other relevant information available in the GitHub context.
You can use context and expressions to tailor run names to reflect:

  • The type of trigger (push, pull_request, workflow_dispatch, etc.)
  • The branch name or tag
  • The actor initiating the run
  • Custom inputs for manual triggers
  • Any combination of available context information to form a meaningful name

That will:

  • makes it easier to navigate and understand the purpose of each run in the Actions tab.
  • helps maintainers quickly identify the type of work and the initiator of workflow runs, aiding in troubleshooting and prioritizing workflow reviews.
  • allows teams to systematically manage and monitor their CI/CD pipelines, especially in repositories with frequent and varied types of contributions.
宛菡 2025-02-08 14:43:34

似乎没有一种方法可以设置运行本身的标题(参考)。

计划和手动运行将获得工作流的标题,并且由Commit / PR触发的运行将获得提交消息或PR标题。

但是,请注意,提交/PR标题还显示了 工作流的名称,该名称出现在两个地方:

”

It does not seem like there is a way to set the title of the run itself (reference).

Scheduled and manual runs will get the title of the workflow, and runs triggered by commit / PR will get the commit message or PR title.

However, notice that the commit / PR title is displayed in addition to the name of the workflow, which appears in two places:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文