如何触发特定的存储库调度?

问题描述 投票:0回答:1

我在 1 个存储库下有 2 个工作流程。当我发送发布请求时,它会触发两个工作流程并运行两个工作流程。我想指定我的有效负载来触发特定的工作流程。

目前有 2 个 GitHub Actions 工作流程:

on:
  repository_dispatch:
  
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Check User
        if: github.event_name == 'repository_dispatch' && github.event.client_payload.workflow_file == 'test1.yml'
on:
  repository_dispatch:
  
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Check User
        if: github.event_name == 'repository_dispatch' && github.event.client_payload.workflow_file == 'test2.yml'

这是我的 2 个请求:

{
  "event_type": "{{issue.key}}",
  "client_payload": {
    "workflow_file": "test1.yml"
  }
}
{
  "event_type": "{{issue.key}}",
  "client_payload": {
    "workflow_file": "test2.yml"
  }
}

但是,运行任一发布请求都会触发工作流运行。

github github-actions
1个回答
0
投票

您可以使用 workflow_dispatch 概念。这将允许您通过事件/cli 或 api 触发特定的工作流程。

如果您仍然需要使用 repository_dispatch 触发器,您可以在步骤

event_type
条件的过滤器中使用
if
,在您的情况下看起来像这样:

if: github.event.action != '{{issue.key}}'

但是,您需要为每个请求使用不同的

event_type

注意:我有一个示例here,我从

here
发送了带有event_type = Formula Workflow Response的请求。

© www.soinside.com 2019 - 2024. All rights reserved.