diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3865b3e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,29 @@ +name: CI + +on: pull_request + +jobs: + validate-json-schemas: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 + - name: install avj + run: npm install --no-save ajv-cli@5.0.0 + - name: validate all schema files + run: find ./schemas -name "*.json" | xargs -n 1 -I {} npx ajv-cli compile -s {} --strict=false + test-against-sample-dbt-files: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 + - name: install avj + run: npm install --no-save ajv-cli@5.0.0 + - name: validate dbt_project.yml sample file + run: npx ajv-cli validate -s schemas/dbt_project.json -d tests/dbt_project.yml + - name: validate sample model YAML file + run: npx ajv-cli validate -s schemas/dbt_yml_files.json -d tests/schema.yml diff --git a/.gitignore b/.gitignore index 9bea433..4f49075 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store +node_modules/ diff --git a/.vscode/settings.json b/.vscode/settings.json index 6b77993..e34afb5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,7 +6,8 @@ "!dbt_project.yml", "!packages.yml", "!selectors.yml", - "!profile_template.yml" + "!profile_template.yml", + "!/.github/**/*.yml" ], "./schemas/dbt_project.json": [ "dbt_project.yml" @@ -34,4 +35,4 @@ "additionalProperties", "$defs" ] -} \ No newline at end of file +} diff --git a/schemas/dbt_project.json b/schemas/dbt_project.json index d9a8bbc..5ae2fd7 100644 --- a/schemas/dbt_project.json +++ b/schemas/dbt_project.json @@ -1,5 +1,6 @@ { "title": "dbt_project", + "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "required": [ "name", @@ -131,7 +132,7 @@ "oneOf": [ { "type": "string", - "pattern": "{{.*}}" + "pattern": "\\{\\{.*\\}\\}" }, { "type": "boolean" @@ -299,4 +300,4 @@ } } } -} \ No newline at end of file +} diff --git a/schemas/dbt_yml_files.json b/schemas/dbt_yml_files.json index f35f6b4..e52b9ab 100644 --- a/schemas/dbt_yml_files.json +++ b/schemas/dbt_yml_files.json @@ -1,5 +1,6 @@ { "title": "dbt_yml_files", + "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "required": [ "version" @@ -531,7 +532,9 @@ }, "column_properties": { "type": "object", - "required": "name", + "required": [ + "name" + ], "properties": { "name": { "type": "string" @@ -615,7 +618,7 @@ }, "jinja_string": { "type": "string", - "pattern": "{{.*}}" + "pattern": "\\{\\{.*\\}\\}" }, "number_or_jinja_string": { "oneOf": [ diff --git a/schemas/packages.json b/schemas/packages.json index 90177ff..86cc8a9 100644 --- a/schemas/packages.json +++ b/schemas/packages.json @@ -1,5 +1,6 @@ { "title": "packages", + "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "required": [ "packages" @@ -80,4 +81,4 @@ } }, "additionalProperties": false -} \ No newline at end of file +} diff --git a/schemas/selectors.json b/schemas/selectors.json index 8f12d50..6426256 100644 --- a/schemas/selectors.json +++ b/schemas/selectors.json @@ -1,5 +1,6 @@ { "title": "selectors", + "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "required": [ "selectors" @@ -20,7 +21,7 @@ "oneOf": [ { "type": "string", - "pattern": "{{.*}}" + "pattern": "\\{\\{.*\\}\\}" }, { "type": "boolean" @@ -48,4 +49,4 @@ } }, "additionalProperties": false -} \ No newline at end of file +} diff --git a/tests/dbt_project.yml b/tests/dbt_project.yml new file mode 100644 index 0000000..e5738fe --- /dev/null +++ b/tests/dbt_project.yml @@ -0,0 +1,39 @@ +# this file was generated with dbt init with dbt 1.2.1 + +# Name your project! Project names should contain only lowercase characters +# and underscores. A good package name should reflect your organization's +# name or the intended use of these models +name: 'test' +version: '1.0.0' +config-version: 2 + +# This setting configures which "profile" dbt uses for this project. +profile: 'test' + +# These configurations specify where dbt should look for different types of files. +# The `model-paths` config, for example, states that models in this project can be +# found in the "models/" directory. You probably won't need to change these! +model-paths: ["models"] +analysis-paths: ["analyses"] +test-paths: ["tests"] +seed-paths: ["seeds"] +macro-paths: ["macros"] +snapshot-paths: ["snapshots"] + +target-path: "target" # directory which will store compiled SQL files +clean-targets: # directories to be removed by `dbt clean` + - "target" + - "dbt_packages" + + +# Configuring models +# Full documentation: https://docs.getdbt.com/docs/configuring-models + +# In this example config, we tell dbt to build all models in the example/ directory +# as tables. These settings can be overridden in the individual model files +# using the `{{ config(...) }}` macro. +models: + test: + # Config indicated by + and applies to all files under models/example/ + example: + +materialized: view diff --git a/tests/schema.yml b/tests/schema.yml new file mode 100644 index 0000000..aeb5214 --- /dev/null +++ b/tests/schema.yml @@ -0,0 +1,22 @@ +# this file was generated with dbt init with dbt 1.2.1 + +version: 2 + +models: + - name: my_first_dbt_model + description: "A starter dbt model" + columns: + - name: id + description: "The primary key for this table" + tests: + - unique + - not_null + + - name: my_second_dbt_model + description: "A starter dbt model" + columns: + - name: id + description: "The primary key for this table" + tests: + - unique + - not_null