diff --git a/.github/actions/lint-jsonschema/action.yml b/.github/actions/lint-jsonschema/action.yml new file mode 100644 index 00000000..22aa6698 --- /dev/null +++ b/.github/actions/lint-jsonschema/action.yml @@ -0,0 +1,52 @@ +name: Lint JSON Schema + +runs: + using: "composite" + steps: + - name: Set up check-jsonschema + shell: bash + run: | + pip install check-jsonschema + + - name: Set up environment + shell: bash + run: | + # Sadly, composite actions currently don't support environment variables so we freestyle a replacement + echo 'SCHEMAS_ROOT=src/schema' >> .gha-env + echo 'EXAMPLES_ROOT=src/schema/examples' >> .gha-env + + - name: Verify schemas + shell: bash + run: | + source .gha-env + + # We handle the return code ourselves to prevent the action from exiting on the first error + rc=0 + + while read -r file; do + echo "Validating $file" + if ! check-jsonschema --check-metaschema "$file"; then + rc=1 + fi + done < <(find "$SCHEMAS_ROOT" -name "*.json" -maxdepth 1) + + exit $rc + + - name: Verify examples + shell: bash + run: | + source .gha-env + + # We handle the return code ourselves to prevent the action from exiting on the first error + rc=0 + + while read -r file; do + schema=$(basename "$file") + schema=$SCHEMAS_ROOT/${schema%%.*}.json + echo "Validating $file against $schema" + if ! check-jsonschema --schemafile "$schema" "$file"; then + rc=1 + fi + done < <(find "$EXAMPLES_ROOT" -name "*.json") + + exit $rc diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index bdb9e2cc..89d7d0e6 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -29,6 +29,16 @@ jobs: - name: Lint uses: ./.github/actions/lint-drawio + jsonschema: + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Lint + uses: ./.github/actions/lint-jsonschema + plantuml: runs-on: ubuntu-latest diff --git a/src/schema/examples/permissionConfig.default-only.json b/src/schema/examples/permissionConfig.default-only.json new file mode 100644 index 00000000..63c26727 --- /dev/null +++ b/src/schema/examples/permissionConfig.default-only.json @@ -0,0 +1,3 @@ +{ + "defaultSetting": "allow all" +} diff --git a/src/schema/examples/permissionConfig.user-exception.json b/src/schema/examples/permissionConfig.user-exception.json new file mode 100644 index 00000000..4b8a9990 --- /dev/null +++ b/src/schema/examples/permissionConfig.user-exception.json @@ -0,0 +1,6 @@ +{ + "defaultSetting": "block all", + "userException": [{ + "mxid": "@david:hassel.hoff" + }] +}