Detecting what triggered "paths" directive

Is it possible to detect what triggered a workflow when specifying paths?

e.g., say we have this directory structure

on:
  push:
    branches:
      - master
    paths:
      - "cluster_1/namespace_1/**"
      - "cluster_1/namespace_2/**"
      - "cluster_2/namespace_1/**"
      - "cluster_3/namespace_1/**"

And a merge was made to master with changes to cluster_2/namespace_1/** … is it possible to get this info from any of the GITHUB env variables, or context?

I know I can grab the merged PR and reach out to the API to get the necessary info, just wondering if there is a simpler way?

@mfridman,

There is no predefined, special variables to get the information you require.

For your case, generally you can do with the steps below:

  1. List all the changed files contained in current push. You can use the “git diff” command or from the “Get a commit” endpoint to list all the changed files.

  2. Use the patterns of the path filters you set for the push event in the workflow file to compare with the path of each changed file in the list.

  3. The files that can match the patterns are the files which triggered the push event.

1 Like