From 1982157b6c3cd3dae6ccce31fad0d2aec0784806 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 31 Jan 2023 16:54:49 -0700 Subject: [PATCH 1/5] feat: add support for excluding the top level directory --- action.yml | 5 +++++ get-changed-paths.sh | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/action.yml b/action.yml index 85dc803c..07345571 100644 --- a/action.yml +++ b/action.yml @@ -75,6 +75,10 @@ inputs: dir_names_max_depth: description: "Maximum depth of directories to output. e.g `test/test1/test2` with max depth of `2` returns `test/test1`." required: false + dir_names_exclude_root: + description: "Exclude the root directory from the output. **NOTE:** This would exclude `.` from the output." + required: false + default: "false" json: description: "Output list of changed files in a JSON formatted string which can be used for matrix jobs." required: false @@ -245,6 +249,7 @@ runs: INPUT_DIFF_RELATIVE: ${{ inputs.diff_relative }} INPUT_DIR_NAMES: ${{ inputs.dir_names }} INPUT_DIR_NAMES_MAX_DEPTH: ${{ inputs.dir_names_max_depth }} + INPUT_DIR_NAMES_EXCLUDE_ROOT: ${{ inputs.dir_names_exclude_root }} INPUT_JSON: ${{ inputs.json }} INPUT_HAS_CUSTOM_PATTERNS: ${{ steps.glob.outputs.has-custom-patterns }} INPUT_JSON_RAW_FORMAT: ${{ inputs.json_raw_format }} diff --git a/get-changed-paths.sh b/get-changed-paths.sh index 363d6576..5cf7fd2f 100755 --- a/get-changed-paths.sh +++ b/get-changed-paths.sh @@ -47,6 +47,10 @@ function get_dirname_max_depth() { depth=$((depth + 1)) done + if [[ "$INPUT_DIR_NAMES_EXCLUDE_ROOT" == "true" && "$output" == "." ]]; then + continue + fi + echo "$output" done < <(uniq) } From ce8c1983473789ea0319acbef16fa58973c124fd Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 31 Jan 2023 17:06:50 -0700 Subject: [PATCH 2/5] Updated the test. --- .github/workflows/test.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b9123fb6..ca12a803 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -446,6 +446,27 @@ jobs: exit 1 shell: bash + - name: Run changed-files with dir_names and dir_names_exclude_root + id: changed-files-dir-names-exclude-root + uses: ./ + with: + base_sha: dddfbd69 + sha: 1982157 + fetch_depth: 60000 + dir_names: "true" + dir_names_exclude_root: "true" + - name: Show output + run: | + echo '${{ toJSON(steps.changed-files-dir-names-exclude-root.outputs) }}' + shell: + bash + - name: Check dir_names output + if: steps.changed-files-dir-names-exclude-root.outputs.all_changed_files != "" + run: | + echo "Invalid output: Expected (empty) got (${{ steps.changed-files-dir-names-exclude-root.outputs.all_changed_files }})" + exit 1 + shell: + bash - name: Run changed-files with dir_names id: changed-files-dir-names uses: ./ From 35d9bb6ce9b56440cdc04f48310d58992b0251a0 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 31 Jan 2023 17:09:22 -0700 Subject: [PATCH 3/5] Updated the test --- .github/workflows/test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ca12a803..394f21ee 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -451,7 +451,7 @@ jobs: uses: ./ with: base_sha: dddfbd69 - sha: 1982157 + sha: ce8c1983 fetch_depth: 60000 dir_names: "true" dir_names_exclude_root: "true" @@ -461,9 +461,9 @@ jobs: shell: bash - name: Check dir_names output - if: steps.changed-files-dir-names-exclude-root.outputs.all_changed_files != "" + if: steps.changed-files-dir-names-exclude-root.outputs.all_changed_files != '.github' run: | - echo "Invalid output: Expected (empty) got (${{ steps.changed-files-dir-names-exclude-root.outputs.all_changed_files }})" + echo "Invalid output: Expected (.github) got (${{ steps.changed-files-dir-names-exclude-root.outputs.all_changed_files }})" exit 1 shell: bash From eb97e7897109c98c168e0ba36dd42227cb7f0fe4 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 31 Jan 2023 17:19:40 -0700 Subject: [PATCH 4/5] Update test.yml --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 394f21ee..ba49ca30 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -455,6 +455,7 @@ jobs: fetch_depth: 60000 dir_names: "true" dir_names_exclude_root: "true" + dir_names_max_depth: "1" - name: Show output run: | echo '${{ toJSON(steps.changed-files-dir-names-exclude-root.outputs) }}' From aae4005247fc2f8e9bc13a010cc310016e9e9367 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 31 Jan 2023 17:23:32 -0700 Subject: [PATCH 5/5] Update action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 07345571..ec1a4c15 100644 --- a/action.yml +++ b/action.yml @@ -76,7 +76,7 @@ inputs: description: "Maximum depth of directories to output. e.g `test/test1/test2` with max depth of `2` returns `test/test1`." required: false dir_names_exclude_root: - description: "Exclude the root directory from the output. **NOTE:** This would exclude `.` from the output." + description: "Exclude the root directory represented by `.` from the output when `dir_names`is set to `true`." required: false default: "false" json: