Skip to content

Commit

Permalink
Merge pull request #238 from gematik/johannes/lint-jsonschema
Browse files Browse the repository at this point in the history
Add JSON schema validation into linting workflow
  • Loading branch information
Johennes authored May 28, 2024
2 parents c37ed9f + 0398c3b commit 5e3ce7d
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/actions/lint-jsonschema/action.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions src/schema/examples/permissionConfig.default-only.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"defaultSetting": "allow all"
}
6 changes: 6 additions & 0 deletions src/schema/examples/permissionConfig.user-exception.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"defaultSetting": "block all",
"userException": [{
"mxid": "@david:hassel.hoff"
}]
}

0 comments on commit 5e3ce7d

Please sign in to comment.