Skip to content
Latchkey

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-files with an id and optional files: 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"
      done

Gotchas

  • The default space separator breaks on filenames with spaces; set separator: '\n' and quote in the loop for safety.
  • Without fetch-depth: 0 the action may not find a base to diff against and can report everything as changed.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →