Merge pull request #1 from dimoobraznii1986/feature/new-dbt-model #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run Pre-commit Hooks with Postgres | |
on: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
jobs: | |
pre-commit: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the code | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
# Set up Python environment | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.11 | |
# Install dependencies | |
- name: Install dependencies | |
run: | | |
python -m venv venv | |
. venv/bin/activate | |
pip install --upgrade pip | |
pip install -r requirements.txt | |
# Install dbt package dependencies | |
- name: Install dbt package dependencies | |
run: | | |
. venv/bin/activate | |
dbt deps | |
# Copy the profiles.yml file to the correct location | |
- name: Copy profiles.yml to /home/runner/.dbt | |
run: | | |
mkdir -p /home/runner/.dbt | |
cp ./profiles.yml /home/runner/.dbt/profiles.yml | |
# Compile the dbt project | |
- name: Compile dbt project | |
run: | | |
. venv/bin/activate | |
dbt compile | |
env: | |
DBT_USER: ${{ secrets.DBT_USER }} | |
DBT_PASSWORD: ${{ secrets.DBT_PASSWORD }} | |
DBT_HOST: ${{ secrets.DBT_HOST }} | |
DBT_DATABASE: ${{ secrets.DBT_DATABASE }} | |
# Run pre-commit hooks | |
- name: Run pre-commit on all changed files | |
run: | | |
. venv/bin/activate | |
files=$(git diff --name-only origin/main) | |
if [ -n "$files" ]; then | |
pre-commit run --files $files | |
else | |
echo "No modified files to check." | |
fi | |
dbt-build: | |
runs-on: ubuntu-latest | |
needs: pre-commit # Ensures dbt-build runs after pre-commit | |
steps: | |
# Checkout the code | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
# Set up Python environment | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.11 | |
# Install dependencies | |
- name: Install dependencies | |
run: | | |
python -m venv venv | |
. venv/bin/activate | |
pip install --upgrade pip | |
pip install -r requirements.txt | |
# Install dbt package dependencies | |
- name: Install dbt package dependencies | |
run: | | |
. venv/bin/activate | |
dbt deps | |
# Copy the profiles.yml file to the correct location | |
- name: Copy profiles.yml to /home/runner/.dbt | |
run: | | |
mkdir -p /home/runner/.dbt | |
cp ./profiles.yml /home/runner/.dbt/profiles.yml | |
# Run dbt build for CI target | |
- name: Run dbt build (CI) | |
run: | | |
. venv/bin/activate | |
dbt run --target ci | |
env: | |
DBT_USER: ${{ secrets.DBT_USER }} | |
DBT_PASSWORD: ${{ secrets.DBT_PASSWORD }} | |
DBT_HOST: ${{ secrets.DBT_HOST }} | |
DBT_DATABASE: ${{ secrets.DBT_DATABASE }} |