From 4458f80f65be487d9f31e0a8bdb00f23ee24b297 Mon Sep 17 00:00:00 2001 From: adonisgarciac Date: Wed, 28 Dec 2022 17:02:30 +0100 Subject: [PATCH 1/9] add raw-output option for json output --- get-changed-paths.sh | 52 ++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/get-changed-paths.sh b/get-changed-paths.sh index 7deb9abdb3d..08ef947c88e 100755 --- a/get-changed-paths.sh +++ b/get-changed-paths.sh @@ -172,19 +172,19 @@ if [[ "$INPUT_HAS_CUSTOM_PATTERNS" == "false" ]]; then ALL_OLD_NEW_RENAMED=$(get_renames "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" | awk -v d="$INPUT_OLD_NEW_FILES_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') fi else - ADDED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" A | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - COPIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" C | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - DELETED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" D | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" M | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - RENAMED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" R | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - TYPE_CHANGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" T | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - UNMERGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" U | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - UNKNOWN=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" X | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_CHANGED_AND_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "*ACDMRTUX" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_CHANGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMR" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMRD" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ADDED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" A | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + COPIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" C | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + DELETED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" D | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" M | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + RENAMED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" R | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + TYPE_CHANGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" T | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + UNMERGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" U | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + UNKNOWN=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" X | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_CHANGED_AND_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "*ACDMRTUX" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_CHANGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMR" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMRD" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) if [[ $INPUT_INCLUDE_ALL_OLD_NEW_RENAMED_FILES == "true" ]]; then - ALL_OLD_NEW_RENAMED=$(get_renames "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_OLD_NEW_RENAMED=$(get_renames "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) fi fi else @@ -233,7 +233,7 @@ else if [[ "$INPUT_JSON" == "false" ]]; then OTHER_CHANGED=$(echo "${OTHER_CHANGED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') else - OTHER_CHANGED=$(echo "${OTHER_CHANGED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + OTHER_CHANGED=$(echo "${OTHER_CHANGED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) fi if [[ -n "${OTHER_CHANGED}" && "${OTHER_CHANGED}" != "[]" ]]; then @@ -285,7 +285,7 @@ else if [[ "$INPUT_JSON" == "false" ]]; then OTHER_MODIFIED=$(echo "${OTHER_MODIFIED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') else - OTHER_MODIFIED=$(echo "${OTHER_MODIFIED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + OTHER_MODIFIED=$(echo "${OTHER_MODIFIED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) fi if [[ -n "${OTHER_MODIFIED}" && "$OTHER_MODIFIED" != "[]" ]]; then @@ -336,7 +336,7 @@ else if [[ "$INPUT_JSON" == "false" ]]; then OTHER_DELETED=$(echo "${OTHER_DELETED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') else - OTHER_DELETED=$(echo "${OTHER_DELETED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + OTHER_DELETED=$(echo "${OTHER_DELETED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) fi if [[ -n "${OTHER_DELETED}" && "${OTHER_DELETED}" != "[]" ]]; then @@ -368,17 +368,17 @@ else ALL_CHANGED=$(echo "${ALL_CHANGED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') ALL_MODIFIED=$(echo "${ALL_MODIFIED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') else - ADDED=$(echo "${ADDED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - COPIED=$(echo "${COPIED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - DELETED=$(echo "${DELETED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - MODIFIED=$(echo "${MODIFIED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - RENAMED=$(echo "${RENAMED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - TYPE_CHANGED=$(echo "${TYPE_CHANGED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - UNMERGED=$(echo "${UNMERGED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - UNKNOWN=$(echo "${UNKNOWN}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_CHANGED_AND_MODIFIED=$(echo "${ALL_CHANGED_AND_MODIFIED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_CHANGED=$(echo "${ALL_CHANGED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_MODIFIED=$(echo "${ALL_MODIFIED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ADDED=$(echo "${ADDED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + COPIED=$(echo "${COPIED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + DELETED=$(echo "${DELETED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + MODIFIED=$(echo "${MODIFIED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + RENAMED=$(echo "${RENAMED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + TYPE_CHANGED=$(echo "${TYPE_CHANGED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + UNMERGED=$(echo "${UNMERGED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + UNKNOWN=$(echo "${UNKNOWN}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_CHANGED_AND_MODIFIED=$(echo "${ALL_CHANGED_AND_MODIFIED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_CHANGED=$(echo "${ALL_CHANGED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_MODIFIED=$(echo "${ALL_MODIFIED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) fi fi From 1f84a785f2ca206b90fb954549ddafe31318df54 Mon Sep 17 00:00:00 2001 From: adonisgarciac Date: Thu, 29 Dec 2022 16:30:36 +0100 Subject: [PATCH 2/9] add jq_raw_input as a variable --- README.md | 9 +++---- action.yml | 5 ++++ get-changed-paths.sh | 57 ++++++++++++++++++++++++-------------------- 3 files changed, 41 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 95da1f8926f..284e68a0d94 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ on: push: branches: - main - # Compare the last commit of main -> to the current commit of a PR branch. + # Compare the last commit of main -> to the current commit of a PR branch. # (Note: To compare changes between the last pushed commit to the remote PR branch set `since_last_remote_commit: true`) pull_request: branches: @@ -183,6 +183,7 @@ Support this project with a :star: | since\_last\_remote\_commit | string | true | `"false"` | 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. | | until | string | false | | Get changed files for commits whose timestamp
is earlier than the given time. | | write\_output\_files | string | false | `"false"` | Write outputs to files in the `.github/outputs`
folder by default. | +| jq_raw_input | string | false | `"false"` | When json is true, if jq_raw_input is true as well, output will be formated directly as a validated json. However if it is false, output will be formated to use, f.e. with fromJSON | @@ -226,7 +227,7 @@ See [inputs](#inputs) for more information. - name: Get changed files id: changed-files uses: tj-actions/changed-files@v35 - + - name: List all added files run: | for file in ${{ steps.changed-files.outputs.added_files }}; do @@ -471,7 +472,7 @@ See [inputs](#inputs) for more information. - uses: nrwl/nx-set-shas@v3 id: last_successful_commit_push with: - main-branch-name: ${{ steps.branch-name.outputs.current_branch }} # Get the last successful commit for the current branch. + main-branch-name: ${{ steps.branch-name.outputs.current_branch }} # Get the last successful commit for the current branch. workflow-id: 'test.yml' - name: Run changed-files with the commit of the last successful test workflow run @@ -498,7 +499,7 @@ See [inputs](#inputs) for more information. - uses: nrwl/nx-set-shas@v3 id: last_successful_commit_pull_request with: - main-branch-name: ${{ steps.branch-name.outputs.base_ref_branch }} # Get the last successful commit on master or main branch + main-branch-name: ${{ steps.branch-name.outputs.base_ref_branch }} # Get the last successful commit on master or main branch workflow_id: 'test.yml' - name: Run changed-files with the commit of the last successful test workflow run on main diff --git a/action.yml b/action.yml index 98884136dd1..7097880542b 100644 --- a/action.yml +++ b/action.yml @@ -95,6 +95,10 @@ inputs: description: "Directory to store output files." required: false default: ".github/outputs" + jq_raw_input: + description: "With this option, if the filter's result is a string then it will be written directly to standard output rather than being formatted as a JSON string with quotes. This can be useful for making jq filters talk to non-JSON-based systems." + required: false + default: "false" outputs: added_files: @@ -238,6 +242,7 @@ 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 }} + JQ_RAW_INPUT: ${{ inputs.jq_raw_input }} - name: Generate output files uses: tj-actions/json2file@v1 if: inputs.write_output_files == 'true' diff --git a/get-changed-paths.sh b/get-changed-paths.sh index 08ef947c88e..51773ff503b 100755 --- a/get-changed-paths.sh +++ b/get-changed-paths.sh @@ -11,6 +11,11 @@ GITHUB_OUTPUT=${GITHUB_OUTPUT:-""} DIFF=$INPUT_DIFF OUTPUTS_EXTENSION="txt" +OPTIONS_JQ="-R" + +if [[ "$JQ_RAW_INPUT" == "true" ]]; then + OPTIONS_JQ="-r -R" +fi if [[ "$INPUT_JSON" == "true" ]]; then OUTPUTS_EXTENSION="json" @@ -172,19 +177,19 @@ if [[ "$INPUT_HAS_CUSTOM_PATTERNS" == "false" ]]; then ALL_OLD_NEW_RENAMED=$(get_renames "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" | awk -v d="$INPUT_OLD_NEW_FILES_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') fi else - ADDED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" A | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - COPIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" C | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - DELETED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" D | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" M | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - RENAMED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" R | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - TYPE_CHANGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" T | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - UNMERGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" U | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - UNKNOWN=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" X | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_CHANGED_AND_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "*ACDMRTUX" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_CHANGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMR" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMRD" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ADDED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" A | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + COPIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" C | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + DELETED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" D | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" M | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + RENAMED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" R | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + TYPE_CHANGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" T | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + UNMERGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" U | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + UNKNOWN=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" X | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_CHANGED_AND_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "*ACDMRTUX" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_CHANGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMR" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMRD" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) if [[ $INPUT_INCLUDE_ALL_OLD_NEW_RENAMED_FILES == "true" ]]; then - ALL_OLD_NEW_RENAMED=$(get_renames "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_OLD_NEW_RENAMED=$(get_renames "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) fi fi else @@ -233,7 +238,7 @@ else if [[ "$INPUT_JSON" == "false" ]]; then OTHER_CHANGED=$(echo "${OTHER_CHANGED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') else - OTHER_CHANGED=$(echo "${OTHER_CHANGED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + OTHER_CHANGED=$(echo "${OTHER_CHANGED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) fi if [[ -n "${OTHER_CHANGED}" && "${OTHER_CHANGED}" != "[]" ]]; then @@ -285,7 +290,7 @@ else if [[ "$INPUT_JSON" == "false" ]]; then OTHER_MODIFIED=$(echo "${OTHER_MODIFIED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') else - OTHER_MODIFIED=$(echo "${OTHER_MODIFIED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + OTHER_MODIFIED=$(echo "${OTHER_MODIFIED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) fi if [[ -n "${OTHER_MODIFIED}" && "$OTHER_MODIFIED" != "[]" ]]; then @@ -336,7 +341,7 @@ else if [[ "$INPUT_JSON" == "false" ]]; then OTHER_DELETED=$(echo "${OTHER_DELETED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') else - OTHER_DELETED=$(echo "${OTHER_DELETED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + OTHER_DELETED=$(echo "${OTHER_DELETED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) fi if [[ -n "${OTHER_DELETED}" && "${OTHER_DELETED}" != "[]" ]]; then @@ -368,17 +373,17 @@ else ALL_CHANGED=$(echo "${ALL_CHANGED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') ALL_MODIFIED=$(echo "${ALL_MODIFIED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') else - ADDED=$(echo "${ADDED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - COPIED=$(echo "${COPIED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - DELETED=$(echo "${DELETED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - MODIFIED=$(echo "${MODIFIED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - RENAMED=$(echo "${RENAMED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - TYPE_CHANGED=$(echo "${TYPE_CHANGED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - UNMERGED=$(echo "${UNMERGED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - UNKNOWN=$(echo "${UNKNOWN}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_CHANGED_AND_MODIFIED=$(echo "${ALL_CHANGED_AND_MODIFIED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_CHANGED=$(echo "${ALL_CHANGED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_MODIFIED=$(echo "${ALL_MODIFIED}" | jq -r -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ADDED=$(echo "${ADDED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + COPIED=$(echo "${COPIED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + DELETED=$(echo "${DELETED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + MODIFIED=$(echo "${MODIFIED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + RENAMED=$(echo "${RENAMED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + TYPE_CHANGED=$(echo "${TYPE_CHANGED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + UNMERGED=$(echo "${UNMERGED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + UNKNOWN=$(echo "${UNKNOWN}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_CHANGED_AND_MODIFIED=$(echo "${ALL_CHANGED_AND_MODIFIED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_CHANGED=$(echo "${ALL_CHANGED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_MODIFIED=$(echo "${ALL_MODIFIED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) fi fi From 275f0f80156e63c29c9847ab82d31f969764e871 Mon Sep 17 00:00:00 2001 From: adonisgarciac Date: Thu, 29 Dec 2022 16:50:31 +0100 Subject: [PATCH 3/9] change varname OPTIONS_JQ for JQ_OPTIONS --- get-changed-paths.sh | 56 ++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/get-changed-paths.sh b/get-changed-paths.sh index 51773ff503b..ddf6b992ce4 100755 --- a/get-changed-paths.sh +++ b/get-changed-paths.sh @@ -11,10 +11,10 @@ GITHUB_OUTPUT=${GITHUB_OUTPUT:-""} DIFF=$INPUT_DIFF OUTPUTS_EXTENSION="txt" -OPTIONS_JQ="-R" +JQ_OPTIONS="-R" if [[ "$JQ_RAW_INPUT" == "true" ]]; then - OPTIONS_JQ="-r -R" + JQ_OPTIONS="-r -R" fi if [[ "$INPUT_JSON" == "true" ]]; then @@ -177,19 +177,19 @@ if [[ "$INPUT_HAS_CUSTOM_PATTERNS" == "false" ]]; then ALL_OLD_NEW_RENAMED=$(get_renames "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" | awk -v d="$INPUT_OLD_NEW_FILES_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') fi else - ADDED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" A | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - COPIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" C | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - DELETED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" D | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" M | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - RENAMED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" R | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - TYPE_CHANGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" T | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - UNMERGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" U | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - UNKNOWN=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" X | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_CHANGED_AND_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "*ACDMRTUX" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_CHANGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMR" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMRD" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ADDED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" A | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + COPIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" C | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + DELETED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" D | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" M | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + RENAMED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" R | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + TYPE_CHANGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" T | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + UNMERGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" U | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + UNKNOWN=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" X | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_CHANGED_AND_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "*ACDMRTUX" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_CHANGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMR" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMRD" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) if [[ $INPUT_INCLUDE_ALL_OLD_NEW_RENAMED_FILES == "true" ]]; then - ALL_OLD_NEW_RENAMED=$(get_renames "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_OLD_NEW_RENAMED=$(get_renames "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) fi fi else @@ -238,7 +238,7 @@ else if [[ "$INPUT_JSON" == "false" ]]; then OTHER_CHANGED=$(echo "${OTHER_CHANGED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') else - OTHER_CHANGED=$(echo "${OTHER_CHANGED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + OTHER_CHANGED=$(echo "${OTHER_CHANGED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) fi if [[ -n "${OTHER_CHANGED}" && "${OTHER_CHANGED}" != "[]" ]]; then @@ -290,7 +290,7 @@ else if [[ "$INPUT_JSON" == "false" ]]; then OTHER_MODIFIED=$(echo "${OTHER_MODIFIED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') else - OTHER_MODIFIED=$(echo "${OTHER_MODIFIED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + OTHER_MODIFIED=$(echo "${OTHER_MODIFIED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) fi if [[ -n "${OTHER_MODIFIED}" && "$OTHER_MODIFIED" != "[]" ]]; then @@ -341,7 +341,7 @@ else if [[ "$INPUT_JSON" == "false" ]]; then OTHER_DELETED=$(echo "${OTHER_DELETED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') else - OTHER_DELETED=$(echo "${OTHER_DELETED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + OTHER_DELETED=$(echo "${OTHER_DELETED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) fi if [[ -n "${OTHER_DELETED}" && "${OTHER_DELETED}" != "[]" ]]; then @@ -373,17 +373,17 @@ else ALL_CHANGED=$(echo "${ALL_CHANGED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') ALL_MODIFIED=$(echo "${ALL_MODIFIED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') else - ADDED=$(echo "${ADDED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - COPIED=$(echo "${COPIED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - DELETED=$(echo "${DELETED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - MODIFIED=$(echo "${MODIFIED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - RENAMED=$(echo "${RENAMED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - TYPE_CHANGED=$(echo "${TYPE_CHANGED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - UNMERGED=$(echo "${UNMERGED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - UNKNOWN=$(echo "${UNKNOWN}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_CHANGED_AND_MODIFIED=$(echo "${ALL_CHANGED_AND_MODIFIED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_CHANGED=$(echo "${ALL_CHANGED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_MODIFIED=$(echo "${ALL_MODIFIED}" | jq $OPTIONS_JQ 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ADDED=$(echo "${ADDED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + COPIED=$(echo "${COPIED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + DELETED=$(echo "${DELETED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + MODIFIED=$(echo "${MODIFIED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + RENAMED=$(echo "${RENAMED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + TYPE_CHANGED=$(echo "${TYPE_CHANGED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + UNMERGED=$(echo "${UNMERGED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + UNKNOWN=$(echo "${UNKNOWN}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_CHANGED_AND_MODIFIED=$(echo "${ALL_CHANGED_AND_MODIFIED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_CHANGED=$(echo "${ALL_CHANGED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_MODIFIED=$(echo "${ALL_MODIFIED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) fi fi From dbfe2bcc9a901b4985753d17949b27ed0c5f4e2b Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 29 Dec 2022 21:42:07 -0700 Subject: [PATCH 4/9] Simplify implementation --- README.md | 1 - action.yml | 10 +++---- get-changed-paths.sh | 67 +++++++++++++++++++++++--------------------- 3 files changed, 40 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 284e68a0d94..67ec31e2053 100644 --- a/README.md +++ b/README.md @@ -183,7 +183,6 @@ Support this project with a :star: | since\_last\_remote\_commit | string | true | `"false"` | 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. | | until | string | false | | Get changed files for commits whose timestamp
is earlier than the given time. | | write\_output\_files | string | false | `"false"` | Write outputs to files in the `.github/outputs`
folder by default. | -| jq_raw_input | string | false | `"false"` | When json is true, if jq_raw_input is true as well, output will be formated directly as a validated json. However if it is false, output will be formated to use, f.e. with fromJSON | diff --git a/action.yml b/action.yml index 7097880542b..7b9bd6d4d79 100644 --- a/action.yml +++ b/action.yml @@ -79,6 +79,10 @@ inputs: description: "Output list of changed files in a JSON formatted string which can be used for matrix jobs." required: false default: "false" + json_raw_format: + description: "Output list of changed files in a raw format which means that the output will not be surrounded by quotes and special characters will not be escaped." + required: false + default: "false" fetch_depth: description: "Depth of additional branch history fetched. **NOTE**: This can be adjusted to resolve errors with insufficient history." required: false @@ -95,10 +99,6 @@ inputs: description: "Directory to store output files." required: false default: ".github/outputs" - jq_raw_input: - description: "With this option, if the filter's result is a string then it will be written directly to standard output rather than being formatted as a JSON string with quotes. This can be useful for making jq filters talk to non-JSON-based systems." - required: false - default: "false" outputs: added_files: @@ -242,7 +242,7 @@ 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 }} - JQ_RAW_INPUT: ${{ inputs.jq_raw_input }} + INPUT_JSON_RAW_FORMAT: ${{ inputs.json_raw_format }} - name: Generate output files uses: tj-actions/json2file@v1 if: inputs.write_output_files == 'true' diff --git a/get-changed-paths.sh b/get-changed-paths.sh index ddf6b992ce4..b03f896b562 100755 --- a/get-changed-paths.sh +++ b/get-changed-paths.sh @@ -11,11 +11,6 @@ GITHUB_OUTPUT=${GITHUB_OUTPUT:-""} DIFF=$INPUT_DIFF OUTPUTS_EXTENSION="txt" -JQ_OPTIONS="-R" - -if [[ "$JQ_RAW_INPUT" == "true" ]]; then - JQ_OPTIONS="-r -R" -fi if [[ "$INPUT_JSON" == "true" ]]; then OUTPUTS_EXTENSION="json" @@ -56,6 +51,14 @@ function get_dirname_max_depth() { done < <(uniq) } +function json_output() { + if [[ "$INPUT_JSON_RAW_FORMAT" == "true" ]]; then + jq -rR 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s / + else + jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s / + fi +} + function get_diff() { local base="$1" local sha="$2" @@ -177,19 +180,19 @@ if [[ "$INPUT_HAS_CUSTOM_PATTERNS" == "false" ]]; then ALL_OLD_NEW_RENAMED=$(get_renames "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" | awk -v d="$INPUT_OLD_NEW_FILES_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') fi else - ADDED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" A | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - COPIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" C | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - DELETED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" D | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" M | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - RENAMED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" R | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - TYPE_CHANGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" T | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - UNMERGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" U | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - UNKNOWN=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" X | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_CHANGED_AND_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "*ACDMRTUX" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_CHANGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMR" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMRD" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ADDED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" A | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | json_output) + COPIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" C | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | json_output) + DELETED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" D | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | json_output) + MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" M | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | json_output) + RENAMED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" R | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | json_output) + TYPE_CHANGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" T | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | json_output) + UNMERGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" U | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | json_output) + UNKNOWN=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" X | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | json_output) + ALL_CHANGED_AND_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "*ACDMRTUX" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | json_output) + ALL_CHANGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMR" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | json_output) + ALL_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMRD" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | json_output) if [[ $INPUT_INCLUDE_ALL_OLD_NEW_RENAMED_FILES == "true" ]]; then - ALL_OLD_NEW_RENAMED=$(get_renames "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ALL_OLD_NEW_RENAMED=$(get_renames "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}' | json_output) fi fi else @@ -238,7 +241,7 @@ else if [[ "$INPUT_JSON" == "false" ]]; then OTHER_CHANGED=$(echo "${OTHER_CHANGED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') else - OTHER_CHANGED=$(echo "${OTHER_CHANGED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + OTHER_CHANGED=$(echo "${OTHER_CHANGED}" | json_output) fi if [[ -n "${OTHER_CHANGED}" && "${OTHER_CHANGED}" != "[]" ]]; then @@ -290,7 +293,7 @@ else if [[ "$INPUT_JSON" == "false" ]]; then OTHER_MODIFIED=$(echo "${OTHER_MODIFIED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') else - OTHER_MODIFIED=$(echo "${OTHER_MODIFIED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + OTHER_MODIFIED=$(echo "${OTHER_MODIFIED}" | json_output) fi if [[ -n "${OTHER_MODIFIED}" && "$OTHER_MODIFIED" != "[]" ]]; then @@ -341,7 +344,7 @@ else if [[ "$INPUT_JSON" == "false" ]]; then OTHER_DELETED=$(echo "${OTHER_DELETED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') else - OTHER_DELETED=$(echo "${OTHER_DELETED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + OTHER_DELETED=$(echo "${OTHER_DELETED}" | json_output) fi if [[ -n "${OTHER_DELETED}" && "${OTHER_DELETED}" != "[]" ]]; then @@ -373,17 +376,17 @@ else ALL_CHANGED=$(echo "${ALL_CHANGED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') ALL_MODIFIED=$(echo "${ALL_MODIFIED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') else - ADDED=$(echo "${ADDED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - COPIED=$(echo "${COPIED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - DELETED=$(echo "${DELETED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - MODIFIED=$(echo "${MODIFIED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - RENAMED=$(echo "${RENAMED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - TYPE_CHANGED=$(echo "${TYPE_CHANGED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - UNMERGED=$(echo "${UNMERGED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - UNKNOWN=$(echo "${UNKNOWN}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_CHANGED_AND_MODIFIED=$(echo "${ALL_CHANGED_AND_MODIFIED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_CHANGED=$(echo "${ALL_CHANGED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) - ALL_MODIFIED=$(echo "${ALL_MODIFIED}" | jq $JQ_OPTIONS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /) + ADDED=$(echo "${ADDED}" | json_output) + COPIED=$(echo "${COPIED}" | json_output) + DELETED=$(echo "${DELETED}" | json_output) + MODIFIED=$(echo "${MODIFIED}" | json_output) + RENAMED=$(echo "${RENAMED}" | json_output) + TYPE_CHANGED=$(echo "${TYPE_CHANGED}" | json_output) + UNMERGED=$(echo "${UNMERGED}" | json_output) + UNKNOWN=$(echo "${UNKNOWN}" | json_output) + ALL_CHANGED_AND_MODIFIED=$(echo "${ALL_CHANGED_AND_MODIFIED}" | json_output) + ALL_CHANGED=$(echo "${ALL_CHANGED}" | json_output) + ALL_MODIFIED=$(echo "${ALL_MODIFIED}" | json_output) fi fi @@ -440,4 +443,4 @@ if [[ $INPUT_INCLUDE_ALL_OLD_NEW_RENAMED_FILES == "true" ]]; then fi fi -echo "::endgroup::" +echo "::endgroup::" \ No newline at end of file From 51e6533d246cdb6bece0e0073f4e5a1cc59d03dc Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 29 Dec 2022 21:44:19 -0700 Subject: [PATCH 5/9] Switch to use args --- get-changed-paths.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/get-changed-paths.sh b/get-changed-paths.sh index b03f896b562..0dc49273fc6 100755 --- a/get-changed-paths.sh +++ b/get-changed-paths.sh @@ -52,11 +52,13 @@ function get_dirname_max_depth() { } function json_output() { + JQ_ARGS="-R" if [[ "$INPUT_JSON_RAW_FORMAT" == "true" ]]; then - jq -rR 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s / - else - jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s / + JQ_ARGS="$JQ_ARGS -r" fi + + # shellcheck disable=SC2086 + jq $JQ_ARGS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s / } function get_diff() { From 67900223af8262a7ccc4a4c89032cabeb6901b82 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 29 Dec 2022 21:49:27 -0700 Subject: [PATCH 6/9] 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 868235a62c8..34dad0f5c67 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -529,6 +529,18 @@ jobs: echo '${{ toJSON(steps.changed-files-json.outputs.all_changed_files) }}' shell: bash + - name: Run changed-files with json raw format + id: changed-files-json-raw-format + uses: ./ + with: + json: true + json_raw_format: true + - name: Show output + run: | + echo '${{ toJSON(steps.changed-files-json-raw-format.outputs) }}' + echo '${{ toJSON(steps.changed-files-json-raw-format.outputs.all_changed_files) }}' + shell: + bash - name: Run changed-files with comma separator id: changed-files-comma uses: ./ From 31a4ace6b1b3831e06ffa51ea72548cbd334a581 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 29 Dec 2022 21:59:06 -0700 Subject: [PATCH 7/9] Test usage of raw json format with matrix jobs --- .github/workflows/manual-matrix-test.yml | 30 +++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/.github/workflows/manual-matrix-test.yml b/.github/workflows/manual-matrix-test.yml index fca089a833f..e0a8e5f8ee1 100644 --- a/.github/workflows/manual-matrix-test.yml +++ b/.github/workflows/manual-matrix-test.yml @@ -12,6 +12,7 @@ jobs: runs-on: ubuntu-latest outputs: matrix: ${{ steps.set-matrix.outputs.matrix }} + matrix-raw-format: ${{ steps.set-matrix-json-raw-format.outputs.matrix }} steps: - name: Checkout uses: actions/checkout@v3 @@ -23,11 +24,19 @@ jobs: with: json: true - name: List all changed files - run: | - echo '${{ steps.changed-files.outputs.all_changed_files }}' - + run: echo '${{ steps.changed-files.outputs.all_changed_files }}' - id: set-matrix run: echo "matrix={\"container\":${{ steps.changed-files.outputs.all_changed_files }}}" >> "$GITHUB_OUTPUT" + - name: Get changed files json raw format + id: changed-files-json-raw-format + uses: ./ + with: + json: true + json_raw_format: true + - name: List all changed files json raw format + run: echo '${{ steps.changed-files-json-raw-format.outputs.all_changed_files }}' + - id: set-matrix-json-raw-format + run: echo "matrix={\"container\":${{ steps.changed-files.outputs.all_changed_files }}}" >> "$GITHUB_OUTPUT" matrix-job: name: Run Matrix Job @@ -43,3 +52,18 @@ jobs: - name: Test run: | echo ${{ matrix.container }} + + matrix-job-json-raw-format: + name: Run Matrix Job json raw format + runs-on: ubuntu-latest + needs: [changed-files] + strategy: + matrix: ${{ fromJSON(needs.changed-files.outputs.matrix-raw-format) }} + max-parallel: 4 + fail-fast: false + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Test + run: | + echo ${{ matrix.container }} From e7a159445a1865eab4492567ab29a135cefa9534 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 29 Dec 2022 22:02:12 -0700 Subject: [PATCH 8/9] Enable debugging --- 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 0dc49273fc6..35e507d04cb 100755 --- a/get-changed-paths.sh +++ b/get-changed-paths.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -euo pipefail +set -euxo pipefail INPUT_SEPARATOR="${INPUT_SEPARATOR//'%'/'%25'}" INPUT_SEPARATOR="${INPUT_SEPARATOR//'.'/'%2E'}" From 8be39b8230a7499f1161d98d0a641b3cfdf91024 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 29 Dec 2022 22:05:30 -0700 Subject: [PATCH 9/9] Remove debugging --- 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 35e507d04cb..0dc49273fc6 100755 --- a/get-changed-paths.sh +++ b/get-changed-paths.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -euxo pipefail +set -euo pipefail INPUT_SEPARATOR="${INPUT_SEPARATOR//'%'/'%25'}" INPUT_SEPARATOR="${INPUT_SEPARATOR//'.'/'%2E'}"