Skip to content

Commit 525181b

Browse files
authored
Merge pull request #3 from kialburg/staging
Staging
2 parents 25a2360 + c8e46d5 commit 525181b

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

.github/workflows/main.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Deploy Templatized Data Environment
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- staging
8+
- main
9+
push:
10+
branches:
11+
- staging
12+
- main
13+
14+
jobs:
15+
deploy_data_environment:
16+
# Only run when PR is merged or on direct push to environment branches
17+
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
18+
runs-on: ubuntu-latest
19+
20+
env:
21+
# Read connection secret
22+
SNOWFLAKE_CONNECTIONS_ADVANCED_DATA_ENGINEERING_SNOWFLAKE_ACCOUNT: ${{ secrets.SNOWFLAKE_ACCOUNT }}
23+
SNOWFLAKE_CONNECTIONS_ADVANCED_DATA_ENGINEERING_SNOWFLAKE_USER: ${{ secrets.SNOWFLAKE_USER }}
24+
SNOWFLAKE_CONNECTIONS_ADVANCED_DATA_ENGINEERING_SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }}
25+
26+
steps:
27+
# Checkout step is necessary to access repository files
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
31+
# Determine environment based on target branch
32+
- name: Set environment
33+
id: set_env
34+
run: |
35+
TARGET_BRANCH="${GITHUB_BASE_REF:-${GITHUB_REF#refs/heads/}}"
36+
37+
if [[ $TARGET_BRANCH == "staging" ]]; then
38+
echo "DEPLOY_ENV=staging" >> $GITHUB_ENV
39+
echo "Environment set to staging"
40+
elif [[ $TARGET_BRANCH == "main" ]]; then
41+
echo "DEPLOY_ENV=prod" >> $GITHUB_ENV
42+
echo "Environment set to production"
43+
else
44+
echo "Unexpected branch: $TARGET_BRANCH"
45+
exit 1
46+
fi
47+
48+
# Install Snowflake CLI GitHub Action and point to config file
49+
- name: Install SnowflakeCLI
50+
uses: snowflakedb/snowflake-cli-action@v1.5
51+
with:
52+
cli-version: "latest"
53+
default-config-file-path: "config.toml"
54+
55+
# Fetch latest changes from the repository to Snowflake
56+
- name: Fetch latest changes to Snowflake
57+
run: snow git fetch course_repo.public.advanced_data_engineering_snowflake
58+
59+
# Deploy templates to the data environment -
60+
- name: Deploy templates to data environment
61+
run: |
62+
# Export TARGET_BRANCH for use in this step
63+
echo "Using branch: ${GITHUB_REF_NAME}"
64+
snow git execute @advanced_data_engineering_snowflake/branches/${GITHUB_REF_NAME}/module-1/hamburg_weather/pipeline/data/ \
65+
-D "env='${{env.DEPLOY_ENV}}'" \
66+
--database=COURSE_REPO \
67+
--schema=PUBLIC

0 commit comments

Comments
 (0)