Schedule Jobs With GitHub Actions and the CLI
Before You Begin
- Access to a GitHub account and project. Sign up for free here.
- Git must be set up and configured in your Coalesce Org. To use GitHub Actions, you must use GitHub as your git repository.
Upload Actions Secret
To follow best practices, Coalesce recommends that you upload your coa config file as a secure file within the GitHub Actions settings.
-
From within your GitHub project, go to Settings → Secrets → Actions
-
Click New repository secret.
-
Provide a name for it. In this example we will call it
COA_CONFIG
. -
Find and open your coa
config
file. Default location is~/.coa
. -
Copy its contents into the Value field.
-
Click Add Secret to save.
Example Deploy on Merge Workflow
-
From within your GitHub project, go to Actions and click New workflow.
-
Choose Simple workflow → Configure.
-
You will be presented with a template YAML file. Provide it a name and replace its content with the Deploy Workflow code below.
Deploy Workflowname: Deploy to Environment
on:
push:
branches:
- main
workflow_dispatch:
env:
COA_VERSION: latest # Before utilizing this pipeline in production scenarios, it is advised to pin a specific version. This practice aims to reduce potential disruptions. You can find the released versions on NPM at this link: https://www.npmjs.com/package/@coalescesoftware/coa
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
# Fetch config secret from GitHub Actions secret repository, then write coa config to a temporary file
- 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 -
Commit this file to your repository.
-
You'll now see your workflow, and it will automatically run when a commit is merged to the
main
branch. You can also manually run it by clicking Run workflow.
Example Scheduled Refresh Workflow
The following instructions provide an example workflow where an Environment is refreshed hourly using a cron job.
-
From within your GitHub project, go to Actions and click New workflow.
-
Choose Simple workflow → Configure.
-
You will be presented with a template YAML file. Provide it a name and replace its content with the Refresh Workflow code below.
Refresh Workflowname: Refresh Data
on:
# Set a schedule using cron
schedule:
- cron: "0 * * * *"
# This option allows the workflow to be triggered manually
workflow_dispatch:
env:
COA_VERSION: latest # Versions released on NPM here: https://www.npmjs.com/package/@coalescesoftware/coa
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
# Fetch coa config secret from GitHub Actions secret repository, then write coa config to a temporary file
- 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 }}
# Execute coa CLI, starting coa refresh
- run: npx coa refresh --config COA_CONFIG -
Commit this file to your repository.
-
You'll now see your workflow, and it will automatically run every hour. You can also manually run it by clicking Run workflow.