From 1be0096ec2488ffef9b42d53fa023530cac198cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= Date: Sun, 16 Feb 2025 13:29:14 +0100 Subject: [PATCH] Improve JSON checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 https://github.com/jqlang/jq/pull/1752 Signed-off-by: Mickaël Salaün --- .github/workflows/ci.yml | 9 ++++++--- schema/check.sh | 24 +++++++++++++++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index da548d9..494e15b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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: diff --git a/schema/check.sh b/schema/check.sh index 7ba7fad..79e6bf6 100755 --- a/schema/check.sh +++ b/schema/check.sh @@ -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