How to List Changed Files With tj-actions/changed-files in CI
tj-actions/changed-files returns the concrete filenames that changed (not just booleans), which you can iterate over to build, lint, or test only those files.
Use tj-actions/changed-files when you need the actual filenames rather than per-area flags. It exposes all_changed_files and per-category outputs, and supports files: filters and custom separators.
Steps
- Checkout with enough history so the action can compute a diff.
- Run
tj-actions/changed-fileswith anidand optionalfiles:filter. - Read
steps.<id>.outputs.all_changed_files(space or custom separated). - Loop over the list to run per-file tooling.
Workflow
.github/workflows/ci.yml
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- id: changed
uses: tj-actions/changed-files@v45
with:
files: |
**/*.ts
**/*.tsx
- if: steps.changed.outputs.any_changed == 'true'
run: |
for f in ${{ steps.changed.outputs.all_changed_files }}; do
echo "Linting $f"
npx eslint "$f"
doneGotchas
- The default space separator breaks on filenames with spaces; set
separator: '\n'and quote in the loop for safety. - Without
fetch-depth: 0the action may not find a base to diff against and can report everything as changed.
Related guides
How to Detect Changed Files With dorny/paths-filter in CIDetect which files changed in a GitHub Actions run with dorny/paths-filter, exposing per-filter boolean outpu…
How to Lint Only Changed Files in CILint only the files changed in a pull request in CI by passing the diff file list to ESLint, so linting time…
How to Set fetch-depth and Base Ref for Change DetectionConfigure actions/checkout fetch-depth and resolve the correct base ref for PR versus push so git-diff-based…