Skip to content

Conversation

@IlyaKhD
Copy link
Contributor

@IlyaKhD IlyaKhD commented Mar 21, 2025

Practical Value

Making the action feasible for usage in other use cases.

Fixed the case with empty paths filter

The paths is not required, but if not specified, empty list of files returned.

Before

    - uses: DevExpress/github-actions/get-changed-files@v1
      with:
        gh-token: XXX
        paths: '**/*'
        output: XXX

After

    - uses: DevExpress/github-actions/get-changed-files@v1
      with:
        gh-token: XXX
        output: XXX

Removed output

The files list is no longer saved to disk. Use the new json output instead, see usage examples.

Added outpus

files

A list of all changed files in the PR. Usage example:

    - run: |
        for file in ${{ steps.changed-files.outputs.files }}; do
          echo "$file"
        done

count

The number of all changed files in the PR. Usage example:

    - if: steps.changed-files.outputs.count > 2
      run: |
        echo "${{ steps.changed-files.outputs.count }}"

json

All data in JSON format, e.g. to use with jq
Data Schema:

type JsonSchema = {
  files: {
    path: string;
    status: string;
  } [];
  count: number;
};

Data sample:

{
  "files": [
    {
      "path": "path/to/file-0.txt",
      "status": "modified"
    },
    {
      "path": "file-1.ts",
      "status": "removed"
    },
    {
      "path": "file-2.js",
      "status": "modified"
    },
    {
      "path": "file-3.yaml",
      "status": "added"
    }
  ],
  "count": 4
}

Usage examples:

    # conditional step
    - if: fromJSON(steps.changed-files.outputs.json).count > 2
      run: |
        echo "${{ fromJSON(steps.changed-files.outputs.json).count }}"

    # output to disk
    - run: |
        jq -r <<< '${{ steps.changed-files.outputs.json }}' > changed-files-2.json

    # change data structure
    # [
    #   { "filename": "path/to/file1" },
    #   ...
    # ]
    - run: |
        jq -r '[.files[] | {filename: .path}]' <<< '${{ steps.changed-files.outputs.json }}' 

    # filter files by status  and change data structure:
    # file1
    # file2
    # ...
    -  run: |
        jq -r '.files[] | select(.status != "removed") | .path' <<< '${{ steps.changed-files.outputs.json }}'

@IlyaKhD IlyaKhD force-pushed the khd/update-get-changed-files branch from d535a48 to bc41669 Compare March 21, 2025 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants