From 1d2b214597a6e07e0e1e6249135ff25a1d60bbc4 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 19 Dec 2022 02:41:53 -0700 Subject: [PATCH 1/8] feat: add support for writing outputs to files --- action.yml | 37 +++++++++++++++++++++++++++++++++++++ get-changed-paths.sh | 8 ++++++++ 2 files changed, 45 insertions(+) diff --git a/action.yml b/action.yml index 659544e7637..c64e9fc63c2 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" + generate_output: + description: "Generate files for all outputs 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,35 @@ 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.generate_output }} == 'true' + with: + outputs: ${{ toJSON(steps.changed-files.outputs) }} + directory: ${{ inputs.output_dir }} + 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..59242e2efc4 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_OUTPUTS" == "json" ]]; 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 From a046f31b8c609e27b2a9bd8228d58bbf1ac5f310 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 19 Dec 2022 02:46:01 -0700 Subject: [PATCH 2/8] updated the test --- .github/workflows/test.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1d6e5083305..2b7f3de10f2 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 generate_output + id: changed-files-generated-output + uses: ./ + with: + json: true + generate_output: true + - name: Show output + run: | + echo '${{ toJSON(steps.changed-files-generated-output.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: ./ From 414a39d80c3d3f3d8efa40a14eaf4e959731b4a9 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 19 Dec 2022 02:51:12 -0700 Subject: [PATCH 3/8] Update get-changed-paths.sh --- get-changed-paths.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get-changed-paths.sh b/get-changed-paths.sh index 59242e2efc4..61d9232e664 100755 --- a/get-changed-paths.sh +++ b/get-changed-paths.sh @@ -12,7 +12,7 @@ DIFF=$INPUT_DIFF OUTPUTS_EXTENSION="txt" -if [[ "$INPUT_OUTPUTS" == "json" ]]; then +if [[ "$INPUT_JSON" == "json" ]]; then OUTPUTS_EXTENSION="json" fi From bc45b73276893c301ce09bf2a789f6e010c1f863 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 19 Dec 2022 02:51:24 -0700 Subject: [PATCH 4/8] Update get-changed-paths.sh --- get-changed-paths.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get-changed-paths.sh b/get-changed-paths.sh index 61d9232e664..7deb9abdb3d 100755 --- a/get-changed-paths.sh +++ b/get-changed-paths.sh @@ -12,7 +12,7 @@ DIFF=$INPUT_DIFF OUTPUTS_EXTENSION="txt" -if [[ "$INPUT_JSON" == "json" ]]; then +if [[ "$INPUT_JSON" == "true" ]]; then OUTPUTS_EXTENSION="json" fi From 324636ef4d92e9ac8ad4d87cf15f7d7533760da2 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 19 Dec 2022 03:09:26 -0700 Subject: [PATCH 5/8] skip missing keys --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index c64e9fc63c2..cded831f399 100644 --- a/action.yml +++ b/action.yml @@ -244,6 +244,7 @@ runs: with: outputs: ${{ toJSON(steps.changed-files.outputs) }} directory: ${{ inputs.output_dir }} + skip_missing_keys: true keys: | added_files copied_files From 3f445f4e3df4f020a5804dc7d73fd168ac550b9e Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 19 Dec 2022 10:12:35 -0700 Subject: [PATCH 6/8] Update test.yml --- .github/workflows/test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2b7f3de10f2..8f2bb4d1c66 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -372,15 +372,15 @@ jobs: echo '${{ toJSON(steps.changed-files-since-last-remote-commit.outputs) }}' shell: bash - - name: Run changed-files with generate_output - id: changed-files-generated-output + - name: Run changed-files with write_output_files + id: changed-files-write-output-files uses: ./ with: json: true - generate_output: true + write_output_files: true - name: Show output run: | - echo '${{ toJSON(steps.changed-files-generated-output.outputs.all_changed_files) }}' + echo '${{ toJSON(steps.changed-files-write-output-files.outputs.all_changed_files) }}' cat .github/outputs/all_changed_files.json shell: bash From f7eec1808a6b266d67239cf704651c67fa247302 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 19 Dec 2022 10:13:30 -0700 Subject: [PATCH 7/8] Update action.yml --- action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index cded831f399..679f890b324 100644 --- a/action.yml +++ b/action.yml @@ -88,8 +88,8 @@ 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" - generate_output: - description: "Generate files for all outputs in the `.github/outputs` folder by default." + write_output_files: + description: "Write outputs to files in the `.github/outputs` folder by default." required: false default: "false" output_dir: @@ -240,7 +240,7 @@ runs: INPUT_HAS_CUSTOM_PATTERNS: ${{ steps.glob.outputs.has-custom-patterns }} - name: Generate output files uses: tj-actions/json2file@v1 - if: ${{ inputs.generate_output }} == 'true' + if: ${{ inputs.write_output_files }} == 'true' with: outputs: ${{ toJSON(steps.changed-files.outputs) }} directory: ${{ inputs.output_dir }} From b1a39700c2fddaa63d5115db7cf2062232a4a37d Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 19 Dec 2022 10:29:44 -0700 Subject: [PATCH 8/8] Update action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 679f890b324..3e19148d3a0 100644 --- a/action.yml +++ b/action.yml @@ -240,7 +240,7 @@ runs: 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' + if: inputs.write_output_files == 'true' with: outputs: ${{ toJSON(steps.changed-files.outputs) }} directory: ${{ inputs.output_dir }}