Skip to content

Add infrastructure for validating JSON schemas #2073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions .github/workflows/check-schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Check JSON Schema

env:
# See: https://github.com/actions/setup-node/#readme
NODE_VERSION: 16.x

# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
on:
create:
push:
paths:
- ".github/workflows/check-schema.ya?ml"
- "package.json"
- "package-lock.json"
- "configuration/configuration.schema.json"
pull_request:
paths:
- ".github/workflows/check-schema.ya?ml"
- "package.json"
- "package-lock.json"
- "configuration/configuration.schema.json"
schedule:
# Run weekly to catch breakage from external changes.
- cron: "0 13 * * WED"
workflow_dispatch:
repository_dispatch:

permissions: {}

jobs:
run-determination:
runs-on: ubuntu-latest
outputs:
result: ${{ steps.determination.outputs.result }}
steps:
- name: Determine if the rest of the workflow should run
id: determination
run: |
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
if [[
"${{ github.event_name }}" != "create" ||
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
]]; then
# Run the other jobs.
RESULT="true"
else
# There is no need to run the other jobs.
RESULT="false"
fi

echo "result=$RESULT" >> $GITHUB_OUTPUT

validate:
name: Validate ${{ matrix.path }}
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
# Paths of the schemas to validate.
path:
- ./configuration/configuration.schema.json

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Validate JSON schema
env:
SCHEMA_PATH: ${{ matrix.path }}
run: task --silent schema:validate
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ venv
.pytest_cache
/dist
/.pytest-tmp-dir
/node_modules/

# gRPC client example folder
/client_example/client_example
Expand Down
22 changes: 22 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ tasks:
cmds:
- npx markdownlint-cli "**/*.md"

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
npm:install-deps:
desc: Install dependencies managed by npm
cmds:
- npm install

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml
poetry:install-deps:
desc: Install dependencies managed by Poetry
Expand Down Expand Up @@ -240,6 +246,22 @@ tasks:
deps:
- task: go:build

schema:validate:
desc: Validate JSON schema
deps:
- task: npm:install-deps
cmds:
- |
if [[ "{{.SCHEMA_PATH}}" == "" ]]; then
echo "Path to a JSON schema must be specified via the SCHEMA_PATH environment variable."
exit 1
fi
- |
npx \
ajv-cli \
compile \
-s "{{.SCHEMA_PATH}}"

test:
desc: Run the full testsuite, `legacy` will be skipped
cmds:
Expand Down
Loading