Skip to content
list

GitHub Action

List Changed Files

v1.0.0 Latest version

List Changed Files

list

List Changed Files

Get a list of changed files and filter them by a list of path patterns similar to .gitignore

Installation

Copy and paste the following snippet into your .yml file.

              

- name: List Changed Files

uses: knu/changed-files@v1.0.0

Learn more about this action in knu/changed-files

Choose a version

Changed Files for GitHub Actions

This GitHub Action returns a list of files changed by a pull request or a push, and a list of files matching a given pattern list.

Usage

on:
  push:

  pull_request:

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - id: changed-files
        name: Check changed files
        uses: knu/changed-files@v1
        with:
          paths: |
            **/*.{json,js,ts,[cm]js}
            !**/*.d.ts
      - name: Show changed files
        run: |
          echo "Changed files:"
          echo "${{ steps.changed-files.outputs.changed_files }}" | sed 's/^/  /'
          echo "Matched files:"
          echo "${{ steps.changed-files.outputs.matched_files }}" | sed 's/^/  /'
      - name: Run if any file matching paths is changed
        if: steps.changed-files.outputs.matched_files != ''
        run: |
          echo "Do something"
      - name: Run if a specific file is changed
        if: contains(fromJson(steps.changed-files.outputs.changed_files_json), 'package.json')
        run: |
          echo "Do something"

Inputs

  • paths (string)

    A list of path patterns to match against changed files in the .gitignore syntax.

    Matching is performed using the ignore library.

  • token (string)

    The GitHub token to use for fetching the list of changed files.

    Default: ${{ github.token }}

Outputs

  • changed_files

    A multi-line string containing the list of changed files.

  • changed_files_json

    A JSON string containing the list of changed files.

  • matched_files

    A multi-line string containing the list of changed files matching paths patterns. Empty ("") if paths is not given.

  • matched_files_json

    A JSON string containing the list of changed files matching paths patterns. Empty ("[]") if paths is not given.

Author

Copyright (c) 2024 Akinori MUSHA.

Licensed under the 2-clause BSD license. See LICENSE.txt for details.

Visit the GitHub Repository for the latest information.