Skip to content

test sort

test sort #12

name: Check Exceptions JSON Files Sorting
on:
pull_request:
branches:
- main
paths:
- 'pkg/kor/exceptions/**'
jobs:
sort_json:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Check Exceptions JSON Files Sorting
run: |
failed_files=$( \
find pkg/kor/exceptions -name '*.json' -exec sh -c '
SORTED=$(jq "with_entries(.value |= sort_by(.Namespace, .ResourceName))" "$1")
if [ "$(jq . "$1")" != "$SORTED" ]; then
echo "$1"
fi
' sh {} \; \
| tr '\n' '\n' \
)
if [ -n "$failed_files" ]; then
echo "The following JSON files are not sorted:"
echo "=================================================="
echo "$failed_files"
echo "=================================================="
echo "Run the following command to sort all files recursively:"
echo "\`find pkg/kor/exceptions -name '*.json' -exec sh -c 'jq \". |= sort_by(.Namespace, .ResourceName)\" {} > {}.tmp && mv {}.tmp {}' \\;\`"
exit 1
fi