Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates #3

Merged
merged 43 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2f45bcc
Try to build & publish a base image
xuliangs Apr 5, 2024
563cd16
use buildx build
xuliangs Apr 5, 2024
0b98895
fix path
xuliangs Apr 5, 2024
206624b
add aarch64 support
xuliangs Apr 5, 2024
af35f5b
only push on merge main
xuliangs Apr 5, 2024
8c8a902
fix event name
xuliangs Apr 5, 2024
d4f2a88
debug event_name
xuliangs Apr 5, 2024
b6041b1
remove unused
xuliangs Apr 5, 2024
8a109ae
revert, use base image after it's built
xuliangs Apr 5, 2024
128ea6d
name updates
xuliangs Apr 9, 2024
484cb55
update README
xuliangs Apr 9, 2024
b057ab0
manually trigger a push
xuliangs Apr 9, 2024
1b437da
Test run dbt steps outside the action
xuliangs Apr 10, 2024
1aad57b
test dbt compile in a separate step
xuliangs Apr 10, 2024
c6949a6
add env vars
xuliangs Apr 10, 2024
1ec2eb7
remove dbt installation
xuliangs Apr 11, 2024
0baa092
add volume
xuliangs Apr 11, 2024
c0bef62
use mount volumes
xuliangs Apr 11, 2024
cd45728
try fix
xuliangs Apr 11, 2024
9daf942
use absolute path
xuliangs Apr 11, 2024
5bef1e2
add bind mount
xuliangs Apr 11, 2024
248c4cb
uses bind mount
xuliangs Apr 11, 2024
30cf5d1
fix
xuliangs Apr 11, 2024
35934e2
path dir
xuliangs Apr 11, 2024
8495f3a
Update examples-test.yml
xuliangs Apr 11, 2024
393c3a4
add ls
xuliangs Apr 11, 2024
35d4de7
Merge branch 'harry/build_base_image' of github.com:sdf-labs/sdf-acti…
xuliangs Apr 11, 2024
3026399
move
xuliangs Apr 11, 2024
d553b4a
add more logs
xuliangs Apr 11, 2024
da0a2c7
pass in target
xuliangs Apr 11, 2024
e5f4c5d
fix
xuliangs Apr 11, 2024
a99ea77
clean up
xuliangs Apr 11, 2024
73a2c1d
remove pre-built image
xuliangs Apr 11, 2024
f9aa82a
try without volume
xuliangs Apr 11, 2024
c2f22ff
use workspace
xuliangs Apr 11, 2024
251782a
simplify
xuliangs Apr 11, 2024
eafaad8
Use latest release
xuliangs Apr 11, 2024
f3425cb
use 0.2.1
xuliangs Apr 11, 2024
df3fccf
remove auth login snowflake
xuliangs Apr 11, 2024
eba61bc
nit fixes
xuliangs Apr 11, 2024
8b9a316
Update to use the latest cli
xuliangs Apr 24, 2024
f91268f
fix env var
xuliangs Apr 24, 2024
d316bf3
Move cli installation to entrypoint.sh
xuliangs Apr 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: Test sdf-action

on:
pull_request:

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'

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

# 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 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'

# 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

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

62 changes: 0 additions & 62 deletions .github/workflows/main.yml

This file was deleted.

Empty file added CONTRIBUTING.md
Empty file.
17 changes: 7 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
FROM python:3.12.2-bookworm
ARG SDF_VERSION=0.1.192
ARG SDF_VERSION=0.2.12

# Install dependencies
RUN apt-get update && apt-get install -y \
yq \
curl \
&& rm -rf /var/lib/apt/lists/*

# Install sdf
RUN curl -LSfs https://cdn.sdf.com/releases/download/install.sh | bash -s -- --version ${SDF_VERSION}
RUN if [ "$(uname -m)" = "aarch64" ]; then \
curl -LSfs https://cdn.sdf.com/releases/download/install.sh | bash -s -- --version ${SDF_VERSION} --target aarch64-unknown-linux-gnu ; \
else \
curl -LSfs https://cdn.sdf.com/releases/download/install.sh | bash -s -- --version ${SDF_VERSION} ; \
fi
# replace above with a pre-built image?

# Install dbt-snowflake plugin using pip
RUN python3.12 -m venv .venv && . .venv/bin/activate \
&& python3 -m pip install dbt-snowflake==1.7.2 \
&& python3 -m pip install --upgrade dbt-core==1.7.9 \
&& python3 -m pip install protobuf==4.25.3

# Copy your code file from your action repository to the filesystem path `/` of the container
COPY entrypoint.sh /entrypoint.sh

# Set the code file as the entry point
Expand Down
17 changes: 0 additions & 17 deletions Dockerfile.normal

This file was deleted.

13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright [2024] [SDF Labs]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
# sdf-action
[WIP] A Github Action to run `sdf` CLI in workflows.
Github Action to run `sdf` CLI in workflows.

## Usage
Check out this [example workflow](./.github/workflows/examples.yml) to see how to use this action.

## Parameters

* `snowflake_`* parameters are required if the `snowflake` table provider is used
* `aws_*` parameters are required if the `redshift` table provider is used
* `access_key` and `secret_key` are required if the `sdf push` is used in `command`

| Parameter | Description | Required | Default |
| --- | --- | --- | --- |
| `command` | The `sdf` CLI command to run. | No | `sdf compile`
| `workspace_dir` | The directory of the workspace | No | `"."` |
| `access_key` | access key created from the [console](https://console.sdf.com/catalog/settings/general) to be used in `sdf push` | No | |
| `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_account_id` | The snowflake account | No | |
| `snowflake_username` | The snowflake username | No | |
| `snowflake_password` | The snowflake password | No | |
| `snowflake_role` | The snowflake role | No | |
| `snowflake_warehouse` | The snowflake warehouse | No | |
| `aws_region` | The aws region | No | |
| `aws_access_key_id` | The aws access key id created from an IAM user | No | |
| `aws_secret_access_key` | The aws secret created from an IAM user | No | |
9 changes: 5 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# action.yml
name: "dbt action"
name: "sdf action"
description: "Run sdf cli commands"
inputs:
command:
description: "The sdf command to run"
default: "sdf compile"
required: true
required: false
workspace_dir:
description: "The directory of the workspace"
default: "."
required: true
required: false
access_key:
description: "The access key"
required: false
Expand All @@ -18,11 +18,12 @@ inputs:
required: false
is_dbt:
description: "Whether the workspace is dbt based or not"
required: true
required: false
default: ""
dbt_target:
description: "The dbt target"
required: false
default: "dev"

# required if snowflake table provider is used
snowflake_account_id:
Expand Down
27 changes: 2 additions & 25 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/bash -l

source /.venv/bin/activate

echo "workspace dir set as: \"${WORKSPACE_DIR}\""
cd ${WORKSPACE_DIR}

Expand All @@ -20,7 +18,7 @@ check_exit_status() {
echo "$command_log"
echo EOF
} >>$GITHUB_OUTPUT

echo "result=failed" >>$GITHUB_OUTPUT
exit $exit_status
fi
Expand All @@ -34,33 +32,12 @@ if [[ $input_command == "sdf push"* ]]; then
fi

if [[ -n $input_is_dbt ]]; then
echo "python3 version - $(python3 --version)"

echo "::group::Setting up dbt"
echo "running dbt deps"
dbt deps
check_exit_status $? ""

echo "running dbt compile"
dbt compile
check_exit_status $? ""

echo "running dbt compile done"
sdf dbt refresh
echo "::endgroup::"
check_exit_status $? ""
fi

# run sdf auth login snwoflake if necessary
snowflake_provider=$(yq .provider.type workspace.sdf.yml | grep snowflake | tail -1)
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

# run and save outputs
echo "running command: $input_command"
log=$($input_command 2>&1)
Expand All @@ -73,4 +50,4 @@ check_exit_status $exit_status "$log"
echo "$log"
echo EOF
} >>$GITHUB_OUTPUT
echo "result=passed" >>$GITHUB_OUTPUT
echo "result=passed" >>$GITHUB_OUTPUT
Loading