Coder Social home page Coder Social logo

ana06 / get-changed-files Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jitterbit/get-changed-files

59.0 2.0 20.0 439 KB

Get all of the files changed/modified in a pull request or push's commits.

License: MIT License

TypeScript 97.39% JavaScript 2.61%

get-changed-files's Introduction

get-changed-files

CI status License

Get all changed/modified files in a pull request (pull_request or pull_request_target) or push's commits. You can choose to get all changed files, only added files, only modified files, only removed files, only renamed files, or all added and modified files. These outputs are available via the steps output context. The steps output context exposes the output names all, added, modified, removed, renamed, and added_modified and added_modified_renamed. Renamed files that are also modified are included in renamed, modified and added_modified.

This project is a fork of jitterbit/get-changed-files, which:

  • Supports pull_request_target
  • Allows to filter files using regular expressions
  • Removes the ahead check
  • Considers renamed modified files as modified
  • Adds added_modified_renamed that includes renamed non-modified files and all files in added_modified
  • Removes node12 deprecation warnings

Usage

See action.yml

- uses: Ana06/[email protected]
  with:
    # Format of the steps output context.
    # Can be 'space-delimited', 'csv', or 'json'.
    # Default: 'space-delimited'
    format: ''
    # Filter files using a glob filter
    filter: '*'

Filtering

You can filter files using regular expressions with the filter option. This option receives a list of patterns using GitHub Actions syntax. You can use ! at the start of a pattern to negate previous positive patterns. See the Get all changed *.yml files but exclude .github/*/*.yml files example.

Examples

Get all changed files as space-delimited

If there are any files with spaces in them, then this method won't work and the step will fail. Consider using one of the other formats if that's the case.

- id: files
  uses: Ana06/[email protected]
- run: |
    for changed_file in ${{ steps.files.outputs.all }}; do
      echo "Do something with this ${changed_file}."
    done

Get all changed *.php files as space-delimited

If there are any files with spaces in them, then this method won't work and the step will fail. Consider using one of the other formats if that's the case.

- id: files
  uses: Ana06/[email protected]
  with:
    filter: '*.php'
- run: |
    for changed_file in ${{ steps.files.outputs.all }}; do
      echo "Do something with this ${changed_file}."
    done

Get all changed *.yml files but exclude .github/*/*.yml files

Be careful that the order of the glob has an importance. Therefore, including all YML files first and excluding the YML files of your .github/*/ directories is the way to go to exclude them. If those two globs were inverted, you would include all the YML files, with the ones in your .github/*/ directories.

- uses: Ana06/[email protected]
  with:
    filter: |
      *.yml
      !.github/*/*.yml

Get all added and modified files as CSV

- id: files
  uses: Ana06/[email protected]
  with:
    format: 'csv'
    filter: '*'
- run: |
    mapfile -d ',' -t added_modified_files < <(printf '%s,' '${{ steps.files.outputs.added_modified }}')
    for added_modified_file in "${added_modified_files[@]}"; do
      echo "Do something with this ${added_modified_file}."
    done

Get all removed files as JSON

- id: files
  uses: Ana06/[email protected]
  with:
    format: 'json'
    filter: '*'
- run: |
    readarray -t removed_files <<<"$(jq -r '.[]' <<<'${{ steps.files.outputs.removed }}')"
    for removed_file in ${removed_files[@]}; do
      echo "Do something with this ${removed_file}."
    done

Install, Build, Lint, Test, and Package

Make sure to do the following before checking in any code changes.

yarn
yarn all

License

The scripts and documentation in this project are released under the MIT License

get-changed-files's People

Contributors

alaeddine-13 avatar ana06 avatar brtrick avatar dependabot[bot] avatar rmed19 avatar rnsc avatar sargunv avatar sean-krail avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

get-changed-files's Issues

Filter does not appear to use GitHub action syntax

I'm sorry that I can't give a detailed description, but it appears as though the filter "*.rs" matches the file errors.py (with emphasis: erro rs .py), which shouldn't happen with the GitHub action syntax. Am I missing something here? The only solution to achieve what I wanted was to use "*.rs$" instead.

Make it available on merge_group events

Hello,

Thanks for this great project.
Do you think we could make it available for the GitHub merge queue mechanism?

image

Would it be possible to retrieve base & head from merge_group here?

[Feature] Filter : include/exclude

Hello @Ana06 ,

I've looked at the code already and I see that the filtering implementation is leveraging regex to filter files.
I have a particular case that would require include a certain type of files but also exclude specific paths at the same time.
ie:

  • blah/test/something.yml
  • blah/not_at_test/something_else.yml
  • blah/another_folder/something.yml
  • blah/another_folder/something_not_a_yaml.j2

So I need to match all *.yml, but not *.yml that are in a test folder for example.
Now, while I undertsand I could make a convoluted regex to do that, I would also want to keep it simple.

Would you welcome a change where we change the filter by include and exclude both supporting regex, and add a bit more code logic?

I'd be willing to have a poke at it.

Thanks,

A suggestion on unsupported events

Hello !

First thanks for adapting this from the original code much appreciated !

I've run into cases where I use this action in a workflow that can run on events other than push and pull_request and it makes the whole workflow fail.

I have an other action which just indicates it does not support the event in the log and skips the execution of the code.

Do you think it's something that could be added to the code ?

Cheers

File contains a space

I'm moving a repo from a custom cookiecutter hook to the native support for jinja in filenames. Hopefully eventually to move from cookiecutter to copier. And ninja in filenames == required spaces. Things like if ... must have a space in it. The end result doesn't have spaces, but the files do. How hard would it be to add support for spaces (and pretty much all other windows-supported characters)?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.