Bump dbt-snowflake from 1.5.1 to 1.6.0 #15
Workflow file for this run
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: CD clean up and deploy to production | |
concurrency: dbt-deploy | |
on: | |
pull_request: | |
types: | |
- closed | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
env: | |
DEBUG: true | |
DBT_PROFILE_NAME: ${{ vars.DBT_PROFILE_NAME }} | |
DBT_SNOWFLAKE_ACCOUNT: ${{ secrets.DBT_SNOWFLAKE_ACCOUNT }} | |
DBT_SNOWFLAKE_USER: ${{ vars.DBT_SNOWFLAKE_USER }} | |
DBT_SNOWFLAKE_ROLE: ${{ vars.DBT_SNOWFLAKE_ROLE }} | |
DBT_SNOWFLAKE_PASSWORD: ${{ secrets.DBT_SNOWFLAKE_PASSWORD }} | |
DBT_SNOWFLAKE_DATABASE: ${{ vars.DBT_SNOWFLAKE_DATABASE }} | |
DBT_SNOWFLAKE_WAREHOUSE: ${{ vars.DBT_SNOWFLAKE_WAREHOUSE }} | |
DBT_SNOWFLAKE_PRODUCTION_SCHEMA: ${{ vars.DBT_SNOWFLAKE_PRODUCTION_SCHEMA }} | |
DBT_SNOWFLAKE_THREADS: ${{ vars.DBT_SNOWFLAKE_THREADS }} | |
PR_NUMBER: ${{ github.event.pull_request.number }} | |
BRANCH_NAME: ${{ github.head_ref }} | |
DBT_PROJECT_FOLDER: ${{ vars.DBT_PROJECT_FOLDER }} | |
jobs: | |
delete_branch: | |
name: Delete PR branch from Snowflake | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Create profiles.yml | |
run: | | |
mkdir -p /home/$(whoami)/.dbt/ | |
echo "${DBT_PROFILE_NAME}:" > /home/$(whoami)/.dbt/profiles.yml | |
echo " target: development" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " outputs:" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " development:" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " type: snowflake" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " account: ${DBT_SNOWFLAKE_ACCOUNT}" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " user: ${DBT_SNOWFLAKE_USER}" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " role: ${DBT_SNOWFLAKE_ROLE}" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " password: ${DBT_SNOWFLAKE_PASSWORD}" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " database: ${DBT_SNOWFLAKE_DATABASE}" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " warehouse: ${DBT_SNOWFLAKE_WAREHOUSE}" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " schema: pr" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " threads: ${DBT_SNOWFLAKE_THREADS}" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " client_session_keep_alive: false" >> /home/$(whoami)/.dbt/profiles.yml | |
- name: Print profiles.yml | |
if: ${{ env.DEBUG == 'true' }} | |
run: | | |
echo "----------------------------------------" | |
echo "Debug mode: Show content of profiles.yml" | |
echo "Note that secrets will be masked" | |
echo "----------------------------------------" | |
cat /home/$(whoami)/.dbt/profiles.yml | |
- name: Read Python version from .python-version | |
run: echo "python_version=$(cat .python-version)" >> "$GITHUB_ENV" | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ env.python_version }} | |
- name: Cache pip dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install dbt | |
run: | | |
python -m pip install --upgrade pip | |
grep dbt-snowflake requirements.txt | xargs -n 1 pip install | |
- name: Run dbt deps | |
run: | | |
cd $DBT_PROJECT_FOLDER | |
dbt deps | |
- name: Run dbt debug | |
if: ${{ env.DEBUG == 'true' }} | |
run: | | |
cd $DBT_PROJECT_FOLDER | |
echo "----------------------------------------" | |
echo "Debug mode: Execute dbt debug" | |
echo "----------------------------------------" | |
dbt debug | |
- name: Drop schema | |
# the "|| true" is to prevent the job from failing if the schema does not exist | |
run: | | |
cd $DBT_PROJECT_FOLDER | |
BRANCH_NAME=$(echo "${BRANCH_NAME}" | tr '-' '_') | |
schema_name="pr_${BRANCH_NAME##*/}_${PR_NUMBER}" | |
dbt run-operation drop_schema --args "{'schema_name': '${schema_name}'}" || true | |
deploy_to_production: | |
name: Deploy to production | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Create profiles.yml | |
run: | | |
mkdir -p /home/$(whoami)/.dbt/ | |
echo "${DBT_PROFILE_NAME}:" > /home/$(whoami)/.dbt/profiles.yml | |
echo " target: development" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " outputs:" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " development:" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " type: snowflake" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " account: ${DBT_SNOWFLAKE_ACCOUNT}" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " user: ${DBT_SNOWFLAKE_USER}" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " role: ${DBT_SNOWFLAKE_ROLE}" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " password: ${DBT_SNOWFLAKE_PASSWORD}" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " database: ${DBT_SNOWFLAKE_DATABASE}" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " warehouse: ${DBT_SNOWFLAKE_WAREHOUSE}" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " schema: ${DBT_SNOWFLAKE_PRODUCTION_SCHEMA}" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " threads: ${DBT_SNOWFLAKE_THREADS}" >> /home/$(whoami)/.dbt/profiles.yml | |
echo " client_session_keep_alive: false" >> /home/$(whoami)/.dbt/profiles.yml | |
- name: Print profiles.yml | |
if: ${{ env.DEBUG == 'true' }} | |
run: | | |
echo "----------------------------------------" | |
echo "Debug mode: Show content of profiles.yml" | |
echo "Note that secrets will be masked" | |
echo "----------------------------------------" | |
cat /home/$(whoami)/.dbt/profiles.yml | |
- name: Read Python version from .python-version | |
run: echo "python_version=$(cat .python-version)" >> "$GITHUB_ENV" | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ env.python_version }} | |
- name: Cache pip dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install dbt | |
run: | | |
python -m pip install --upgrade pip | |
grep dbt-snowflake requirements.txt | xargs -n 1 pip install | |
- name: Run dbt deps | |
run: | | |
cd $DBT_PROJECT_FOLDER | |
dbt deps | |
- name: Run dbt debug | |
if: ${{ env.DEBUG == 'true' }} | |
run: | | |
cd $DBT_PROJECT_FOLDER | |
echo "----------------------------------------" | |
echo "Debug mode: Execute dbt debug" | |
echo "----------------------------------------" | |
dbt debug | |
- name: Deploy models to production schema | |
run: | | |
cd $DBT_PROJECT_FOLDER | |
dbt build | |
- name: Generate docs | |
run: | | |
cd $DBT_PROJECT_FOLDER | |
dbt docs generate | |
- name: Upload pages artifact | |
uses: actions/upload-pages-artifact@v1 | |
with: | |
path: ${{ env.DBT_PROJECT_FOLDER }}/target | |
deploy-pages: | |
name: Deployment docs to pages | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
needs: deploy_to_production | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v2 |