【问题标题】:Github Actions: Is there a way to run actions on Pull Requests opened from specific branches?Github Actions:有没有办法对从特定分支打开的拉取请求运行操作?
【发布时间】:2020-03-30 19:40:27
【问题描述】:

我正在尝试创建一个操作,其工作流在针对 master 打开来自特定分支的拉取请求时运行。我目前对所有分支的 master 打开的所有 Pull 请求运行工作流。

name: Auto Approve Pull Request
on:
  pull_request:
    branches:
      - 'master'
      - 'skip-*'

jobs:
  build:
    name: Approve PR
    runs-on: ubuntu-latest
    steps:
      - name: Fetch out code
        uses: username/my-github-repo@master
        with:
          token: ******
        env:
          BRANCH_PREFIX: "skip-*"
          PULL_REQUEST_BRANCH: "master"

我想让工作流只在名为 skip-* 的分支上运行。

【问题讨论】:

    标签: pull-request github-actions


    【解决方案1】:

    我找到的解决方案是使用 if 语句来检查 head-ref 分支名称是否匹配(以 skip- 开头。

    这是我的解决方案:

    name: Auto Approve Pull Request
    on:
      pull_request:
        branches:
          - 'master'
    
    jobs:
      build:
        name: Approve PR
        runs-on: ubuntu-latest
        if: startsWith(github.head_ref, 'skip-') == true
        steps:
          - name: Fetch out code
            uses: username/my-github-repo@master
            with:
              token: ******
            env:
              BRANCH_PREFIX: "skip-*"
              PULL_REQUEST_BRANCH: "master"
    

    注意事项:

    【讨论】:

    • 请注意,工作流运行仍将显示在 repo 的操作页面中(带有灰色的“已跳过”图标)。可能有点烦人
    猜你喜欢
    • 1970-01-01
    • 2020-06-25
    • 2022-11-03
    • 2020-12-28
    • 2020-10-01
    • 2020-01-30
    • 2021-07-22
    • 2020-10-22
    • 2021-09-29
    相关资源
    最近更新 更多