Skip to content

feat: add regex in resource exceptions #2

feat: add regex in resource exceptions

feat: add regex in resource exceptions #2

name: Validate Exceptions JSON 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: Validte Exceptions JSON 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 \"with_entries(.value |= sort_by(.Namespace, .ResourceName))\" {} > {}.tmp && mv {}.tmp {}' \\;\`"
exit 1
fi