-
Notifications
You must be signed in to change notification settings - Fork 98
/
Makefile
62 lines (52 loc) · 1.97 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
EXCEPTIONS_DIR := pkg/kor/exceptions
EXCEPTIONS_FILE_PATTERN := *.json
.PHONY: *
build:
go build -o build/kor main.go
lint:
golangci-lint run
lint-fix:
golangci-lint run --fix
test:
go test -race -coverprofile=coverage.txt -shuffle on ./...
sort-exception-files:
@echo "Sorting exception files..."
@find $(EXCEPTIONS_DIR) -name '$(EXCEPTIONS_FILE_PATTERN)' | xargs -I{} -P 4 sh -c ' \
jq "with_entries(.value |= sort_by(.Namespace, .ResourceName))" {} > {}.tmp && mv {}.tmp {} \
' \;
validate-exception-sorting:
@PRINT_ERR=1; \
for file in $(wildcard $(EXCEPTIONS_DIR)/*/$(EXCEPTIONS_FILE_PATTERN)); do \
SORTED=$$(jq "with_entries(.value |= sort_by(.Namespace, .ResourceName))" "$$file"); \
CURRENT_FILE=$$(jq . "$$file"); \
if [ "$$CURRENT_FILE" != "$$SORTED" ]; then \
if [ "$$PRINT_ERR" = 1 ]; then \
echo "The following JSON files are not sorted:"; \
PRINT_ERR=0; \
fi; \
echo "\t$$file"; \
fi; \
done; \
if [ "$$PRINT_ERR" = 0 ]; then \
echo "Run the following command to sort all files recursively: make sort-exception-files"; \
fi; \
dedup-exception-files:
@echo "Deduplicating exception files..."
@find $(EXCEPTIONS_DIR) -type f -name '$(EXCEPTIONS_FILE_PATTERN)' | xargs -I{} -P 4 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; \