Skip to content
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

Fix model validation, add CI #16

Merged
merged 14 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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 --spec=draft7
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

.DS_Store
node_modules/
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -34,4 +35,4 @@
"additionalProperties",
"$defs"
]
}
}
4 changes: 2 additions & 2 deletions schemas/dbt_project.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"oneOf": [
{
"type": "string",
"pattern": "{{.*}}"
"pattern": "\\{\\{.*\\}\\}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
{
"type": "boolean"
Expand Down Expand Up @@ -299,4 +299,4 @@
}
}
}
}
}
6 changes: 4 additions & 2 deletions schemas/dbt_yml_files.json
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,9 @@
},
"column_properties": {
"type": "object",
"required": "name",
"required": [
"name"
],
"properties": {
"name": {
"type": "string"
Expand Down Expand Up @@ -615,7 +617,7 @@
},
"jinja_string": {
"type": "string",
"pattern": "{{.*}}"
"pattern": "\\{\\{.*\\}\\}"
},
"number_or_jinja_string": {
"oneOf": [
Expand Down
4 changes: 2 additions & 2 deletions schemas/selectors.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"oneOf": [
{
"type": "string",
"pattern": "{{.*}}"
"pattern": "\\{\\{.*\\}\\}"
},
{
"type": "boolean"
Expand Down Expand Up @@ -48,4 +48,4 @@
}
},
"additionalProperties": false
}
}
39 changes: 39 additions & 0 deletions tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# this file was generated with dbt init with DBT 1.2.1
kochalex marked this conversation as resolved.
Show resolved Hide resolved

# 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
22 changes: 22 additions & 0 deletions tests/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# this file was generated with dbt init with DBT 1.2.1
kochalex marked this conversation as resolved.
Show resolved Hide resolved

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