πŸ’ΈSave up to $132K/month in CI costs!πŸ‘‰ Try Free✨
Skip to main content
← Back to workflows

How to Track Changed Files and Directories with GitHub Actions?

tj-actions-changed-files -
GitHub Action
v44.4.0
1,786
Contributors
Contributor - jackton1
Categories

Optimize Your CI/CD Pipeline

Get instant insights into your CI/CD performance and costs. Reduce build times by up to 45% and save on infrastructure costs.

45% Faster Builds
60% Cost Reduction
Usage
name: 'Usage of changed-files GitHub Action'
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
# To compare changes between the current commit and
# the last pushed remote commit set `since_last_remote_commit: true`. e.g
# with:
# since_last_remote_commit: true
- name: List all changed files
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
for file in ${ALL_CHANGED_FILES}; do
echo "$file was changed"
done

changed-files logo

changed-files

:octocat: Github action to retrieve all (added, copied, modified, deleted, renamed, type changed, unmerged, unknown) files and directories.


What is changed-files?​

You can easily keep track of all changed (added, copied, modified, deleted, renamed, type changed, unmerged, unknown) files and directories relative to a target branch, current branch, preceding commit, or last remote commit, multiple branches, or custom commitsβ€”all returning relative paths from the project root, using this GitHub action.

How to Define a Base Commit for Comparison?​

Set the base_sha to specify a commit SHA or branch for comparing changes.

- uses: tj-actions/changed-files@v44
with:
base_sha: 'main'

How to Make Path Differences Relative​

Use the diff_relative boolean to make path differences relative to a specified directory.

- uses: tj-actions/changed-files@v44
with:
diff_relative: true

How to Output Unique Changed Directories?​

Enable the dir_names input to output unique directory names instead of filenames.

- uses: tj-actions/changed-files@v44
with:
dir_names: true

How to Include Only Deleted Directories?​

Set dir_names_deleted_files_include_only_deleted_dirs to true to include only directories that have been deleted.

- uses: tj-actions/changed-files@v44
with:
dir_names_deleted_files_include_only_deleted_dirs: true

How to Exclude the Current Directory from Outputs?​

Activate the dir_names_exclude_current_dir to exclude the current directory represented by . from outputs.

- uses: tj-actions/changed-files@v44
with:
dir_names_exclude_current_dir: true

How to Include Specific File Patterns in Directory Outputs?​

Specify dir_names_include_files to include certain file patterns when dir_names is set to true.

- uses: tj-actions/changed-files@v44
with:
dir_names_include_files: 'src/**/*.py'

How to Include Specific File Patterns in Directory Outputs?​

Specify dir_names_include_files to include certain file patterns when dir_names is set to true.

- uses: tj-actions/changed-files@v44
with:
dir_names_include_files: 'src/**/*.py'

How to Limit Directory Output Depth?​

Limit the depth of directory outputs. Useful for large repositories where changes are nested in deep directory structures.

- uses: tj-actions/changed-files@v44
with:
dir_names_max_depth: '2'

How to Escape JSON Output?​

Control JSON output escaping, useful when outputs are used in subsequent steps that parse JSON.

- uses: tj-actions/changed-files@v44
with:
escape_json: true

How to Exclude Submodule Changes?​

Exclude changes to submodules from the action's output, which can be essential for repositories with many submodules.

- uses: tj-actions/changed-files@v44
with:
exclude_submodules: false

How to Handle Failures on Initial Diff?​

Define the action's behavior when the initial diff calculation fails.

- uses: tj-actions/changed-files@v44
with:
fail_on_initial_diff_error: false

How to Handle Failures on Submodule Diff?​

Set up error handling for submodule diffs specifically.

- uses: tj-actions/changed-files@v44
with:
fail_on_submodule_diff_error: false

How to Fetch Additional Submodule History?​

Fetch more history for submodules to ensure a comprehensive diff.

- uses: tj-actions/changed-files@v44
with:
fetch_additional_submodule_history: false

How to Set the Depth of History Fetched?​

Specify how much branch history to fetch, which can help resolve issues with insufficient history.

- uses: tj-actions/changed-files@v44
with:
fetch_depth: '25'