From 83952deb066af649951afb0211f296acc6da6bbe Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 19 Dec 2022 10:51:22 -0700 Subject: [PATCH] feat: add support for writing outputs to files (#890) Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com> --- .github/workflows/test.yml | 12 ++++++++++++ action.yml | 38 ++++++++++++++++++++++++++++++++++++++ get-changed-paths.sh | 8 ++++++++ 3 files changed, 58 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1d6e5083305..8f2bb4d1c66 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: ./ diff --git a/action.yml b/action.yml index 659544e7637..3e19148d3a0 100644 --- a/action.yml +++ b/action.yml @@ -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: @@ -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 diff --git a/get-changed-paths.sh b/get-changed-paths.sh index bff1402becc..7deb9abdb3d 100755 --- a/get-changed-paths.sh +++ b/get-changed-paths.sh @@ -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 @@ -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 <>"$GITHUB_OUTPUT" added_files=$ADDED @@ -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