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 }} 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: ./ diff --git a/README.md b/README.md index 4c0669c49c1..f8d93d19b04 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: @@ -227,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 @@ -472,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 @@ -499,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 23e0f27d22f..4f3d923c484 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 @@ -243,6 +247,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 }} + 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 7deb9abdb3d..0dc49273fc6 100755 --- a/get-changed-paths.sh +++ b/get-changed-paths.sh @@ -51,6 +51,16 @@ function get_dirname_max_depth() { done < <(uniq) } +function json_output() { + JQ_ARGS="-R" + if [[ "$INPUT_JSON_RAW_FORMAT" == "true" ]]; then + JQ_ARGS="$JQ_ARGS -r" + fi + + # shellcheck disable=SC2086 + jq $JQ_ARGS 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s / +} + function get_diff() { local base="$1" local sha="$2" @@ -172,19 +182,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}' | 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 -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}' | json_output) fi fi else @@ -233,7 +243,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}" | json_output) fi if [[ -n "${OTHER_CHANGED}" && "${OTHER_CHANGED}" != "[]" ]]; then @@ -285,7 +295,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}" | json_output) fi if [[ -n "${OTHER_MODIFIED}" && "$OTHER_MODIFIED" != "[]" ]]; then @@ -336,7 +346,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}" | json_output) fi if [[ -n "${OTHER_DELETED}" && "${OTHER_DELETED}" != "[]" ]]; then @@ -368,17 +378,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}" | 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 @@ -435,4 +445,4 @@ if [[ $INPUT_INCLUDE_ALL_OLD_NEW_RENAMED_FILES == "true" ]]; then fi fi -echo "::endgroup::" +echo "::endgroup::" \ No newline at end of file