Skip to content

About

Check whether any files matching the specified glob pattern(s) were changed in a pull request or push (or between two arbitrary commits)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Detect changes

Check whether files matching the specified glob patterns were changed in a pull request or push (or between two arbitrary commits).

This action uses GitHub API and not git CLI, so it won't work for local commits that weren't pushed to GitHub.

Intended use: skip jobs or steps if relevant files were not changed.

Inputs

repository

The owner and repository name, in owner/name format.

Default: ${{ github.repository }} - the repository where the workflow was triggered.

files

File path/name glob patterns to check, one pattern per line. No default value. Required input.

Patterns starting with ! exclude files. Last matched pattern determines whether to include or exclude the file.

Only files are matched. To include directories, use dir/** syntax.

Only Unix path separator / is used, even on Windows.

See minimatch documentation for syntax details.

base

Base commit/branch to compare.

Default: Pull request/merge group base branch/commit. Or the previous branch head for push event.

head

Head commit/branch to compare.

Default: ${{ github.sha }} - the "current commit" or merge commit for pull requests.

Warning

The default value won't work correctly for pull_request_target event. To check changed files of a pull request in pull_request_target event, you have to get merge commit SHA from GitHub API first, because it's not provided in github.event.pull_request.merge_commit_sha anymore:

- id: get-merge-sha
  if: ${{ github.event.pull_request }}
  run: |
    sha="$(curl -s "$URL" | jq -r .merge_commit_sha)"
    echo "sha=$sha" | tee "$GITHUB_OUTPUT"
  env:
    URL: ${{ github.event.pull_request.url }}

- uses: amezin/detect-changes-action@v2
  with:
    head: ${{ steps.get-merge-sha.outputs.sha || github.sha }}

ignore-removed

Ignore removed files - return false if all changes are just removals.

Default: false

github-token

GitHub API token to use.

Default: ${{ github.token }}

Outputs

changed

true if a change in files was detected, false otherwise.

There is no output with a file list, because GitHub API can return an incomplete list of changed files (it returns up to 300 files) - see https://github.com/proxy/docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#compare-two-commits.

When an incomplete list is detected, changed is always set to true, even if the list doesn't contain any file matching files input.

About

Check whether any files matching the specified glob pattern(s) were changed in a pull request or push (or between two arbitrary commits)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages