Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qa: Enforce JSON linter for GCT configs #1526

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/configs-json-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: might be able to use files=$(git ls-files '*.json') so we can conform everything and for future files and filter by config key word. But that seems like a pain. So only a suggestion.

here's the output:

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it was made to be extensible but this PR only targets our mainly touched configs for now

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


18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ DRIVER ?= psql
RACE_FLAG := $(if $(NO_RACE_TEST),,-race)
CONFIG_FLAG = $(if $(CONFIG),-config $(CONFIG),)

.PHONY: get linter check test build install update_deps
.PHONY: get linter check test build install update_deps lint_configs

all: check build

Expand Down Expand Up @@ -61,3 +61,19 @@ 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
@echo "Processing $(1)..."
@jq '.exchanges |= sort_by(.name)' --indent 1 $(1) > $(1).temp && \
(mv $(1).temp $(1)) || \
(rm $(1).temp; echo "jq processing failed on $(1)"; exit 1)
endef

check-jq:
@echo "Checking if jq is installed..."
@command -v jq >/dev/null 2>&1 || { echo >&2 "jq is not installed. Please install jq to proceed."; exit 1; }
Loading
Loading