Maven / GitHub Actions Interview Questions
How do you implement path filtering so a workflow only runs when specific files change?
GitHub Actions supports built-in path filtering on push and pull_request triggers via the paths: and paths-ignore: filters. When set, the workflow only fires if at least one file in the commit diff matches the given glob pattern.
on:
push:
branches: [main]
paths:
- 'backend/**' # any file under backend/
- 'Dockerfile'
- '.github/workflows/backend-ci.yml'
pull_request:
paths-ignore:
- '**.md' # skip when only docs changed
- 'frontend/**'
You can use both paths and paths-ignore but not on the same trigger event simultaneously. Use paths when you want an allow-list and paths-ignore when you want to exclude certain patterns.
Monorepo scenario — for finer-grained per-step filtering (e.g., only run specific jobs when specific subdirectories changed), the community action dorny/paths-filter is widely used:
jobs:
changes:
runs-on: ubuntu-latest
outputs:
backend: ${{ steps.filter.outputs.backend }}
frontend: ${{ steps.filter.outputs.frontend }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
backend:
- 'backend/**'
frontend:
- 'frontend/**'
test-backend:
needs: changes
if: needs.changes.outputs.backend == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: ./gradlew :backend:test
The limitation of the built-in paths: filter is that it applies to the entire workflow; you cannot skip only certain jobs within it. dorny/paths-filter solves this by producing per-path boolean outputs that individual job conditions can check.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
