Skip to content

Commit

Permalink
Add back snowflake auth
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangs committed May 1, 2024
1 parent ec22818 commit 9bb084b
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 88 deletions.
209 changes: 121 additions & 88 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
@@ -1,115 +1,149 @@
name: Test sdf-action

on:
pull_request:
push:
branches:
- harry/add_back_snowflake_auth

jobs:
tpch_redshift:
runs-on: ubuntu-latest
name: Redshift workspace
steps:
- name: Checkout
uses: actions/checkout@v4
- name: sdf compile step
uses: ./ # Uses an action in the root directory
id: sdf
with:
command: 'sdf compile --show all'
workspace_dir: 'workspace/tpch_redshift'
# tpch_redshift:
# runs-on: ubuntu-latest
# name: Redshift workspace
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# - name: sdf compile step
# uses: ./ # Uses an action in the root directory
# id: sdf
# with:
# command: 'sdf compile --show all'
# workspace_dir: 'workspace/tpch_redshift'

aws_region: 'us-west-2'
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# aws_region: 'us-west-2'
# aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
# aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

# Use the output from the `sdf` step
- name: Display the sdf output
run: |
echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY
echo '```' >>$GITHUB_STEP_SUMMARY
echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY
echo '```' >>$GITHUB_STEP_SUMMARY
# # Use the output from the `sdf` step
# - name: Display the sdf output
# run: |
# echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY
# echo '```' >>$GITHUB_STEP_SUMMARY
# echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY
# echo '```' >>$GITHUB_STEP_SUMMARY

# dbt_init_challenge_v1 - uses dbt-action
dbt_init_challenge_v1:
runs-on: ubuntu-latest
name: Snowflake + dbt workspace - run dbt commands using dbt-action
steps:
- name: Checkout
uses: actions/checkout@v4
# # dbt_init_challenge_v1 - uses dbt-action
# dbt_init_challenge_v1:
# runs-on: ubuntu-latest
# name: Snowflake + dbt workspace - run dbt commands using dbt-action
# steps:
# - name: Checkout
# uses: actions/checkout@v4

- name: Run DBT commands
uses: mwhitaker/dbt-action@master
env:
DBT_TARGET: dev
SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }}
SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }}
with:
dbt_command: "dbt compile"
dbt_project_folder: "workspace/dbt_init_challenge"
# - name: Run DBT commands
# uses: mwhitaker/dbt-action@master
# env:
# DBT_TARGET: dev
# SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }}
# SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }}
# with:
# dbt_command: "dbt compile"
# dbt_project_folder: "workspace/dbt_init_challenge"

- name: Run sdf compile
uses: ./ # Uses an action in the root directory
id: sdf
env:
CATALOG: dbt_hol_dev
SCHEMA: public
with:
command: 'sdf compile'
workspace_dir: 'workspace/dbt_init_challenge'
access_key: ${{ secrets.ACCESS_KEY }}
secret_key: ${{ secrets.SECRET_KEY }}
# - name: Run sdf compile
# uses: ./ # Uses an action in the root directory
# id: sdf
# env:
# CATALOG: dbt_hol_dev
# SCHEMA: public
# with:
# command: 'sdf compile'
# workspace_dir: 'workspace/dbt_init_challenge'
# access_key: ${{ secrets.ACCESS_KEY }}
# secret_key: ${{ secrets.SECRET_KEY }}

is_dbt: 'true'
snowflake_account_id: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }}
snowflake_username: ${{ secrets.SNOWFLAKE_USERNAME }}
snowflake_password: ${{ secrets.SNOWFLAKE_PASSWORD }}
snowflake_role: 'dbt_test_role'
snowflake_warehouse: 'dbt_dev_wh'
# is_dbt: 'true'
# snowflake_account_id: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }}
# snowflake_username: ${{ secrets.SNOWFLAKE_USERNAME }}
# snowflake_password: ${{ secrets.SNOWFLAKE_PASSWORD }}
# snowflake_role: 'dbt_test_role'
# snowflake_warehouse: 'dbt_dev_wh'

# Use the output from the `sdf` step
- name: Display the sdf output
run: |
echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY
echo '```' >>$GITHUB_STEP_SUMMARY
echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY
echo '```' >>$GITHUB_STEP_SUMMARY
# # Use the output from the `sdf` step
# - name: Display the sdf output
# run: |
# echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY
# echo '```' >>$GITHUB_STEP_SUMMARY
# echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY
# echo '```' >>$GITHUB_STEP_SUMMARY

# dbt_init_challenge_v2: rus dbt commands in a container job
dbt_init_challenge_v2:
container:
image: ghcr.io/dbt-labs/dbt-snowflake:1.5.latest
volumes:
- ${{ github.workspace }}:/repo
# # dbt_init_challenge_v2: rus dbt commands in a container job
# dbt_init_challenge_v2:
# container:
# image: ghcr.io/dbt-labs/dbt-snowflake:1.5.latest
# volumes:
# - ${{ github.workspace }}:/repo

# runs-on: ubuntu-latest
# name: Snowflake + dbt workspace - run dbt commands in a container job
# steps:
# - name: Checkout
# uses: actions/checkout@v4

# - name: Run DBT commands
# env:
# DBT_TARGET: dev
# SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }}
# SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }}
# run: |
# cd /repo/workspace/dbt_init_challenge
# dbt deps
# dbt compile
# - name: Run sdf push
# uses: ./ # Uses an action in the root directory
# id: sdf
# env:
# CATALOG: dbt_hol_dev
# SCHEMA: public
# with:
# command: 'sdf push'
# # relative path to ${{ github.workspace }} which is automatically mounted by GitHub Actions
# workspace_dir: workspace/dbt_init_challenge
# access_key: ${{ secrets.ACCESS_KEY }}
# secret_key: ${{ secrets.SECRET_KEY }}

# is_dbt: 'true'
# snowflake_account_id: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }}
# snowflake_username: ${{ secrets.SNOWFLAKE_USERNAME }}
# snowflake_password: ${{ secrets.SNOWFLAKE_PASSWORD }}
# snowflake_role: 'dbt_test_role'
# snowflake_warehouse: 'dbt_dev_wh'

# # Use the output from the `sdf` step
# - name: Display the sdf output
# run: |
# echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY
# echo '```' >>$GITHUB_STEP_SUMMARY
# echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY
# echo '```' >>$GITHUB_STEP_SUMMARY


# a pure snowflake workspace
snowflake:
runs-on: ubuntu-latest
name: Snowflake + dbt workspace - run dbt commands in a container job
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Run DBT commands
env:
DBT_TARGET: dev
SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }}
SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }}
run: |
cd /repo/workspace/dbt_init_challenge
dbt deps
dbt compile
- name: Run sdf push
- name: Run sdf compile
uses: ./ # Uses an action in the root directory
id: sdf
env:
CATALOG: dbt_hol_dev
SCHEMA: public
with:
command: 'sdf push'
command: 'sdf compile'
# relative path to ${{ github.workspace }} which is automatically mounted by GitHub Actions
workspace_dir: workspace/dbt_init_challenge
access_key: ${{ secrets.ACCESS_KEY }}
secret_key: ${{ secrets.SECRET_KEY }}
workspace_dir: workspace/snowflake

is_dbt: 'true'
snowflake_provider: 'true'
snowflake_account_id: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }}
snowflake_username: ${{ secrets.SNOWFLAKE_USERNAME }}
snowflake_password: ${{ secrets.SNOWFLAKE_PASSWORD }}
Expand All @@ -123,4 +157,3 @@ jobs:
echo '```' >>$GITHUB_STEP_SUMMARY
echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY
echo '```' >>$GITHUB_STEP_SUMMARY
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Check out this [example workflow](./.github/workflows/examples.yml) to see how t
| `secret_key` | secret key created from the [console](https://console.sdf.com/catalog/settings/general) to be used in `sdf push` | No | |
| `is_dbt` | Set to a non-empty string if the workspace is dbt based | No | `""` | |
| `dbt_target` | The dbt target | No | `"dev"` |
| `snowflake_provider` | Uses a snowflake provider or not | No | `""` |
| `snowflake_account_id` | The snowflake account | No | |
| `snowflake_username` | The snowflake username | No | |
| `snowflake_password` | The snowflake password | No | |
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ inputs:
default: "dev"

# required if snowflake table provider is used
snowflake_provider:
description: "The snowflake provider"
default: ""
required: false
snowflake_account_id:
description: "The snowflake account id"
required: false
Expand Down Expand Up @@ -69,6 +73,7 @@ runs:
- ${{ inputs.command }}
- ${{ inputs.is_dbt }}
- ${{ inputs.sdf_version }}
- ${{ inputs.snowflake_provider }}
env:
WORKSPACE_DIR: ${{ inputs.workspace_dir }}
ACCESS_KEY: ${{ inputs.access_key }}
Expand Down
9 changes: 9 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
input_command=$1
input_is_dbt=$2
sdf_version=$3
snowflake_provider=$4

is_less_semvar() {
# split the version strings into arrays
Expand Down Expand Up @@ -72,6 +73,14 @@ if [[ $input_command == "sdf push"* ]]; then
check_exit_status $? ""
fi

if [[ -n $snowflake_provider ]]; then
echo "snowflake provider used: running 'sdf auth login'"
sdf auth login snowflake \
--account-id "${SNOWFLAKE_ACCOUNT_ID}" --username "${SNOWFLAKE_USERNAME}" --password "${SNOWFLAKE_PASSWORD}" \
--role "${SNOWFLAKE_ROLE}" --warehouse "${SNOWFLAKE_WAREHOUSE}"
check_exit_status $? ""
fi

if [[ -n $input_is_dbt ]]; then
echo "::group::Setting up dbt"
sdf dbt refresh
Expand Down
1 change: 1 addition & 0 deletions workspace/snowflake/src/main.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from apress.public.big_customers;
12 changes: 12 additions & 0 deletions workspace/snowflake/workspace.sdf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
workspace:
name: hello # The name of this workspace -- required
edition: "1.2" # The edition of this workspace -- required
description: "A minimal workspace"
defaults:
dialect: snowflake # The dialect of SQL used in this workspace, defaults to "presto"
includes:
- path: src # The path to sql sources for this workspace -- at least one path is required
providers:
- type: snowflake
sources:
- pattern: apress.*.*

0 comments on commit 9bb084b

Please sign in to comment.