-
Notifications
You must be signed in to change notification settings - Fork 20
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
Changes from all commits
55e9d3c
956182e
0b98d12
d371995
de1f38c
eb061c4
6efbdb0
0c6352b
e3da65b
c1e82c4
de73d10
3269ec7
873b7ea
58c3e15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,12 +85,37 @@ jobs: | |
- id: files | ||
name: Run the action | ||
uses: ./ | ||
with: | ||
glob-filter: '*' | ||
|
||
- name: Print steps context output | ||
- name: Print files | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 }}' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,68 @@ | ||
# get-changed-files | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 files using a glob filter | ||
filter: '*' | ||
``` | ||
|
||
# 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 *.php files as space-delimited](#get-all-changed-php-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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
- 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. | ||
|
||
```yaml | ||
- id: files | ||
uses: Ana06/get-changed-files@v2.0.0 | ||
with: | ||
filter: '*.php' | ||
- run: | | ||
|
@@ -47,43 +71,59 @@ Consider using one of the other formats if that's the case. | |
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: | ||
filter: | | ||
*.yml | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' | ||
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' | ||
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) |
There was a problem hiding this comment.
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 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh no! Sorry!