Github actions: Run step / job in a workflow if changes happen in specific folder
You could use the paths-filter custom action with if
conditions at the jobs or step levels, using a setup
job as preliminary to check if your specific path has been updated, saving the result as an output.
Here is an example
name: Paths Filter Example
on: [push, workflow_dispatch]
jobs:
paths-filter:
runs-on: ubuntu-latest
outputs:
output1: ${{ steps.filter.outputs.workflows }}
steps:
- uses: actions/checkout@v2
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
workflows:
- '.github/workflows/**'
# run only if 'workflows' files were changed
- name: workflow tests
if: steps.filter.outputs.workflows == 'true'
run: echo "Workflow file"
# run only if not 'workflows' files were changed
- name: not workflow tests
if: steps.filter.outputs.workflows != 'true'
run: echo "NOT workflow file"
next-job:
runs-on: ubuntu-latest
# Wait from the paths-filter to be completed before starting next-job
needs: paths-filter
if: ${{ needs.paths-filter.outputs.output1 }} == 'true'
steps:
...
That way, you could have something like this in your jobs: A
--> B
or A
--> C
depending on the path that has been updated.