From b6b129ae1b2d975d362fde08c70f2c2f53b10df9 Mon Sep 17 00:00:00 2001 From: dweinholz Date: Thu, 21 Sep 2023 13:26:32 +0200 Subject: [PATCH] added validation method --- .github/workflows/validate_database_json.yml | 4 +-- .github/workflows/validate_databases_json.yml | 36 +++++++++++++++++++ ...tabase_schema.json => database_schema.json | 0 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/validate_databases_json.yml rename databases/database_schema.json => database_schema.json (100%) diff --git a/.github/workflows/validate_database_json.yml b/.github/workflows/validate_database_json.yml index 638d173..21818f3 100644 --- a/.github/workflows/validate_database_json.yml +++ b/.github/workflows/validate_database_json.yml @@ -34,9 +34,9 @@ jobs: - name: Validate JSON run: | FILENAME="./fts3-databases/${{ inputs.FILENAME || github.event.inputs.FILENAME }}" - SCHEMA="./fts3-databases/databases/database_schema.json" + SCHEMA="./fts3-databases/database_schema.json" - if npx ajv validate --spec=draft2020 -s "$SCHEMA" -d "$FILENAME"; then + if npx ajv validate --spec=draft2020 --errors=text -s "$SCHEMA" -d "$FILENAME"; then echo "JSON is valid." else echo "JSON is invalid." diff --git a/.github/workflows/validate_databases_json.yml b/.github/workflows/validate_databases_json.yml new file mode 100644 index 0000000..aff2171 --- /dev/null +++ b/.github/workflows/validate_databases_json.yml @@ -0,0 +1,36 @@ +name: Validate JSON + +on: + workflow_call: + + workflow_dispatch: + +jobs: + validate-json: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + path: fts3-databases + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' # Use the Node.js version you prefer + + - name: Install dependencies + run: npm install ajv-cli + + - name: Validate JSON + run: | + FILENAME="./fts3-databases/*.json" + SCHEMA="./fts3-databases/database_schema.json" + + if npx ajv validate --spec=draft2020 --errors=text -s "$SCHEMA" -d "$FILENAME"; then + echo "JSON is valid." + else + echo "JSON is invalid." + exit 1 + fi + diff --git a/databases/database_schema.json b/database_schema.json similarity index 100% rename from databases/database_schema.json rename to database_schema.json