179 lines
4.6 KiB
YAML
179 lines
4.6 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
# Lint
|
|
lint-python:
|
|
name: Ruff (lint + format)
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v5
|
|
|
|
- name: Install uv
|
|
uses: astral-sh/setup-uv@v7
|
|
with:
|
|
enable-cache: true
|
|
|
|
- name: Install dependencies
|
|
run: uv sync
|
|
|
|
- name: Ruff lint
|
|
run: uv run ruff check .
|
|
|
|
- name: Ruff format check
|
|
run: uv run ruff format --check .
|
|
|
|
lint-sql:
|
|
name: SQLFluff
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v5
|
|
|
|
- name: Install uv
|
|
uses: astral-sh/setup-uv@v7
|
|
with:
|
|
enable-cache: true
|
|
|
|
- name: Install dependencies
|
|
run: uv sync
|
|
|
|
- name: SQLFluff lint
|
|
run: uv run sqlfluff lint dbt/models data_platform/ --dialect postgres
|
|
|
|
lint-yaml-json-md:
|
|
name: Prettier (YAML / JSON / Markdown)
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v5
|
|
|
|
- name: Setup Node
|
|
uses: actions/setup-node@v5
|
|
with:
|
|
node-version: "22"
|
|
|
|
- name: Install prettier
|
|
run: npm install --global prettier
|
|
|
|
- name: Prettier check
|
|
run: |
|
|
prettier --check \
|
|
"**/*.yml" "**/*.yaml" "**/*.md" \
|
|
--ignore-path .prettierignore
|
|
|
|
# dbt validation
|
|
validate-dbt:
|
|
name: dbt parse
|
|
needs: [lint-python, lint-sql, lint-yaml-json-md]
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v5
|
|
|
|
- name: Install uv
|
|
uses: astral-sh/setup-uv@v7
|
|
with:
|
|
enable-cache: true
|
|
|
|
- name: Install dependencies
|
|
run: uv sync
|
|
|
|
- name: Load environment from .env.example
|
|
run: grep -v '^#' .env.example | grep -v '^$' >> "$GITHUB_ENV"
|
|
|
|
- name: Install dbt packages
|
|
run: uv run dbt deps --project-dir dbt --profiles-dir dbt
|
|
|
|
- name: Validate dbt project
|
|
run: uv run dbt parse --project-dir dbt --profiles-dir dbt
|
|
|
|
# Dagster validation
|
|
validate-dagster:
|
|
name: Dagster definitions
|
|
needs: validate-dbt
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v5
|
|
|
|
- name: Install uv
|
|
uses: astral-sh/setup-uv@v7
|
|
with:
|
|
enable-cache: true
|
|
|
|
- name: Install dependencies
|
|
run: uv sync
|
|
|
|
- name: Load environment from .env.example
|
|
run: grep -v '^#' .env.example | grep -v '^$' >> "$GITHUB_ENV"
|
|
|
|
- name: Install dbt packages
|
|
run: uv run dbt deps --project-dir dbt --profiles-dir dbt
|
|
|
|
- name: Generate dbt manifest
|
|
run: uv run dbt parse --project-dir dbt --profiles-dir dbt
|
|
|
|
- name: Validate Dagster definitions
|
|
run: uv run dagster definitions validate
|
|
|
|
# Tests
|
|
test:
|
|
name: Pytest
|
|
needs: [validate-dbt, validate-dagster]
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v5
|
|
|
|
- name: Install uv
|
|
uses: astral-sh/setup-uv@v7
|
|
with:
|
|
enable-cache: true
|
|
|
|
- name: Install dependencies
|
|
run: uv sync
|
|
|
|
- name: Load environment from .env.example
|
|
run: grep -v '^#' .env.example | grep -v '^$' >> "$GITHUB_ENV"
|
|
|
|
- name: Install dbt packages
|
|
run: uv run dbt deps --project-dir dbt --profiles-dir dbt
|
|
|
|
- name: Generate dbt manifest
|
|
run: uv run dbt parse --project-dir dbt --profiles-dir dbt
|
|
|
|
- name: Run tests with coverage
|
|
run: uv run pytest tests/ --cov=data_platform --cov-report=json:coverage.json
|
|
|
|
- name: Round coverage percentage
|
|
if: github.ref == 'refs/heads/main'
|
|
run: |
|
|
python -c "
|
|
import json
|
|
with open('coverage.json') as f:
|
|
data = json.load(f)
|
|
data['totals']['percent_covered'] = round(data['totals']['percent_covered'])
|
|
with open('coverage.json', 'w') as f:
|
|
json.dump(data, f)
|
|
"
|
|
|
|
- name: Generate coverage badge
|
|
if: github.ref == 'refs/heads/main'
|
|
run: |
|
|
npx --yes coverage-badges-cli \
|
|
--source coverage.json \
|
|
--output badge/coverage-badge.svg \
|
|
--jsonPath totals.percent_covered
|
|
|
|
- name: Deploy coverage badge
|
|
if: github.ref == 'refs/heads/main'
|
|
run: |
|
|
cd badge
|
|
git init -b coverage-badge
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
git add .
|
|
git commit -m "Update coverage badge"
|
|
git push --force "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" coverage-badge
|