From 89de6e336678514f91aa6034c6e3c53903671b89 Mon Sep 17 00:00:00 2001 From: Vinicius Date: Wed, 14 Feb 2024 17:27:10 -0300 Subject: [PATCH] feat: add dbt linter --- .github/workflows/ci-dbt.yaml | 23 ++++++++++++++++ .../{lint_docker.yaml => ci-docker.yaml} | 13 +++++----- .github/workflows/docs.yaml | 2 +- .github/workflows/metadata_automation.yaml | 2 +- .pre-commit-config.yaml | 26 +++++++++++++++++++ Makefile | 4 +++ ...ements-actions.txt => requirements-dev.txt | 4 ++- 7 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/ci-dbt.yaml rename .github/workflows/{lint_docker.yaml => ci-docker.yaml} (57%) create mode 100644 .pre-commit-config.yaml rename requirements-actions.txt => requirements-dev.txt (69%) diff --git a/.github/workflows/ci-dbt.yaml b/.github/workflows/ci-dbt.yaml new file mode 100644 index 00000000..f687ebd7 --- /dev/null +++ b/.github/workflows/ci-dbt.yaml @@ -0,0 +1,23 @@ +--- +name: CI dbt +on: + pull_request: + paths: ['**.sql', '**.yaml'] +jobs: + lint: + name: Lint dbt + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up python + uses: actions/setup-python@v4 + with: + cache: pip + python-version: '3.10' + - name: Install requirements + run: pip install -r requirements-dev.txt + - name: Lint sql + run: sqlfmt --diff . + - name: Lint yaml + run: yamlfix --exclude ".kubernetes/**/*" . diff --git a/.github/workflows/lint_docker.yaml b/.github/workflows/ci-docker.yaml similarity index 57% rename from .github/workflows/lint_docker.yaml rename to .github/workflows/ci-docker.yaml index 9db59bfb..2a7f1184 100644 --- a/.github/workflows/lint_docker.yaml +++ b/.github/workflows/ci-docker.yaml @@ -1,14 +1,15 @@ -name: Lint Dockerfile - +--- +name: CI Docker on: pull_request: - + paths: [Dockerfile] jobs: - docker_lint: - name: Lint Dockerfile + lint: + name: Lint dockerfile runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v4 - name: Run hadolint uses: reviewdog/action-hadolint@v1 with: diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index 9faef967..7182802b 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -33,7 +33,7 @@ jobs: - name: Install dependencies run: | - pip3 install -r requirements-actions.txt -r requirements.txt + pip3 install -r requirements-dev.txt -r requirements.txt - name: Setup credentials run: | diff --git a/.github/workflows/metadata_automation.yaml b/.github/workflows/metadata_automation.yaml index 9bc0287f..9a61ec0d 100644 --- a/.github/workflows/metadata_automation.yaml +++ b/.github/workflows/metadata_automation.yaml @@ -29,7 +29,7 @@ jobs: - name: Install Python dependencies for actions run: |- - pip install -r requirements-actions.txt + pip install -r requirements-dev.txt - name: Checkout to the head ref run: |- diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..c506c202 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,26 @@ +--- +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.2.0 + hooks: + - id: check-added-large-files + - id: check-merge-conflict + - id: detect-private-key + - id: end-of-file-fixer + - id: fix-byte-order-marker + - id: no-commit-to-branch + args: [-b, main] + - id: trailing-whitespace + - repo: https://github.com/tconbeer/sqlfmt + rev: v0.20.0 + hooks: + - id: sqlfmt + language_version: python + additional_dependencies: ['.[jinjafmt]'] + - repo: local + hooks: + - id: yamlfix + name: yamlfix + types: [yaml] + language: system + entry: yamlfix --exclude ".kubernetes/**/*" . diff --git a/Makefile b/Makefile index 27f5358f..10d3653b 100644 --- a/Makefile +++ b/Makefile @@ -21,3 +21,7 @@ logs: .PHONY: status status: docker-compose ps + +.PHONY: lint +lint: + pre-commit run --all-files diff --git a/requirements-actions.txt b/requirements-dev.txt similarity index 69% rename from requirements-actions.txt rename to requirements-dev.txt index 376f2892..c59e659b 100644 --- a/requirements-actions.txt +++ b/requirements-dev.txt @@ -4,6 +4,8 @@ pandas==1.4.2 requests==2.27.1 openpyxl==3.0.9 ruamel.yaml==0.17.21 -arcgis==1.9.1 markdown==3.3.6 jinja2==2.11.3 +pre-commit==3.6.1 +shandy-sqlfmt==0.20.0 +yamlfix==1.16.0