Skip to content

Commit

Permalink
qa: Enforce JSON standard for GCT configs (#1526)
Browse files Browse the repository at this point in the history
* qa: Enforce JSON lint for GCT configs

* Makefile/GHA: Make output more verbose on success, clean duplicate PHONY and rid excess newlines

* Makefile: Use printf for OS cross-compatibility output
  • Loading branch information
thrasher- authored Apr 30, 2024
1 parent b46b793 commit 1e95ae9
Show file tree
Hide file tree
Showing 4 changed files with 2,923 additions and 2,882 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/configs-json-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: configs-json-lint
on: [push, pull_request]

jobs:
lint:
name: configs JSON lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Check configs JSON format
run: |
files=("config_example.json" "testdata/configtest.json")
for file in "${files[@]}"; do
processed_file="${file%.*}_processed.${file##*.}"
jq '.exchanges |= sort_by(.name)' --indent 1 $file > $processed_file
if ! diff $file $processed_file; then
echo "jq differences found in $file! Please run 'make lint_configs'"
exit 1
else
rm $processed_file
echo "No differences found in $file 🌞"
fi
done
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,20 @@ endif
target/sqlboiler.json:
mkdir -p $(@D)
go run ./cmd/gen_sqlboiler_config/main.go $(CONFIG_FLAG) -outdir $(@D)

.PHONY: lint_configs
lint_configs: check-jq
@$(call sort-json,config_example.json)
@$(call sort-json,testdata/configtest.json)

define sort-json
@printf "Processing $(1)... "
@jq '.exchanges |= sort_by(.name)' --indent 1 $(1) > $(1).temp && \
(mv $(1).temp $(1) && printf "OK\n") || \
(rm $(1).temp; printf "FAILED\n"; exit 1)
endef

.PHONY: check-jq
check-jq:
@printf "Checking if jq is installed... "
@command -v jq >/dev/null 2>&1 && { printf "OK\n"; } || { printf "FAILED. Please install jq to proceed.\n"; exit 1; }
Loading

0 comments on commit 1e95ae9

Please sign in to comment.