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 writing outputs to files #890

Merged
merged 9 commits into from Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
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
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
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