Skip to content

Commit

Permalink
Improve JSON checks
Browse files Browse the repository at this point in the history
Check formatting for all JSON files including the schema.

Improve check.sh with error details.

Fix big integer parsing in JQ by upgrading to Ubuntu 24.04:

 diff -u ./schema/landlockconfig.json <(jq < ./schema/landlockconfig.json)
 --- ./schema/landlockconfig.json
 +++ /dev/fd/63
 @@ -11,7 +11,7 @@
      "uint64": {
        "type": "integer",
        "minimum": 0,
 -      "maximum": 18446744073709551615
 +      "maximum": 18446744073709552000
      },
      "file": {
        "anyOf": [

See jqlang/jq#1752

Signed-off-by: Mickaël Salaün <mic@digikod.net>
  • Loading branch information
l0kod committed Feb 18, 2025
1 parent c4f21b4 commit 1be0096
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ jobs:
outputs:
commits: ${{ toJSON(steps.*.outputs.*) }}

ubuntu_22_schema:
runs-on: ubuntu-22.04
ubuntu_24_json:
runs-on: ubuntu-24.04
needs: commit_list
strategy:
fail-fast: false
Expand All @@ -60,7 +60,10 @@ jobs:
- name: Install check-jsonschema
run: pipx install check-jsonschema

- name: Check JSON schema
- name: Check schema format
run: diff -u ./schema/landlockconfig.json <(jq < ./schema/landlockconfig.json)

- name: Check JSON
run: ./schema/check.sh examples/mini-write-tmp.json

ubuntu_22_rust_msrv:
Expand Down
24 changes: 23 additions & 1 deletion schema/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,26 @@ set -u -e -o pipefail

BASE_DIR=$(dirname "${BASH_SOURCE[0]}")

check-jsonschema --schemafile "${BASE_DIR}/landlockconfig.json" "$@"
if [[ $# -eq 0 ]]; then
echo "ERROR: No files to check" >&2
exit 1
fi

for file in "$@"; do
if [[ ! -r "${file}" ]]; then
echo "ERROR: Invalid file: ${file}" >&2
exit 1
fi

diff -u "${file}" <(jq < "${file}") || {
echo
echo "ERROR: Invalid formatting" >&2
exit 1
}

check-jsonschema --schemafile "${BASE_DIR}/landlockconfig.json" "${file}" || {
echo
echo "ERROR: Not validated by schema: ${file}" >&2
exit 1
}
done

0 comments on commit 1be0096

Please # to comment.