From 68fbfb94201403d16261e59a5949de2212a837b4 Mon Sep 17 00:00:00 2001 From: smilysophia Date: Tue, 21 Jul 2026 14:05:01 -0700 Subject: [PATCH 1/3] Create main.yml --- .github/workflows/main.yml | 67 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..d8f6ad5d --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,67 @@ +name: Deploy Templatized Data Environment + +on: + pull_request: + types: [closed] + branches: + - staging + - main + push: + branches: + - staging + - main + +jobs: + deploy_data_environment: + # Only run when PR is merged or on direct push to environment branches + if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) + runs-on: ubuntu-latest + + env: + # Read connection secret + SNOWFLAKE_CONNECTIONS_ADVANCED_DATA_ENGINEERING_SNOWFLAKE_ACCOUNT: ${{ secrets.SNOWFLAKE_ACCOUNT }} + SNOWFLAKE_CONNECTIONS_ADVANCED_DATA_ENGINEERING_SNOWFLAKE_USER: ${{ secrets.SNOWFLAKE_USER }} + SNOWFLAKE_CONNECTIONS_ADVANCED_DATA_ENGINEERING_SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} + + steps: + # Checkout step is necessary to access repository files + - name: Checkout repository + uses: actions/checkout@v4 + + # Determine environment based on target branch + - name: Set environment + id: set_env + run: | + TARGET_BRANCH="${GITHUB_BASE_REF:-${GITHUB_REF#refs/heads/}}" + + if [[ $TARGET_BRANCH == "staging" ]]; then + echo "DEPLOY_ENV=staging" >> $GITHUB_ENV + echo "Environment set to staging" + elif [[ $TARGET_BRANCH == "main" ]]; then + echo "DEPLOY_ENV=prod" >> $GITHUB_ENV + echo "Environment set to production" + else + echo "Unexpected branch: $TARGET_BRANCH" + exit 1 + fi + + # Install Snowflake CLI GitHub Action and point to config file + - name: Install SnowflakeCLI + uses: snowflakedb/snowflake-cli-action@v1.5 + with: + cli-version: "latest" + default-config-file-path: "config.toml" + + # Fetch latest changes from the repository to Snowflake + - name: Fetch latest changes to Snowflake + run: snow git fetch course_repo.public.advanced_data_engineering_snowflake + + # Deploy templates to the data environment - + - name: Deploy templates to data environment + run: | + # Export TARGET_BRANCH for use in this step + echo "Using branch: ${GITHUB_REF_NAME}" + snow git execute @advanced_data_engineering_snowflake/branches/${GITHUB_REF_NAME}/module-1/hamburg_weather/pipeline/data/ \ + -D "env='${{ env_DEPLOY_ENV }}'" \ + --database=COURSE_REPO \ + --schema=PUBLIC From 3185036e8380bfc4675b5bf8513362326a1d7cf2 Mon Sep 17 00:00:00 2001 From: smilysophia Date: Tue, 21 Jul 2026 15:48:08 -0700 Subject: [PATCH 2/3] Fix environment variable reference in workflow --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d8f6ad5d..e7413e0c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -62,6 +62,6 @@ jobs: # Export TARGET_BRANCH for use in this step echo "Using branch: ${GITHUB_REF_NAME}" snow git execute @advanced_data_engineering_snowflake/branches/${GITHUB_REF_NAME}/module-1/hamburg_weather/pipeline/data/ \ - -D "env='${{ env_DEPLOY_ENV }}'" \ + -D "env='${{ env.DEPLOY_ENV }}'" \ --database=COURSE_REPO \ --schema=PUBLIC From 067a64af1f86e80e7882b077af9f9769285fd020 Mon Sep 17 00:00:00 2001 From: smilysophia Date: Tue, 21 Jul 2026 16:09:19 -0700 Subject: [PATCH 3/3] Replace table creation with create or replace statement --- module-1/hamburg_weather/pipeline/data/load_tasty_bytes.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module-1/hamburg_weather/pipeline/data/load_tasty_bytes.sql b/module-1/hamburg_weather/pipeline/data/load_tasty_bytes.sql index 4565f538..76b2c323 100644 --- a/module-1/hamburg_weather/pipeline/data/load_tasty_bytes.sql +++ b/module-1/hamburg_weather/pipeline/data/load_tasty_bytes.sql @@ -57,7 +57,7 @@ raw zone table build -- country table build -- todo: complete table build -CREATE TABLE {{env}}_tasty_bytes.raw_pos.country +CREATE OR REPLACE TABLE {{env}}_tasty_bytes.raw_pos.country ( country_id NUMBER(18,0), country VARCHAR(16777216), @@ -338,4 +338,4 @@ FROM @{{env}}_tasty_bytes.public.s3load/raw_pos/subset_order_header/; -- order_detail table load COPY INTO {{env}}_tasty_bytes.raw_pos.order_detail -FROM @{{env}}_tasty_bytes.public.s3load/raw_pos/subset_order_detail/; \ No newline at end of file +FROM @{{env}}_tasty_bytes.public.s3load/raw_pos/subset_order_detail/;