gh 工作流程运行不适用于特定分支

Tan*_*shk 1 github-actions github-cli

我的仓库中有两个分支,即mainkaju1

main分支(默认)上,定义了两个工作流push.ymltest.yml

kaju1分支上,定义了push.ymltest.yml、 和三个工作流程pr.yml

我想使用 github cli 在分支pr.yml上触发 ie kaju1

我尝试使用这段代码:

gh workflow run --repo username/repo-name --ref kaju1 pr.yml
Run Code Online (Sandbox Code Playgroud)

但这返回给我以下错误:

HTTP 404: Not Found (https://api.github.com/repos/username/repo-name/actions/workflows/pr.yml)
Run Code Online (Sandbox Code Playgroud)

Tan*_*shk 9

我做了一些研究,发现工作流程仅适用于两个条件

  1. 它存在于main (默认)分支中。
  2. 它存在于其他一些分支中,但之前已经运行过。

所以我想到的,我将把它保留在其他分支(我想要的)中,然后我将在其on:push上添加触发器,因为每次推送到该分支时都会触发它,然后我将用它if/else来区分on:pushon:workflow_dispach

on:
  push:
    branches:
      - "other-branch"

  workflow_dispatch:
    inputs:
      greeting:
        description: 'Greetings'
        required: true
        default: 'Hello, World'
        type: string

jobs:
  job1:
    runs-on: ubuntu-latest

    if: ${{ github.event_name == 'workflow_dispatch' }}

    steps:
      - uses: actions/checkout@v3
Run Code Online (Sandbox Code Playgroud)

现在每次推送时它至少会在 中注册github/actionss,然后

 gh workflow run --repo username/repo-name --ref other-branch pr.yml
Run Code Online (Sandbox Code Playgroud)