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

feat: add support for json formatted output. #557

Merged
merged 18 commits into from Aug 3, 2022
39 changes: 39 additions & 0 deletions .github/workflows/manual-matrix-test.yml
@@ -0,0 +1,39 @@
name: Manual Matrix Test

on:
workflow_dispatch:

jobs:
changed-files:
name: Get changes
runs-on: ubuntu-latest
outputs:
matrix: "{\"container\": ${{ toJson(steps.changed-files.outputs.all_changed_files) }} }"
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0 # needed for tj-actions/changed-files
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v23
with:
json: true
- name: List all changed files
run: |
echo '${{ toJSON(steps.changed-files.outputs.all_changed_files) }}'

matrix-job:
name: Run Matrix Job
runs-on: ubuntu-latest
needs: [changed-files]
strategy:
matrix: ${{ fromJSON(needs.changed-files.outputs.matrix) }}
max-parallel: 4
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Test
run: |
echo ${{ matrix.container }}
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Expand Up @@ -332,6 +332,17 @@ jobs:
echo '${{ toJSON(steps.changed-files-pipe.outputs) }}'
shell:
bash
- name: Run changed-files with json output
id: changed-files-json
uses: ./
with:
json: true
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-json.outputs) }}'
echo '${{ toJSON(steps.changed-files-json.outputs.all_changed_files) }}'
shell:
bash
- name: Run changed-files with comma separator
id: changed-files-comma
uses: ./
Expand Down
12 changes: 10 additions & 2 deletions README.md
Expand Up @@ -130,7 +130,7 @@ Support this project with a :star:
|:--------------------------------------:|:----------------------:|:--------:|:---------------------:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| token | `string` | `false` | `${{ github.token }}` | [GITHUB\_TOKEN](https://docs.github.com/en/free-pro-team@latest/actions/reference/authentication-in-a-workflow#using-the-github_token-in-a-workflow) <br /> or a repo scoped <br /> [Personal Access Token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token) |
| separator | `string` | `false` | `' '` | Split character for output strings |
| include\_all\_old\_new\_renamed\_files | `boolean` | `false` | `false` | Include `all_old_new_renamed_files` output. Note this can generate a large output See: [#501](https://github.com/tj-actions/changed-files/issues/501). |
| include\_all\_old\_new\_renamed\_files | `boolean` | `false` | `false` | Include `all_old_new_renamed_files` output. Note this can generate a large output See: [#501](https://github.com/tj-actions/changed-files/issues/501). |
| old\_new\_separator | `string` | `false` | `','` | Split character for old and new filename pairs |
| old\_new\_files\_separator | `string` | `false` | `' '` | Split character for multiple old and new filename pairs |
| files | `string` OR `string[]` | `false` | | Check for changes <br> using only these <br> list of file(s) <br> (Defaults to the <br> entire repo) |
Expand All @@ -146,7 +146,8 @@ Support this project with a :star:
| use\_fork\_point | `boolean` | `false` | `false` | Finds best common ancestor <br /> between two commits <br /> to use in a three-way merge <br /> as the `base_sha` <br /> See: [git merge-base](https://git-scm.com/docs/git-merge-base#Documentation/git-merge-base.txt---fork-point). <br> NOTE: This pulls the entire commit history of the base branch |
| quotepath | `boolean` | `false` | `true` | Output filenames completely verbatim by setting this to `false` |
| diff\_relative | `boolean` | `false` | | Exclude changes outside the current directory and show pathnames relative to it. |
| dir\_names | `boolean` | `false` | `false` | Output unique changed directories instead of filenames. <br> NOTE: This returns `.` for <br> changed files located in the root of the project. |
| dir\_names | `boolean` | `false` | `false` | Output unique changed directories instead of filenames. <br> NOTE: This returns `.` for <br> changed files located in the root of the project. |
| json | `boolean` | `false` | `false` | Output changed files in JSON format which can be used for matrix jobs. |

## Examples

Expand Down Expand Up @@ -337,6 +338,13 @@ Support this project with a :star:
uses: tj-actions/changed-files@v24
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@v24
with:
json: "true"
```

<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">
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Expand Up @@ -77,6 +77,10 @@ inputs:
default: "false"
description: "Output the absolute path to the changed directories instead of the filenames"
required: false
json:
description: "Output changed files in JSON format which can be used for matrix jobs"
required: false
default: "false"

outputs:
added_files:
Expand Down Expand Up @@ -212,6 +216,7 @@ runs:
INPUT_OLD_NEW_FILES_SEPARATOR: ${{ inputs.old_new_files_separator }}
INPUT_DIFF_RELATIVE: ${{ inputs.diff_relative }}
INPUT_DIR_NAMES: ${{ inputs.dir_names }}
INPUT_JSON: ${{ inputs.json }}

branding:
icon: file-text
Expand Down