Orchestrate Jobs With GitHub Actions and the API
Node 16 is reached the end of it's life. GitHub now requires Node 20.
Learn more in GitHub Actions: Transitioning from Node 16 to Node 20.
GitHub Actions serves as a comprehensive platform for continuous integration and continuous delivery (CI/CD), enabling the automation of your build, testing, and deployment processes. It empowers you to design workflows that automatically build and test each pull request submitted to your repository, and seamlessly deploy successfully merged pull requests to the production environment.
In this how-to, we will walk you through best practices for scheduling Coalesce refreshes through the GitHub actions interface to allow you to automate the triggering of your Coalesce jobs to be on a schedule or upon approved pull request into your main branch in accordance with CI/CD best practices.
Before You Begin
You'll need:
- GitHub: GitHub account with admin privileges to configure pipelines and manage secrets.
- Project: A Project with version control configured using your chosen platform.
- Environment: At least one Environment configured for deployment.
- Access Token: Your Coalesce access token for the CLI configuration file.
Create and Configure an Environment
- Create a new Environment for CI/CD deployments. It's recommended to use a dedicated Environment for automated deployments.
- Configure authentication for your Environment based on your data platform:
- Snowflake: Set up Snowflake Key-Pair Authentication with a service account.
- Databricks: Set up OAuth Machine-to-Machine authentication with a service principal.
- Configure Storage Mappings for your Environment.
- Deploy the Environment to verify configuration.
Data Platform Permissions
Snowflake
USAGEprivilege on the database and schema.SELECT,INSERT,UPDATE, andDELETEprivileges on tables involved in transformations.EXECUTEprivilege for procedures or functions referenced by Coalesce.- Ability to create Snowflake Key-Pair Authentication (recommended for automated deployments).
Databricks
- SQL Warehouse configured and accessible.
- Appropriate catalog and schema permissions.
- Ability to create OAuth Machine-to-Machine authentication (recommended for automated deployments).
Set up GitHub Variables and Environment
- Databricks
- Snowflake
- In GitHub, go to repo you are using with Coalesce.
- Click Settings > Security > Secrets and variable > Actions.
- You'll create two repository secrets by clicking the secrets tab, called
MY_COALESCE_SECRETandDATABRICKS_CLIENT_SECRET.MY_COALESCE_SECRET- Your API access token from your environment.DATABRICKS_CLIENT_SECRET- Client Secret from Databricks OAuth Machine-to-Machine setup.
- In GitHub, go to repo you are using with Coalesce.
- Click Settings > Security > Secrets and variable > Actions.
- You'll create two repository secrets by clicking the secrets tab, called
MY_COALESCE_SECRET, andSF_PRIVATE_KEY.MY_COALESCE_SECRET- Your API access token from your environment.SF_PRIVATE_KEY- Snowflake Private Key from Snowflake Key-Pair Authentication.
- Add your private key. The private key must contain explicitly typed newline (\n) characters at the end of each line in the .
pemfile when saved as plain text in the private key secret in GitHub.
-----BEGIN PRIVATE KEY-----\n
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCv2xVhFpaM6hhf\n
ce4U5GRfdArGkoqkL2EBRs0zGMn1YYfQ8+zDuN9YkMTNC1pNxQptGn921teGk0wv\n
cMP+I83P390jqXh56TlQtwn2reRXH7OlLdELttof4VGYb4I6KpdBhDaid8bys2FE\n
f0r948EXM81Euh9FgmMbc4KzeF1tBDyU0sqAcAJCQXOl95jUR6Wqdp04LXJVoGmI\n
-----END PRIVATE KEY-----
Update Repo With Secrets
- Create a new folder called
.githubin your main branch. - Create a subfolder within .github called
workflowsand file within workflows calledcoalesce_test.yml. - Copy and paste the following sample code into
coalesce_test.yml. - Update the "environmentID": "3" and "jobID": "2" to match your Coalesce environment.
In the default state, this workflow is triggered under three circumstances:
- A pull request into the main branch
- A successful merging of an open pull request into the main branch
- Execution on the cron scheduler (commented out). If you want to modify the cron syntax, you can use any POSIX cron scheduler.
The file also includes workflow_dispatch so you can trigger the job manually or turn it on and off in the GitHub app.
name: Deploy to PROD
on:
push:
branches:
- main
workflow_dispatch:
env:
COA_VERSION: latest
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 22.19.0
- run: echo '${{ secrets.COA_CONFIG }}' >> COA_CONFIG
# Install Coalesce CLI tool, if not installed already
- run: npm list | grep "@coalescesoftware/coa@${{ env.COA_VERSION }}" || npm install @coalescesoftware/coa@${{ env.COA_VERSION }}
# Print version number
- run: npx coa --version
# Create Deployment Plan
- run: npx coa plan --config COA_CONFIG --out ./coa-plan --debug
# Deploy Plan
- run: npx coa deploy --config COA_CONFIG --plan ./coa-plan --debug