Skip to content

Commit

Permalink
feat: Add exception dedup workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
doronkg committed Jul 24, 2024
1 parent 01ce4a6 commit 3b93157
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 20 deletions.
19 changes: 0 additions & 19 deletions .github/workflows/exceptions-json-sort.yml

This file was deleted.

22 changes: 22 additions & 0 deletions .github/workflows/validate-exception-jsons.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Validate Exception JSONs

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: Validate Exception JSON Sorting
run: make validate-exception-sorting

- name: Validate Exception Deduplication
run: make validate-exception-duplications
25 changes: 24 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,27 @@ validate-exception-sorting:
done; \
if [ "$$PRINT_ERR" = 0 ]; then \
echo "Run the following command to sort all files recursively: make sort-exception-files"; \
fi; \
fi; \

dedup-exception-files:
@echo "Deduplicating exception files..."
@find $(EXCEPTIONS_DIR) -type f -name '$(EXCEPTIONS_FILE_PATTERN)' -exec sh -c ' \
jq '\''keys[0] as $$key | { ($$key): (.[$$key] | group_by(.Namespace, .ResourceName) | map(.[0])) }'\'' "$$1" > "$$1.tmp" && mv "$$1.tmp" "$$1" \
' sh {} \;


validate-exception-duplications:
@PRINT_ERR=1; \
for file in $(wildcard $(EXCEPTIONS_DIR)/*/$(EXCEPTIONS_FILE_PATTERN)); do \
DUPLICATES=$$(jq 'keys[0] as $$key | .[$$key] | group_by(.Namespace, .ResourceName) | map(select(length > 1))' "$$file"); \
if [ "$$DUPLICATES" != "[]" ]; then \
if [ "$$PRINT_ERR" = 1 ]; then \
echo "The following JSON files contain duplications:"; \
PRINT_ERR=0; \
fi; \
echo "\t$$file"; \
fi; \
done; \
if [ "$$PRINT_ERR" = 0 ]; then \
echo "Run the following command to deduplicate all files recursively: make dedup-exception-files"; \
fi; \

0 comments on commit 3b93157

Please sign in to comment.