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

271
README.md
View file

@ -166,56 +166,111 @@ Support this project with a :star:
## Examples
<details>
<summary>Get all changed files in the current branch</summary>
```yaml
...
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit.
# submodules: true # OR "recursive" -> To include all changed submodule files.
- name: Get changed files using defaults
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v32
...
```
</details>
- name: Get changed files using a comma separator
id: changed-files-comma
<details>
<summary>Get all changed files and using a comma separator</summary>
```yaml
...
- name: Get all changed files and use a comma separator in the output
id: changed-files
uses: tj-actions/changed-files@v32
with:
separator: ","
...
```
See [inputs](#inputs) for more information.
</details>
<details>
<summary> Get all changed files and list all added files</summary>
```yaml
...
- name: Get changed files
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: Run step when a file changes
See [outputs](#outputs) for a list of all available outputs.
</details>
<details>
<summary>Get all changed files and optionally run a step if a file was modified</summary>
```yaml
...
- name: Get changed files
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 "Your my-file.txt file has been modified."
echo "my-file.txt file has been modified."
...
```
- name: Run step when a file has been deleted
if: contains(steps.changed-files.outputs.deleted_files, 'test.txt')
run: |
echo "Your test.txt file has been deleted."
See [outputs](#outputs) for a list of all available outputs.
</details>
- name: Get specific changed files
id: changed-files-specific
<details>
<summary>Get all changed files using a list of files</summary>
```yaml
...
- name: Get changed files
id: changed-files
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
test_directory
**/*.sql
...
```
See [inputs](#inputs) for more information.
</details>
<details>
<summary>Get all changed files using a list of files and take action base on the changes</summary>
```yaml
...
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v32
with:
files: |
my-file.txt
*.sh
*.png
!*.md
test_directory
**/*.sql
- name: Run step if any of the listed files above change
if: steps.changed-files-specific.outputs.any_changed == 'true'
@ -240,15 +295,36 @@ Support this project with a :star:
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.
- name: Use a source file or list of file(s) to populate to files input.
</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
...
```
- name: Use a source file or list of file(s) to populate to files input and optionally specify more files.
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:
@ -256,26 +332,60 @@ Support this project with a :star:
test/changed-files-list.txt
files: |
test.txt
...
```
- name: Use a different commit SHA
id: changed-files-custom-sha
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 }}
...
```
- name: Use a different base SHA
id: changed-files-custom-base-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 on the dir1
- name: Run changed-files with defaults in dir1
id: changed-files-for-dir1
uses: tj-actions/changed-files@v32
with:
@ -286,18 +396,47 @@ Support this project with a :star:
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"
# Run changed-files action using the last successful commit as the base_sha
# 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.
- 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"
...
```
# Push event based workflows
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
id: branch-name
uses: tj-actions/branch-names@v6
@ -314,41 +453,86 @@ Support this project with a :star:
uses: tj-actions/changed-files@v32
with:
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
id: branch-name
uses: tj-actions/branch-names@v5
if: github.event_name == 'pull_request'
- uses: nrwl/last-successful-commit-action@v1
id: last_successful_commit_pull_request
if: github.event_name == 'pull_request'
with:
branch: ${{ steps.branch-name.outputs.base_ref_branch }} # Get the last successful commit on master or main branch
workflow_id: 'test.yml'
github_token: ${{ secrets.GITHUB_TOKEN }}
- 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
uses: tj-actions/changed-files@v32
with:
base_sha: ${{ steps.last_successful_commit_pull_request.outputs.commit_hash }}
...
```
</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"
...
```
# All outputs are JSON formatted arrays and can be used in other actions and matrix compatible jobs.
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
@ -360,8 +544,15 @@ Support this project with a :star:
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">
* Free software: [MIT license](LICENSE)