Skip to content

Commit

Permalink
feat: add support for complex filters (#1265)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: tj-actions[bot] <109116665+tj-actions-bot@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 16, 2023
1 parent ea90b5c commit c25c77a
Show file tree
Hide file tree
Showing 15 changed files with 29,842 additions and 3,511 deletions.
70 changes: 60 additions & 10 deletions .github/workflows/test.yml
Expand Up @@ -36,7 +36,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout to branch
- name: Checkout branch
uses: actions/checkout@v3
- name: shellcheck
uses: reviewdog/action-shellcheck@v1.17
Expand Down Expand Up @@ -188,7 +188,7 @@ jobs:
if: github.event_name == 'push'

steps:
- name: Checkout to branch
- name: Checkout branch
uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
Expand Down Expand Up @@ -245,7 +245,7 @@ jobs:
needs: build

steps:
- name: Checkout to branch
- name: Checkout branch
uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
Expand Down Expand Up @@ -282,7 +282,7 @@ jobs:
needs: build

steps:
- name: Checkout to branch
- name: Checkout branch
uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
Expand Down Expand Up @@ -318,7 +318,7 @@ jobs:
input-fetch_depth: [1, 50]

steps:
- name: Checkout to branch
- name: Checkout branch
uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
Expand Down Expand Up @@ -348,7 +348,7 @@ jobs:
if: github.event_name != 'push'

steps:
- name: Checkout to branch
- name: Checkout branch
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
Expand Down Expand Up @@ -380,7 +380,7 @@ jobs:
fetch-depth: [1, 2, 0]

steps:
- name: Checkout to branch
- name: Checkout branch
uses: actions/checkout@v3
with:
fetch-depth: ${{ matrix.fetch-depth }}
Expand Down Expand Up @@ -408,7 +408,7 @@ jobs:
needs: build

steps:
- name: Checkout to branch
- name: Checkout branch
uses: actions/checkout@v3

- name: Download build assets
Expand Down Expand Up @@ -461,7 +461,7 @@ jobs:
needs: build

steps:
- name: Checkout to branch
- name: Checkout branch
uses: actions/checkout@v3

- name: Download build assets
Expand Down Expand Up @@ -519,7 +519,7 @@ jobs:
fetch-depth: [0, 1, 2]

steps:
- name: Checkout to branch
- name: Checkout branch
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
Expand Down Expand Up @@ -550,6 +550,56 @@ jobs:
echo "${{ toJSON(steps.changed-files.outputs) }}"
shell:
bash
test-yaml:
name: Test changed-files with yaml
runs-on: ubuntu-latest
needs: build
strategy:
fail-fast: false
max-parallel: 4
matrix:
fetch-depth: [0, 1, 2]

steps:
- name: Checkout branch
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
submodules: recursive
fetch-depth: ${{ matrix.fetch-depth }}

- name: Download build assets
uses: actions/download-artifact@v3
with:
name: build-assets

- name: Run changed-files with files_yaml
id: changed-files
uses: ./
with:
files_yaml: |
test:
- test/**.txt
- test/**.md
- name: Show output
run: |
echo "${{ toJSON(steps.changed-files.outputs) }}"
shell:
bash

- name: Run changed-files with files_yaml_from_source_file
id: changed-files-from-source-file
uses: ./
with:
files_yaml_from_source_file: |
test/changed-files.yml
- name: Show output
run: |
echo "${{ toJSON(steps.changed-files-from-source-file.outputs) }}"
shell:
bash

test:
name: Test changed-files
Expand Down
33 changes: 33 additions & 0 deletions README.md
Expand Up @@ -62,6 +62,10 @@ Retrieve all changed files and directories relative to a target branch, precedin
* Using [Glob pattern](https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet) matching.
* Globstar.
* Brace expansion.
* Negation.
* Using [YAML](https://yaml.org/) syntax for specifying the patterns for files and directories.
* Supports [YAML anchors & aliases](https://www.educative.io/blog/advanced-yaml-syntax-cheatsheet#anchors).
* Supports [YAML multi-line strings](https://learnxinyminutes.com/docs/yaml/).

## Usage

Expand Down Expand Up @@ -141,6 +145,35 @@ jobs:
run: |
echo "One or more .js file(s) or any file in the static folder but not in the doc folder has changed."
echo "List all the files that have changed: ${{ steps.changed-files-excluded.outputs.all_changed_files }}"
# Example 4
- name: Get all test files, doc and src files that have changed
id: changed-files-yml
uses: tj-actions/changed-files@v36
with:
files_yaml: |
doc:
- *.md
- docs/**
- !docs/README.md
test:
- test/**
- !test/README.md
src:
- src/**
# Optionally set `files_yaml_from_source_file` to read the YAML from a file. e.g `files_yaml_from_source_file: .github/changed-files.yml`

- name: Run step if test file(s) change
if: steps.changed-files-yml.outputs.test_any_changed == 'true'
run: |
echo "One or more test file(s) has changed."
echo "List all the files that have changed: ${{ steps.changed-files-yml.outputs.test_all_changed_files }}"
- name: Run step if doc file(s) change
if: steps.changed-files-yml.outputs.doc_any_changed == 'true'
run: |
echo "One or more doc file(s) has changed."
echo "List all the files that have changed: ${{ steps.changed-files-yml.outputs.doc_all_changed_files }}"
```

To access more examples, navigate to the [Examples](#examples) section.
Expand Down
32 changes: 28 additions & 4 deletions action.yml
Expand Up @@ -28,13 +28,37 @@ inputs:
default: "\n"
required: false
files:
description: "File and directory patterns to detect changes using only these list of file(s) (Defaults to the entire repo) **NOTE:** Multiline file/directory patterns should not include quotes."
description: "File and directory patterns used to detect changes (Defaults to the entire repo if unset) **NOTE:** Multiline file/directory patterns should not include quotes."
required: false
default: ""
files_separator:
description: "Separator used to split the `files` input"
default: "\n"
required: false
files_yaml:
description: "YAML used to define a set of file patterns to detect changes"
required: false
default: ""
files_yaml_from_source_file:
description: "Source file(s) used to populate the `files_yaml` input. [Example](https://github.com/tj-actions/changed-files/blob/main/test/changed-files.yml)"
required: false
default: ""
files_yaml_from_source_file_separator:
description: 'Separator used to split the `files_yaml_from_source_file` input'
default: "\n"
required: false
files_ignore_yaml:
description: "YAML used to define a set of file patterns to ignore changes"
required: false
default: ""
files_ignore_yaml_from_source_file:
description: "Source file(s) used to populate the `files_ignore_yaml` input. [Example](https://github.com/tj-actions/changed-files/blob/main/test/changed-files.yml)"
required: false
default: ""
files_ignore_yaml_from_source_file_separator:
description: 'Separator used to split the `files_ignore_yaml_from_source_file` input'
default: "\n"
required: false
files_ignore:
description: "Ignore changes to these file(s) **NOTE:** Multiline file/directory patterns should not include quotes."
required: false
Expand Down Expand Up @@ -70,7 +94,7 @@ inputs:
required: false
default: "."
quotepath:
description: "Use non ascii characters to match files and output the filenames completely verbatim by setting this to `false`"
description: "Use non-ascii characters to match files and output the filenames completely verbatim by setting this to `false`"
default: "true"
required: false
diff_relative:
Expand Down Expand Up @@ -106,7 +130,7 @@ inputs:
required: false
default: "50"
since_last_remote_commit:
description: "Use the last commit on the remote branch as the `base_sha`. Defaults to the last non merge commit on the target branch for pull request events and the previous remote commit of the current branch for push events."
description: "Use the last commit on the remote branch as the `base_sha`. Defaults to the last non-merge commit on the target branch for pull request events and the previous remote commit of the current branch for push events."
required: false
default: "false"
write_output_files:
Expand Down Expand Up @@ -134,7 +158,7 @@ outputs:
renamed_files:
description: "Returns only files that are Renamed (R)."
all_old_new_renamed_files:
description: "Returns only files that are Renamed and list their old and new names. **NOTE:** This requires setting `include_all_old_new_renamed_files` to `true` (R)"
description: "Returns only files that are Renamed and lists their old and new names. **NOTE:** This requires setting `include_all_old_new_renamed_files` to `true`. Also, keep in mind that this output is global and wouldn't be nested in outputs generated when the `*_yaml_*` input is used. (R)"
type_changed_files:
description: "Returns only files that have their file type changed (T)."
unmerged_files:
Expand Down

0 comments on commit c25c77a

Please sign in to comment.