3
0
Fork 0
mirror of https://github.com/tj-actions/changed-files synced 2025-02-06 09:41:22 +00:00

Merge pull request #700 from tj-actions/chore/update-readme

This commit is contained in:
Tonye Jack 2022-10-18 18:01:12 -06:00 committed by GitHub
commit cdbd6e5e85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

473
README.md
View file

@ -162,142 +162,281 @@ Support this project with a :star:
| json | `boolean` | `false` | `false` | Output changed files in JSON format which can be used for [matrix jobs](https://github.com/tj-actions/changed-files/blob/main/.github/workflows/manual-matrix-test.yml). | | json | `boolean` | `false` | `false` | Output changed files in JSON format which can be used for [matrix jobs](https://github.com/tj-actions/changed-files/blob/main/.github/workflows/manual-matrix-test.yml). |
| since | `string` | `false` | | Get changed files for commits whose timestamp is older than the given time. | | since | `string` | `false` | | Get changed files for commits whose timestamp is older than the given time. |
| until | `string` | `false` | | Get changed files for commits whose timestamp is earlier than the given time. | | until | `string` | `false` | | Get changed files for commits whose timestamp is earlier than the given time. |
| target\_branch\_fetch\_depth | `string` | `false` | `20` | Limit fetching commits from the target branch to a specified number. **NOTE**: This can be adjusted to resolve errors with insufficient history. See: [#668](https://github.com/tj-actions/changed-files/issues/668). | | target\_branch\_fetch\_depth | `string` | `false` | `20` | Limit fetching commits from the target branch to a specified number. **NOTE**: This can be adjusted to resolve errors with insufficient history. See: [#668](https://github.com/tj-actions/changed-files/issues/668). |
## Examples ## Examples
<details>
<summary>Get all changed files in the current branch</summary>
```yaml ```yaml
... ...
steps: - name: Get changed files
- uses: actions/checkout@v3 id: changed-files
with: uses: tj-actions/changed-files@v32
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit. ...
# submodules: true # OR "recursive" -> To include all changed submodule files. ```
</details>
- name: Get changed files using defaults <details>
id: changed-files <summary>Get all changed files and using a comma separator</summary>
uses: tj-actions/changed-files@v32
- name: Get changed files using a comma separator ```yaml
id: changed-files-comma ...
uses: tj-actions/changed-files@v32 - name: Get all changed files and use a comma separator in the output
with: id: changed-files
separator: "," uses: tj-actions/changed-files@v32
with:
separator: ","
...
```
- name: List all added files See [inputs](#inputs) for more information.
run: | </details>
for file in ${{ steps.changed-files.outputs.added_files }}; do
echo "$file was added"
done
- name: Run step when a file changes <details>
if: contains(steps.changed-files.outputs.modified_files, 'my-file.txt') <summary> Get all changed files and list all added files</summary>
run: |
echo "Your my-file.txt file has been modified."
- name: Run step when a file has been deleted ```yaml
if: contains(steps.changed-files.outputs.deleted_files, 'test.txt') ...
run: | - name: Get changed files
echo "Your test.txt file has been deleted." id: changed-files
uses: tj-actions/changed-files@v32
- name: List all added files
run: |
for file in ${{ steps.changed-files.outputs.added_files }}; do
echo "$file was added"
done
...
```
- name: Get specific changed files See [outputs](#outputs) for a list of all available outputs.
id: changed-files-specific </details>
uses: tj-actions/changed-files@v32
with:
files: |
my-file.txt
test.txt
new.txt
test_directory
*.sh
*.png
!*.md
*.jpeg
**/migrate-*.sql
files_ignore: |
*.yml
- name: Run step if any of the listed files above change <details>
if: steps.changed-files-specific.outputs.any_changed == 'true' <summary>Get all changed files and optionally run a step if a file was modified</summary>
run: |
echo "One or more files listed above has changed."
- name: Run step if only the files listed above change ```yaml
if: steps.changed-files-specific.outputs.only_changed == 'true' ...
run: | - name: Get changed files
echo "Only files listed above have changed." id: changed-files
uses: tj-actions/changed-files@v32
- name: Run a step if my-file.txt was modified
if: contains(steps.changed-files.outputs.modified_files, 'my-file.txt')
run: |
echo "my-file.txt file has been modified."
...
```
- name: Run step if any of the listed files above is deleted See [outputs](#outputs) for a list of all available outputs.
if: steps.changed-files.outputs.any_deleted == 'true' </details>
run: |
for file in ${{ steps.changed-files.outputs.deleted_files }}; do
echo "$file was deleted"
done
- name: Run step if all listed files above have been deleted <details>
if: steps.changed-files.outputs.only_deleted == 'true' <summary>Get all changed files using a list of files</summary>
run: |
for file in ${{ steps.changed-files.outputs.deleted_files }}; do
echo "$file was deleted"
done
- name: Use a source file or list of file(s) to populate to files input. ```yaml
id: changed-files-specific-source-file ...
uses: tj-actions/changed-files@v32 - name: Get changed files
with: id: changed-files
files_from_source_file: | uses: tj-actions/changed-files@v32
test/changed-files-list.txt with:
files: |
my-file.txt
*.sh
*.png
!*.md
test_directory
**/*.sql
...
```
See [inputs](#inputs) for more information.
- name: Use a source file or list of file(s) to populate to files input and optionally specify more files. </details>
id: changed-files-specific-source-file-and-specify-files
uses: tj-actions/changed-files@v32
with:
files_from_source_file: |
test/changed-files-list.txt
files: |
test.txt
- name: Use a different commit SHA <details>
id: changed-files-custom-sha <summary>Get all changed files using a list of files and take action base on the changes</summary>
uses: tj-actions/changed-files@v32
with:
sha: ${{ github.event.pull_request.head.sha }}
- name: Use a different base SHA ```yaml
id: changed-files-custom-base-sha ...
uses: tj-actions/changed-files@v32 - name: Get changed files
with: id: changed-files
base_sha: ${{ github.event.pull_request.base.sha }} uses: tj-actions/changed-files@v32
with:
- name: Checkout into dir1 files: |
uses: actions/checkout@v3 my-file.txt
with: *.sh
fetch-depth: 0 *.png
path: dir1 !*.md
test_directory
**/*.sql
- name: Run changed-files with defaults on the dir1 - name: Run step if any of the listed files above change
id: changed-files-for-dir1 if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: tj-actions/changed-files@v32 run: |
with: echo "One or more files listed above has changed."
path: dir1
- name: List all added files in dir1 - name: Run step if only the files listed above change
run: | if: steps.changed-files-specific.outputs.only_changed == 'true'
for file in ${{ steps.changed-files-for-dir1.outputs.added_files }}; do run: |
echo "$file was added" echo "Only files listed above have changed."
done
- name: Run changed-files with quotepath disabled - name: Run step if any of the listed files above is deleted
id: changed-files-quotepath if: steps.changed-files.outputs.any_deleted == 'true'
uses: tj-actions/changed-files@v32 run: |
with: for file in ${{ steps.changed-files.outputs.deleted_files }}; do
quotepath: "false" echo "$file was deleted"
done
# Run changed-files action using the last successful commit as the base_sha - name: Run step if all listed files above have been deleted
# NOTE: This setting overrides the commit sha used by setting since_last_remote_commit to true. if: steps.changed-files.outputs.only_deleted == 'true'
# It is recommended to use either solution that works for your use case. run: |
for file in ${{ steps.changed-files.outputs.deleted_files }}; do
echo "$file was deleted"
done
...
```
See [outputs](#outputs) for a list of all available outputs.
# Push event based workflows </details>
<details>
<summary>Get all changed files using a source file or list of file(s) to populate to files input</summary>
```yaml
...
- name: Get changed files using a source file or list of file(s) to populate to files input.
id: changed-files-specific-source-file
uses: tj-actions/changed-files@v32
with:
files_from_source_file: |
test/changed-files-list.txt
...
```
See [inputs](#inputs) for more information.
</details>
<details>
<summary>Get changed files using a source file or list of file(s) to populate to files input and optionally specify more files</summary>
```yaml
...
- name: Get changed files using a source file or list of file(s) to populate to files input and optionally specify more files.
id: changed-files-specific-source-file-and-specify-files
uses: tj-actions/changed-files@v32
with:
files_from_source_file: |
test/changed-files-list.txt
files: |
test.txt
...
```
See [inputs](#inputs) for more information.
</details>
<details>
<summary>Get all changed files using a different SHA</summary>
```yaml
...
- name: Get changed files using a different SHA
id: changed-files
uses: tj-actions/changed-files@v32
with:
sha: ${{ github.event.pull_request.head.sha }}
...
```
See [inputs](#inputs) for more information.
</details>
<details>
<summary>Get all changed files using a different base SHA</summary>
```yaml
...
- name: Get changed files using a different base SHA
id: changed-files
uses: tj-actions/changed-files@v32
with:
base_sha: ${{ github.event.pull_request.base.sha }}
...
```
See [inputs](#inputs) for more information.
</details>
<details>
<summary>Get all changed files for a repository located in a different path</summary>
```yaml
...
- name: Checkout into dir1
uses: actions/checkout@v3
with:
fetch-depth: 0
path: dir1
- name: Run changed-files with defaults in dir1
id: changed-files-for-dir1
uses: tj-actions/changed-files@v32
with:
path: dir1
- name: List all added files in dir1
run: |
for file in ${{ steps.changed-files-for-dir1.outputs.added_files }}; do
echo "$file was added"
done
...
```
See [inputs](#inputs) for more information.
</details>
<details>
<summary>Get all changed files with non äšćįí characters i.e (Filename in other languages)</summary>
```yaml
...
- name: Run changed-files with quotepath disabled
id: changed-files-quotepath
uses: tj-actions/changed-files@v32
with:
quotepath: "false"
- name: Run changed-files with quotepath disabled for a specified list of file(s)
id: changed-files-quotepath-specific
uses: ./
with:
files: test/test-è.txt
quotepath: "false"
...
```
See [inputs](#inputs) for more information.
</details>
<details>
<summary>Get all changed files using the last successful commit of the base branch</summary>
<ul>
<li>
<details>
<summary>Push event</summary>
```yaml
...
- name: Get branch name - name: Get branch name
id: branch-name id: branch-name
uses: tj-actions/branch-names@v6 uses: tj-actions/branch-names@v6
@ -314,54 +453,106 @@ Support this project with a :star:
uses: tj-actions/changed-files@v32 uses: tj-actions/changed-files@v32
with: with:
base_sha: ${{ steps.last_successful_commit_push.outputs.commit_hash }} base_sha: ${{ steps.last_successful_commit_push.outputs.commit_hash }}
...
```
</details>
</li>
# Pull request based workflows. <li>
<details>
<summary>Pull request events </summary>
```yaml
...
- name: Get branch name - name: Get branch name
id: branch-name id: branch-name
uses: tj-actions/branch-names@v5 uses: tj-actions/branch-names@v5
if: github.event_name == 'pull_request'
- uses: nrwl/last-successful-commit-action@v1 - uses: nrwl/last-successful-commit-action@v1
id: last_successful_commit_pull_request id: last_successful_commit_pull_request
if: github.event_name == 'pull_request'
with: with:
branch: ${{ steps.branch-name.outputs.base_ref_branch }} # Get the last successful commit on master or main branch branch: ${{ steps.branch-name.outputs.base_ref_branch }} # Get the last successful commit on master or main branch
workflow_id: 'test.yml' workflow_id: 'test.yml'
github_token: ${{ secrets.GITHUB_TOKEN }} github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Run changed-files with the commit of the last successful test workflow run on main - name: Run changed-files with the commit of the last successful test workflow run on main
if: github.event_name == 'pull_request'
id: changed-files-base-sha-pull-request id: changed-files-base-sha-pull-request
uses: tj-actions/changed-files@v32 uses: tj-actions/changed-files@v32
with: with:
base_sha: ${{ steps.last_successful_commit_pull_request.outputs.commit_hash }} base_sha: ${{ steps.last_successful_commit_pull_request.outputs.commit_hash }}
...
- name: Run changed-files with dir_names
id: changed-files-dir-names
uses: tj-actions/changed-files@v32
with:
dir_names: "true"
# All outputs are JSON formatted arrays and can be used in other actions and matrix compatible jobs.
- name: Run changed-files with json output
id: changed-files-json
uses: tj-actions/changed-files@v32
with:
json: "true"
- name: Get changed-files since 2022-08-19
id: changed-files-since
uses: tj-actions/changed-files@v32
with:
since: "2022-08-19"
- name: Get changed-files until 2022-08-20
id: changed-files-until
uses: tj-actions/changed-files@v32
with:
until: "2022-08-20"
``` ```
</details>
</li>
</ul>
> NOTE: This setting overrides the commit sha used by setting `since_last_remote_commit` to true.
> It is recommended to use either solution that works for your use case.
See [inputs](#inputs) for more information.
</details>
<details>
<summary>Get all changed files but only return the directory names</summary>
```yaml
...
- name: Run changed-files with dir_names
id: changed-files-dir-names
uses: tj-actions/changed-files@v32
with:
dir_names: "true"
...
```
See [inputs](#inputs) for more information.
</details>
<details>
<summary>Get all changed files and return JSON formatted outputs</summary>
```yaml
...
- name: Run changed-files with json output
id: changed-files-json
uses: tj-actions/changed-files@v32
with:
json: "true"
...
```
See [inputs](#inputs) for more information.
</details>
<details>
<summary>Get all changed files by commits pushed in the past</summary>
```yaml
...
- name: Get changed-files since 2022-08-19
id: changed-files-since
uses: tj-actions/changed-files@v32
with:
since: "2022-08-19"
- name: Get changed-files until 2022-08-20
id: changed-files-until
uses: tj-actions/changed-files@v32
with:
until: "2022-08-20"
...
```
See [inputs](#inputs) for more information.
</details>
### Real world example
<img width="1147" alt="Screen Shot 2021-11-19 at 4 59 21 PM" src="https://user-images.githubusercontent.com/17484350/142696936-8b7ca955-7ef9-4d53-9bdf-3e0008e90c3f.png"> <img width="1147" alt="Screen Shot 2021-11-19 at 4 59 21 PM" src="https://user-images.githubusercontent.com/17484350/142696936-8b7ca955-7ef9-4d53-9bdf-3e0008e90c3f.png">
* Free software: [MIT license](LICENSE) * Free software: [MIT license](LICENSE)