Created
June 4, 2022 02:07
-
-
Save jeffhollan/759712bae6096773fb590c50f68e5fe8 to your computer and use it in GitHub Desktop.
GitHub Actions and Snowflake Stored Proc
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
# Very basic GitHub Action workflow, goes in ~/.github/workflows/deploy.yaml | |
name: CI | |
# Controls when the workflow will run | |
on: | |
# Triggers the workflow on any branch or tag commit | |
push: | |
branches: | |
- "*" | |
tags: | |
- "v*" | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
jobs: | |
# This workflow contains a single job called "deploy" | |
deploy: | |
runs-on: ubuntu-latest | |
env: | |
SNOWSQL_PWD: ${{ secrets.SNOWFLAKE_PASSWORD }} | |
SNOWSQL_ACCOUNT: ${{ secrets.SNOWFLAKE_ACCOUNT }} | |
SNOWSQL_USER: ${{ secrets.SNOWFLAKE_USERNAME }} | |
SNOWSQL_DATABASE: ${{ secrets.SNOWFLAKE_DATABASE }} | |
SNOWSQL_SCHEMA: ${{ secrets.SNOWFLAKE_SCHEMA }} | |
SNOWSQL_ROLE: ${{ secrets.SNOWFLAKE_ROLE }} | |
SNOWSQL_WAREHOUSE: ${{ secrets.SNOWFLAKE_WAREHOUSE }} | |
# Steps represent a sequence of tasks that will be executed as part of the job | |
steps: | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
- uses: actions/checkout@v3 | |
- name: Install SnowSQL | |
run: | | |
curl -O https://sfc-repo.snowflakecomputing.com/snowsql/bootstrap/1.2/linux_x86_64/snowsql-1.2.9-linux_x86_64.bash | |
SNOWSQL_DEST=~/bin SNOWSQL_LOGIN_SHELL=~/.profile bash snowsql-1.2.9-linux_x86_64.bash | |
- name: Upload artifact to SnowSQL | |
run: | | |
~/bin/snowsql -q 'put file://'$(pwd)'/storedproc.py @~/${{ github.ref_name }} overwrite=true' -o friendly=false | |
- name: Create or update Stored PRocedure | |
run: | | |
~/bin/snowsql -q 'CREATE OR REPLACE PROCEDURE MYPROC(message STRING) | |
RETURNS STRING | |
LANGUAGE PYTHON | |
RUNTIME_VERSION = '\''3.8'\'' | |
PACKAGES = ('') | |
IMPORTS = ('\''@~/${{ github.ref_name }}/storedproc.py'\'') | |
HANDLER = '\''storedproc.run'\'';' -o friendly=false | |
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
# Workflow that supports versions, goes in ~/.github/workflows/deploy.yaml | |
name: CI | |
# Controls when the workflow will run | |
on: | |
# Triggers the workflow on any branch or tag commit | |
push: | |
branches: | |
- "*" | |
tags: | |
- "v*" | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
env: | |
SNOWSQL_PWD: ${{ secrets.SNOWFLAKE_PASSWORD }} | |
SNOWSQL_ACCOUNT: ${{ secrets.SNOWFLAKE_ACCOUNT }} | |
SNOWSQL_USER: ${{ secrets.SNOWFLAKE_USERNAME }} | |
SNOWSQL_DATABASE: ${{ secrets.SNOWFLAKE_DATABASE }} | |
SNOWSQL_SCHEMA: ${{ secrets.SNOWFLAKE_SCHEMA }} | |
SNOWSQL_ROLE: ${{ secrets.SNOWFLAKE_ROLE }} | |
SNOWSQL_WAREHOUSE: ${{ secrets.SNOWFLAKE_WAREHOUSE }} | |
steps: | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
- uses: actions/checkout@v3 | |
- name: Install SnowSQL | |
run: | | |
curl -O https://sfc-repo.snowflakecomputing.com/snowsql/bootstrap/1.2/linux_x86_64/snowsql-1.2.9-linux_x86_64.bash | |
SNOWSQL_DEST=~/bin SNOWSQL_LOGIN_SHELL=~/.profile bash snowsql-1.2.9-linux_x86_64.bash | |
# Runs a single command using the runners shell | |
- name: Upload artifact to SnowSQL | |
run: | | |
~/bin/snowsql -q 'put file://'$(pwd)'/storedproc.py @~/${{ github.ref_name }} overwrite=true' -o friendly=false | |
- name: Create or update storedproc | |
run: | | |
~/bin/snowsql -q 'CREATE OR REPLACE PROCEDURE MYPROC_'$(echo ${{ github.ref_name }} | tr . _)'(message STRING) | |
RETURNS STRING | |
LANGUAGE PYTHON | |
RUNTIME_VERSION = '\''3.8'\'' | |
PACKAGES = ('\''snowflake-snowpark-python'\'') | |
IMPORTS = ('\''@~/${{ github.ref_name }}/storedproc.py'\'') | |
HANDLER = '\''storedproc.run'\'';' -o friendly=false | |
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
# storedproc.py file | |
def run(message): | |
return "hello world, v1"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment