Skip to content

Commit

Permalink
qa: Enforce JSON lint for GCT configs
Browse files Browse the repository at this point in the history
  • Loading branch information
thrasher- committed Apr 26, 2024
1 parent 44d50a3 commit c4fcfba
Show file tree
Hide file tree
Showing 4 changed files with 2,923 additions and 2,883 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/json_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: config-json-lint
on: [push, pull_request]

jobs:
lint:
name: JSON format check
runs-on: ubuntu-latest
strategy:
matrix:
file: ["config_example.json", "testdata/configtest.json"]
steps:
- uses: actions/checkout@v4

- name: Install jq
run: sudo apt-get install jq

- name: Check JSON format for ${{ matrix.file }}
run: |
jq '.exchanges |= sort_by(.name)' --indent 1 ${{ matrix.file }} > processed_${{ matrix.file }}
if ! diff ${{ matrix.file }} processed_${{ matrix.file }}; then
echo "Differences found in ${{ matrix.file }}! Please run 'make lint_configs'"
exit 1
fi
19 changes: 18 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,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)

# Function to sort JSON and replace the original file safely
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

0 comments on commit c4fcfba

Please sign in to comment.