SDF is a powerful tool on its own, but its utility is amplified when integrated into CI/CD workflows.
sdf compile
and sdf test
on new pull requests and subsequent updates. This guide assumes you have a basic understanding of GitHub Actions and how to create a workflow file. If you’re new to GitHub Actions, we recommend checking out the official documentation.
If you’d like to skip ahead and see the final result, you can find the example repository here.
Create an Example Workspace
pii_saas_platform
example. You can create a new workspace by running the following command:Run Compile
sdf compile
. This command will compile all of the SQL in your workspace and ensure it is valid. If you have any errors in your SQL, this command will fail.Add the GitHub Action
sdf compile
on each pull request. We’ll need to add a workflow file to our workspace that utilizes the SDF GitHub Action to do this.Add the following yml
to a file called sdf.yml
in the .github/workflows
directory of your repository. This file will run the trigger the SDF GitHub action on each pull request.sdf-labs/sdf-action@v0
as the action to use. Version v0
gets the latest version under 0.*.*
. If you’d like to use a specific version, you can specify it in the uses
field by specifying the entire semantic version (e.g. sdf-labs/sdf-action@v0.1.0
).For documentation on each of the allowed inputs, see the README in the SDF GitHub Action repository.The last step in the workflow is to pretty print the output from the SDF command. This is optional, but will result in the output seen in the screenshot below on the workflow summary page.(Optional) Use the Action with DBT
dbt compile
using this GitHub Action.Furthermore, if you don’t have the DBT profiles.yml
configured in your DBT project (i.e. adjacent to your dbt_project.yml
), you’ll need to write the profiles.yml
file in the GitHub action. Use the modified sdf.yml
workflow file (called sdf_dbt.yml
) below to accomplish this.
Note the example below is for a Snowflake configuration.profiles.yml
was contributed by Chris Hronek. Thanks Chris!is_dbt
is set to true
in the sdf compile
step. Furthermore, we are specifying the workspace_dir
to be the path to the DBT project, since the SDF workspace must be defined adjacent to the DBT project in order to function properly.sdf dbt refresh
and looks for models in the target/compiled/models/sdf
directory for compilation when is_dbt
is set to true
.Create a Pull Request on GitHub
add-sdf-action
.git add .
sdf-add-action
branch as the branch to merge into main
.Once the pull request is created, you should see our new GitHub action start running and succeed. Congrats! You’ve successfully integrated SDF into your CI/CD workflow.Test a Breaking Change (Optional)
add-sdf-action
branch. This will trigger the GitHub action to run again, and it should fail.To demonstrate SDF’s static impact analysis, let’s remove a column that’s being used in a downstream model. This will cause the sdf compile
command to fail, and in a perfect world, would prevent us from merging this update into our main branch.
To do this, remove line 7
from the file found at ddls/payment/public/invoices.sql
. This will remove the payer_user_id
column from the invoices
DDL.After committing the change, push it to the branch with an open pull request. You should see the GitHub action fail, and the pull request will not be mergeable if the repository is configured in this way.Here’s an example job summary of an SDF compilation failure in CI/CDsdf compile
on each pull request, and tested the action by making a breaking change to our SQL. By integrating SDF into your CI/CD workflow, you can ensure that your SQL is always valid and downstream models are compliant with your new changes. This can help prevent costly errors and ensure that your data is always reliable.
For a completed example of this guide, check out the example repository