How To: Call Liquibase Enterprise Packager from GitHub Actions
Liquibase Enterprise can be integrated with GitHub Actions CI/CD to package and build your database code. Please visit the GitHub Actions website to learn more about GitHub actions https://docs.github.com/en/actions.
This document provides a sample CI/CD pipeline to execute the Liquibase Enterprise packager operation. In the sample it references a self-hosted GitHub Action runner for either Linux or Windows.
Prerequisites
1. Liquibase Repositories
Before following the steps in this document, setup your databases and create the Liquibase project.
Liquibase Enterprise requires two repositories. In GitHub create the following two repositories:
The Liquibase Project repository.
The SQL code repository.
Push the Liquibase project configuration files to the project repository in GitHub. Add the sql_code folders to the SQL code repository.
(Optional) In the sample, a third centralized rules repository is referenced.
Centralized rules repository.
Add the rules to your centralized rules repository, placing rules in database-specific folders such as sqlserver, oracle, etc. Ensure that the rules are housed in the correct folder for Forecast, PostForecast, PreForecast, and SqlRules beneath the database-specific folders.
2. GitHub Self-Hosted runner with Liquibase Enterprise installed
Refer to the GitHub documentation to setup a self-hosted runner.
Sample Files
Sample buildsql.yml
Below is sample content for a GitHub Actions file that would go into .github/workflows of the SQL code repository. In this sample, the build is triggered automatically whenever there is a push to the branches “main” or “development”.
This file calls either packager.sh or packager.bat depending on the type of agent in use, Linux or Windows.
# This is a basic workflow to help you get started with Actions
name: buildsql
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches:
- 'main'
- 'development'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on. Uncomment the correct runs-on for your runner type.
# runs-on: [ self-hosted, windows ]
# runs-on: [ self-hosted, linux ]
if: "!contains(github.event.head_commit.message, 'Datical automatic check-in')"
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
# Runs the Packager commands for Linux
# Ensure the PATH is updated for your database's native executor
- name: Package (Linux)
if: runner.os == 'Linux'
run: |
whoami
PATH="$PATH:/opt/datical/DaticalDB/repl:/opt/mssql-tools/bin"
echo $PATH
hammer show version
REPO_NAME=${{ github.event.repository.name }}
PROJECT_NAME=${REPO_NAME//"_sql"/}
BUILD=${{ github.run_number }}
BRANCH=${{ github.ref }}
BRANCH=${BRANCH##*/}
./packager.sh $PROJECT_NAME $BUILD $BRANCH
# Runs the Packager commands for Windows
# Ensure the Path is updated for your database's native executor
- name: Package (Windows)
if: runner.os == 'Windows'
run: |
whoami
$Env:Path += ";C:\Users\Administrator\DaticalDB\repl"
$Env:Path += ";C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\"
hammer show version
$REPO_NAME="${{ github.event.repository.name }}"
$PROJECT_NAME=$REPO_NAME.replace("_sql","")
$BUILD="${{ github.run_number }}"
$BRANCH="${{ github.ref }}"
$BRANCH=$BRANCH -replace '.*/'
Get-Variable -Name REPO_NAME
Get-Variable -Name PROJECT_NAME
Get-Variable -Name BUILD
Get-Variable -Name BRANCH
.\packager.bat $PROJECT_NAME $BUILD $BRANCH
- name: Create Artifact
uses: actions/upload-artifact@v4
with:
name: ddb-repo
path: |
project
!project/Reports/*
!project/Logs/*
!project/Snapshots/*
!project/Profiles/*
!project/daticaldb.log
!project/deployPackager.properties
Sample packager.sh (for Linux)
Ensure this file has executable permissions by using chmod +x packager.sh
#!/bin/bash
project=$1
build=$2
pipeline=$3
database="sqlserver"
echo "Checking out the DDB, SQL, and Rules repo for project $project"
git clone git@github.com:datical-customersuccess/"$project"_ddb.git project
git clone git@github.com:datical-customersuccess/"$project"_sql.git
git clone git@github.com:datical-customersuccess/application_rules.git rules
echo 'Process runs in ddb repo'
cd project
echo 'Copying in global rules'
cp -R ../rules/common/Rules .
cp -R ../rules/"$database"/Rules .
echo 'For the packager command also include Build number in labels'
/opt/datical/DaticalDB/repl/hammer groovy deployPackager.groovy pipeline=$pipeline scm=true labels=$pipeline,$build
if [ $? -ne 0 ]; then exit 1; fi
Sample packager.bat (for Windows)
SET project=%1
SET build=%2
SET branch=%3
SET database="sqlserver"
echo "Checking out the DDB, SQL, and Rules repo for project %project%"
git clone applicationrepo_ddb:liquibase/%project%_ddb.git project
git clone applicationrepo_sql:liquibase/%project%_sql.git
git clone application_rules:liquibase/application_rules.git rules
echo 'Process runs in ddb repo'
cd project
echo 'Copying in global rules'
xcopy /s/e/y ..\rules\common\Rules\* .\Rules\*
xcopy /s/e/y ..\rules\%database%\Rules\* .\Rules\*
echo 'Running Packager....'
cd ../%project%_sql
git checkout %branch%
cd ../project
if "%branch%"=="main" (
hammer groovy deployPackager.groovy pipeline=release scm=true labels=build_%build%
)
if "%branch%"=="development" (
hammer groovy deployPackager.groovy pipeline=develop scm=true labels=build_%build%
)
Related content
Copyright © Datical 2012-2020 - Proprietary and Confidential