add raw-output option for json output (#900)
Co-authored-by: Tonye Jack <jtonye@ymail.com> Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
parent
232c8a3b69
commit
171fd357a8
30
.github/workflows/manual-matrix-test.yml
vendored
30
.github/workflows/manual-matrix-test.yml
vendored
@ -12,6 +12,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
matrix: ${{ steps.set-matrix.outputs.matrix }}
|
matrix: ${{ steps.set-matrix.outputs.matrix }}
|
||||||
|
matrix-raw-format: ${{ steps.set-matrix-json-raw-format.outputs.matrix }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
@ -23,11 +24,19 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
json: true
|
json: true
|
||||||
- name: List all changed files
|
- name: List all changed files
|
||||||
run: |
|
run: echo '${{ steps.changed-files.outputs.all_changed_files }}'
|
||||||
echo '${{ steps.changed-files.outputs.all_changed_files }}'
|
|
||||||
|
|
||||||
- id: set-matrix
|
- id: set-matrix
|
||||||
run: echo "matrix={\"container\":${{ steps.changed-files.outputs.all_changed_files }}}" >> "$GITHUB_OUTPUT"
|
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:
|
matrix-job:
|
||||||
name: Run Matrix Job
|
name: Run Matrix Job
|
||||||
@ -43,3 +52,18 @@ jobs:
|
|||||||
- name: Test
|
- name: Test
|
||||||
run: |
|
run: |
|
||||||
echo ${{ matrix.container }}
|
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 }}
|
||||||
|
12
.github/workflows/test.yml
vendored
12
.github/workflows/test.yml
vendored
@ -529,6 +529,18 @@ jobs:
|
|||||||
echo '${{ toJSON(steps.changed-files-json.outputs.all_changed_files) }}'
|
echo '${{ toJSON(steps.changed-files-json.outputs.all_changed_files) }}'
|
||||||
shell:
|
shell:
|
||||||
bash
|
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
|
- name: Run changed-files with comma separator
|
||||||
id: changed-files-comma
|
id: changed-files-comma
|
||||||
uses: ./
|
uses: ./
|
||||||
|
@ -79,6 +79,10 @@ inputs:
|
|||||||
description: "Output list of changed files in a JSON formatted string which can be used for matrix jobs."
|
description: "Output list of changed files in a JSON formatted string which can be used for matrix jobs."
|
||||||
required: false
|
required: false
|
||||||
default: "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:
|
fetch_depth:
|
||||||
description: "Depth of additional branch history fetched. **NOTE**: This can be adjusted to resolve errors with insufficient history."
|
description: "Depth of additional branch history fetched. **NOTE**: This can be adjusted to resolve errors with insufficient history."
|
||||||
required: false
|
required: false
|
||||||
@ -243,6 +247,7 @@ runs:
|
|||||||
INPUT_DIR_NAMES_MAX_DEPTH: ${{ inputs.dir_names_max_depth }}
|
INPUT_DIR_NAMES_MAX_DEPTH: ${{ inputs.dir_names_max_depth }}
|
||||||
INPUT_JSON: ${{ inputs.json }}
|
INPUT_JSON: ${{ inputs.json }}
|
||||||
INPUT_HAS_CUSTOM_PATTERNS: ${{ steps.glob.outputs.has-custom-patterns }}
|
INPUT_HAS_CUSTOM_PATTERNS: ${{ steps.glob.outputs.has-custom-patterns }}
|
||||||
|
INPUT_JSON_RAW_FORMAT: ${{ inputs.json_raw_format }}
|
||||||
- name: Generate output files
|
- name: Generate output files
|
||||||
uses: tj-actions/json2file@v1
|
uses: tj-actions/json2file@v1
|
||||||
if: inputs.write_output_files == 'true'
|
if: inputs.write_output_files == 'true'
|
||||||
|
@ -51,6 +51,16 @@ function get_dirname_max_depth() {
|
|||||||
done < <(uniq)
|
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() {
|
function get_diff() {
|
||||||
local base="$1"
|
local base="$1"
|
||||||
local sha="$2"
|
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}')
|
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
|
fi
|
||||||
else
|
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 /)
|
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}' | 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}' | 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}' | 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}' | 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}' | 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}' | 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}' | 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}' | 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}' | 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}' | 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}' | 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}' | 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}' | 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}' | 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}' | 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}' | 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}' | 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}' | 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}' | 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}' | json_output)
|
||||||
if [[ $INPUT_INCLUDE_ALL_OLD_NEW_RENAMED_FILES == "true" ]]; then
|
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
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@ -233,7 +243,7 @@ else
|
|||||||
if [[ "$INPUT_JSON" == "false" ]]; then
|
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}')
|
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
|
else
|
||||||
OTHER_CHANGED=$(echo "${OTHER_CHANGED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /)
|
OTHER_CHANGED=$(echo "${OTHER_CHANGED}" | json_output)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "${OTHER_CHANGED}" && "${OTHER_CHANGED}" != "[]" ]]; then
|
if [[ -n "${OTHER_CHANGED}" && "${OTHER_CHANGED}" != "[]" ]]; then
|
||||||
@ -285,7 +295,7 @@ else
|
|||||||
if [[ "$INPUT_JSON" == "false" ]]; then
|
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}')
|
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
|
else
|
||||||
OTHER_MODIFIED=$(echo "${OTHER_MODIFIED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /)
|
OTHER_MODIFIED=$(echo "${OTHER_MODIFIED}" | json_output)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "${OTHER_MODIFIED}" && "$OTHER_MODIFIED" != "[]" ]]; then
|
if [[ -n "${OTHER_MODIFIED}" && "$OTHER_MODIFIED" != "[]" ]]; then
|
||||||
@ -336,7 +346,7 @@ else
|
|||||||
if [[ "$INPUT_JSON" == "false" ]]; then
|
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}')
|
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
|
else
|
||||||
OTHER_DELETED=$(echo "${OTHER_DELETED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /)
|
OTHER_DELETED=$(echo "${OTHER_DELETED}" | json_output)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "${OTHER_DELETED}" && "${OTHER_DELETED}" != "[]" ]]; then
|
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_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}')
|
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
|
else
|
||||||
ADDED=$(echo "${ADDED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /)
|
ADDED=$(echo "${ADDED}" | json_output)
|
||||||
COPIED=$(echo "${COPIED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /)
|
COPIED=$(echo "${COPIED}" | json_output)
|
||||||
DELETED=$(echo "${DELETED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /)
|
DELETED=$(echo "${DELETED}" | json_output)
|
||||||
MODIFIED=$(echo "${MODIFIED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /)
|
MODIFIED=$(echo "${MODIFIED}" | json_output)
|
||||||
RENAMED=$(echo "${RENAMED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /)
|
RENAMED=$(echo "${RENAMED}" | json_output)
|
||||||
TYPE_CHANGED=$(echo "${TYPE_CHANGED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /)
|
TYPE_CHANGED=$(echo "${TYPE_CHANGED}" | json_output)
|
||||||
UNMERGED=$(echo "${UNMERGED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /)
|
UNMERGED=$(echo "${UNMERGED}" | json_output)
|
||||||
UNKNOWN=$(echo "${UNKNOWN}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /)
|
UNKNOWN=$(echo "${UNKNOWN}" | json_output)
|
||||||
ALL_CHANGED_AND_MODIFIED=$(echo "${ALL_CHANGED_AND_MODIFIED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /)
|
ALL_CHANGED_AND_MODIFIED=$(echo "${ALL_CHANGED_AND_MODIFIED}" | json_output)
|
||||||
ALL_CHANGED=$(echo "${ALL_CHANGED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /)
|
ALL_CHANGED=$(echo "${ALL_CHANGED}" | json_output)
|
||||||
ALL_MODIFIED=$(echo "${ALL_MODIFIED}" | jq -R 'split("|") | @json' | sed -r 's/^"|"$//g' | tr -s /)
|
ALL_MODIFIED=$(echo "${ALL_MODIFIED}" | json_output)
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user