首页 > 解决方案 > Github 工作流不会在推送基于路径的过滤时触发

问题描述

我有一个工作流程,每当有推送到开发分支时,我都需要运行该工作流程。我正在使用基于路径的过滤。这是工作流程的片段

name: Push to XYZ

on:
  push:
    branches: [ Develop ]
    paths:
    - '!.github/**'

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Extract commit
        run: |
          echo "Sending commit $GITHUB_SHA for $GITHUB_REPOSITORY"
          curl -XPOST ......

所以这个想法是,在推送到开发(直接或通过拉取请求)时,如果所做的更改位于文件夹或文件.github夹以外的文件中,则工作流应该运行。此工作流程已被推送到 Develop at .github/workflows/file.yaml。我从开发中取出一个分支,对不在其中的文件进行更改,.github然后提出 PR 并将其合并。但是工作流程没有运行

我错过了什么吗?

没有语法或缩进问题,因为我能够手动触发工作流程并且工作正常

标签: githubgithub-actions

解决方案


您需要的是首先添加过滤器以允许某些文件夹,这里就是

name: Push to XYZ

on:
  push:
    branches: [ main ]
    paths:
    - '**'
    - '!.github/**'

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Extract commit
        run: |
          echo "Sending commit $GITHUB_SHA for $GITHUB_REPOSITORY"

推荐阅读