Skip to content

Commit

Permalink
feat: add support for writing outputs to files (#890)
Browse files Browse the repository at this point in the history
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
  • Loading branch information
jackton1 and repo-ranger[bot] authored Dec 19, 2022
1 parent c4bb28b commit 83952de
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,18 @@ jobs:
echo '${{ toJSON(steps.changed-files-since-last-remote-commit.outputs) }}'
shell:
bash
- name: Run changed-files with write_output_files
id: changed-files-write-output-files
uses: ./
with:
json: true
write_output_files: true
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-write-output-files.outputs.all_changed_files) }}'
cat .github/outputs/all_changed_files.json
shell:
bash
- name: Run changed-files with include_all_old_new_renamed_files
id: changed-files-all-old-new-renamed-files
uses: ./
Expand Down
38 changes: 38 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ inputs:
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: true
default: "false"
write_output_files:
description: "Write outputs to files in the `.github/outputs` folder by default."
required: false
default: "false"
output_dir:
description: "Directory to store output files."
required: false
default: ".github/outputs"

outputs:
added_files:
Expand Down Expand Up @@ -230,6 +238,36 @@ runs:
INPUT_DIR_NAMES_MAX_DEPTH: ${{ inputs.dir_names_max_depth }}
INPUT_JSON: ${{ inputs.json }}
INPUT_HAS_CUSTOM_PATTERNS: ${{ steps.glob.outputs.has-custom-patterns }}
- name: Generate output files
uses: tj-actions/json2file@v1
if: inputs.write_output_files == 'true'
with:
outputs: ${{ toJSON(steps.changed-files.outputs) }}
directory: ${{ inputs.output_dir }}
skip_missing_keys: true
keys: |
added_files
copied_files
deleted_files
modified_files
renamed_files
all_old_new_renamed_files
type_changed_files
unmerged_files
unknown_files
all_changed_and_modified_files
all_changed_files
any_changed
only_changed
other_changed_files
all_modified_files
any_modified
only_modified
other_modified_files
any_deleted
only_deleted
other_deleted_files
extension: ${{ steps.changed-files.outputs.outputs_extension }}

branding:
icon: file-text
Expand Down
8 changes: 8 additions & 0 deletions get-changed-paths.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ INPUT_SEPARATOR="${INPUT_SEPARATOR//$'\r'/'%0D'}"
GITHUB_OUTPUT=${GITHUB_OUTPUT:-""}
DIFF=$INPUT_DIFF

OUTPUTS_EXTENSION="txt"

if [[ "$INPUT_JSON" == "true" ]]; then
OUTPUTS_EXTENSION="json"
fi

if [[ $INPUT_QUOTEPATH == "false" ]]; then
git config --global core.quotepath off
else
Expand Down Expand Up @@ -403,6 +409,7 @@ if [[ -z "$GITHUB_OUTPUT" ]]; then
echo "::set-output name=all_changed_and_modified_files::$ALL_CHANGED_AND_MODIFIED"
echo "::set-output name=all_changed_files::$ALL_CHANGED"
echo "::set-output name=all_modified_files::$ALL_MODIFIED"
echo "::set-output name=outputs_extension::$OUTPUTS_EXTENSION"
else
cat <<EOF >>"$GITHUB_OUTPUT"
added_files=$ADDED
Expand All @@ -416,6 +423,7 @@ unknown_files=$UNKNOWN
all_changed_and_modified_files=$ALL_CHANGED_AND_MODIFIED
all_changed_files=$ALL_CHANGED
all_modified_files=$ALL_MODIFIED
outputs_extension=$OUTPUTS_EXTENSION
EOF
fi

Expand Down

0 comments on commit 83952de

Please sign in to comment.