Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] include/exclude filters (#1) #2

Merged
merged 14 commits into from
Jul 27, 2021
27 changes: 26 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,37 @@ jobs:
- id: files
name: Run the action
uses: ./
with:
glob-filter: '*'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had skipped that one 🙈 I have fix it on main 😉

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no! Sorry!


- name: Print steps context output
- name: Print files
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] I think the name was accurate, but it is not very important. Does someone else has an opinion about this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to have a different name since I had duplicated the step with the exclude filter.

run: |
echo 'steps.files.outputs.all=${{ steps.files.outputs.all }}'
echo 'steps.files.outputs.added=${{ steps.files.outputs.added }}'
echo 'steps.files.outputs.modified=${{ steps.files.outputs.modified }}'
echo 'steps.files.outputs.removed=${{ steps.files.outputs.removed }}'
echo 'steps.files.outputs.renamed=${{ steps.files.outputs.renamed }}'
echo 'steps.files.outputs.added_modified=${{ steps.files.outputs.added_modified }}'

- id: files-filtered
name: Run the action
uses: ./
with:
glob-filter: |
*.yml
!.github/*/*.yml
*.js
*.ts
package*
!*.json


- name: Print files-filtered
run: |
echo 'steps.files-filtered.outputs.all=${{ steps.files-filtered.outputs.all }}'
echo 'steps.files-filtered.outputs.added=${{ steps.files-filtered.outputs.added }}'
echo 'steps.files-filtered.outputs.modified=${{ steps.files-filtered.outputs.modified }}'
echo 'steps.files-filtered.outputs.removed=${{ steps.files-filtered.outputs.removed }}'
echo 'steps.files-filtered.outputs.renamed=${{ steps.files-filtered.outputs.renamed }}'
echo 'steps.files-filtered.outputs.added_modified=${{ steps.files-filtered.outputs.added_modified }}'

70 changes: 50 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,89 +1,119 @@
# get-changed-files
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a bit of linting on the README too, I hope that's ok

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's awesome, thanks!


[![CI status](https://github.com/Ana06/get-changed-files/workflows/Test/badge.svg)](https://github.com/Ana06/get-changed-files/actions?query=event%3Apush+branch%3Amain)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE.txt)

This project is a fork of https://github.com/jitterbit/get-changed-files, which supports `pull_request_target`, allow to filter files using regular expressions and removes the ahead check.
This project is a fork of <https://github.com/jitterbit/get-changed-files>, which supports `pull_request_target`, allow to filter files using regular expressions and removes the ahead check.

# Get All Changed Files
## Get All Changed Files

Get all of the files changed/modified 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`.

# Usage
## Usage

See [action.yml](action.yml)

```yaml
- uses: Ana06/get-changed-files@v1.2
- uses: Ana06/get-changed-files@v2.0.0
with:
# Format of the steps output context.
# Can be 'space-delimited', 'csv', or 'json'.
# Default: 'space-delimited'
format: ''
# Filter files using a regex
filter: '*'
glob-filter: '*'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, the verison of the action should be changed too right?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should. yarn version --no-git-tag-version --major

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, @micalevisk, @Ana06, should we also change the repository URLs in the package.json? Or are we planning on trying to merge in the original repo in the future?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did the yarn command thingie, I'll let you all check :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we call it grob-filter or just filter? I like filter, as we don't have any other filer I think the name doesn't need to be more specific as long as we document it properly. But I don't have a strong opinion... 🤔 🤔 Any other opinion?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rnsc

should we also change the repository URLs in the package.json? Or are we planning on trying to merge in the original repo in the future?

I think we can change the urls. I was hopping upstream integrates these changes when I originally forked it, but it doesn't look like it will happen.

```

# Scenarios
## Scenarios

- [Get all changed files as space-delimited](#get-all-changed-files-as-space-delimited)
- [Get all added and modified files as CSV](#get-all-added-and-modified-files-as-csv)
- [Get all removed files as JSON](#get-all-removed-files-as-json)
- [get-changed-files](#get-changed-files)
- [Get All Changed Files](#get-all-changed-files)
- [Usage](#usage)
- [Scenarios](#scenarios)
- [Get all changed files as space-delimited](#get-all-changed-files-as-space-delimited)
- [Get all changed *.yml files but exclude .github/*/*.yml files](#get-all-changed-yml-files-but-exclude-githubyml-files)
- [Get all added and modified files as CSV](#get-all-added-and-modified-files-as-csv)
- [Get all removed files as JSON](#get-all-removed-files-as-json)
- [Install, Build, Lint, Test, and Package](#install-build-lint-test-and-package)
- [License](#license)

## Get all changed files as space-delimited
### Get all changed files as space-delimited
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this was already like this before, but I think it would be clearer to have this Get all changed files as space-delimited without the filter option and make another section to only get *.php and give there some more details about how the filter option works (that a list of regular expression is expected, GitHub like syntax is used, etc.). Ideally users should be able to understand how it works only with the README without checking the code. I am not completely sure this is the case now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added one example


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.

```yaml
- id: files
uses: Ana06/get-changed-files@v1.2
uses: Ana06/get-changed-files@v2.0.0
with:
filter: '*.php'
glob-filter: '*.php'
- run: |
for changed_file in ${{ steps.files.outputs.all }}; do
echo "Do something with this ${changed_file}."
done
```

## Get all added and modified files as CSV
### Get all changed *.yml files but exclude .github/*/*.yml files
rnsc marked this conversation as resolved.
Show resolved Hide resolved

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.

```yaml
- uses: Ana06/get-changed-files@v2.0.0
with:
# Format of the steps output context.
# Can be 'space-delimited', 'csv', or 'json'.
# Default: 'space-delimited'
format: ''
# Filter files using a regex
glob-filter: |
*.yml
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agraul not sure if you've seen this, but as GitHub actions core doesn't support a standard YAML as input, we have to declare the list a multi line string.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the ping, I missed that. It's a bit unfortunate, I didn't know that lists can't be passed, but as long as the structure is kept I think this is still nice!

!.github/*/*.yml
```

### Get all added and modified files as CSV

```yaml
- id: files
uses: Ana06/get-changed-files@v1.2
uses: Ana06/get-changed-files@v2.0.0
with:
format: 'csv'
glob-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
### Get all removed files as JSON

```yaml
- id: files
uses: Ana06/get-changed-files@v1.2
uses: Ana06/get-changed-files@v2.0.0
with:
format: 'json'
glob-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
## Install, Build, Lint, Test, and Package

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

```bash
$ yarn
$ yarn all
yarn
yarn all
```

# License
## License

The scripts and documentation in this project are released under the [MIT License](LICENSE)
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ inputs:
Can be 'space-delimited', 'csv', or 'json'.
required: true
default: space-delimited
filter:
glob-filter:
required: true
default: '*'
outputs:
Expand Down
Loading