Continuous Deployment of refs/heads/develop by dreads #12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##################################################################### | |
# GitHub Action to perform continuous deployment (CD) of database | |
# changes using Liquibase Pro, Liquibase Pro Flows, and Custom | |
# Policy checks. | |
##################################################################### | |
name: 'Liquibase Pro CD Workflow' | |
run-name: Continuous Deployment of ${{github.ref}} by ${{ github.actor }} | |
# This workflow will execute whenever a 'push' event occurs on the | |
# 'develop' branch. A push event can occur due to several events, | |
# including merging a PR or bypassing rules and pushing directly to | |
# the branch as a repository administrator. When this workflow | |
# executes, it will deploy all pending changes, including any which | |
# have been previously rolled back. Since the GitHub Actions and | |
# Azure Pipelines files are housed in the same repository, we safely | |
# ignore any changes to the Azure workflows. | |
# | |
# To extend CD to other environments, add their corresponding | |
# branches here. | |
on: | |
push: | |
branches: | |
- 'develop' | |
paths-ignore: | |
- '.azure_pipelines/**' | |
##################################################################### | |
# Set up the environment | |
##################################################################### | |
env: | |
# The top level Flow File that gets cloned into the workspace from | |
# the Liquibase Configuration Repo which orchestrates the database changes. | |
# See https://docs.liquibase.com/commands/flow/flow.html | |
FLOW_FILE: "flowfiles/liquibase-postmerge.flowfile.yaml" | |
# The Liquibase Search Path controls how Liquibase finds it's configurations. | |
# To ensure the correct config gets located first, keep "." at the end of this path. | |
# See https://docs.liquibase.com/concepts/changelogs/how-liquibase-finds-files.html | |
LIQUIBASE_SEARCH_PATH: "liquibase-process,." | |
# Location of the Custom Policy Checks settings file from the Liquibase Configuration Repo. | |
# See https://docs.liquibase.com/liquibase-pro/policy-checks/custom-policy-checks/home.html | |
LIQUIBASE_COMMAND_CHECKS_SETTINGS_FILE: "policychecks/liquibase.checks-settings.conf" | |
# Store the Liquibase Pro License key in a Github Action Repository Secret. The | |
# same license key is used for all executions, so it is tracked at the repository level | |
# See https://docs.liquibase.com/workflows/liquibase-pro/how-to-apply-your-liquibase-pro-license-key.html | |
LIQUIBASE_LICENSE_KEY: ${{ secrets.LIQUIBASE_PRO_LICENSE_KEY }} | |
# JDBC URL of the database per environment. Based on the incoming branch (one of DEV, QA, or PROD), | |
# the corresponding secret will be taken from the Environment secrets. | |
# See https://docs.liquibase.com/workflows/liquibase-community/using-jdbc-url-in-liquibase.html | |
LIQUIBASE_COMMAND_URL: ${{ secrets.LIQUIBASE_COMMAND_URL }} | |
# Credentials for the environment's database. Based on the incoming branch (one of DEV, QA, or PROD), | |
# the corresponding secrets will be taken from the Environment secrets. | |
# See https://docs.liquibase.com/parameters/command-parameters.html | |
LIQUIBASE_COMMAND_USERNAME: ${{ secrets.LIQUIBASE_COMMAND_USERNAME }} | |
LIQUIBASE_COMMAND_PASSWORD: ${{ secrets.LIQUIBASE_COMMAND_PASSWORD }} | |
# Logging Settings | |
# See https://docs.liquibase.com/parameters/log-format.html | |
LIQUIBASE_LOG_FORMAT: JSON | |
LIQUIBASE_LOG_LEVEL: INFO | |
jobs: | |
#################################################################### | |
# Initialization runs first because it has no 'needs' value. | |
#################################################################### | |
init: | |
name: Initialization | |
# This runs on a self-hosted runner with Liquibase preinstalled. | |
runs-on: [self-hosted] | |
# From init, we output the environment determined during the set-environment step below | |
outputs: | |
environment: ${{ steps.set-environment.outputs.environment }} | |
steps: | |
# Cancel any previous runs that are not completed for this workflow | |
- name: Cancel previous workflow | |
uses: styfle/[email protected] | |
with: | |
access_token: ${{ github.token }} | |
# Determine the environment based on the branch(es) that triggered this workflow. | |
# Output "DEV", "QA", or "PROD" to $GITHUB_OUTPUT where job output parameters are | |
# shared between jobs. | |
- name: Set Environment | |
id: set-environment | |
run: | | |
echo "environment=DEV" >> $GITHUB_OUTPUT | |
if [[ "${{github.base_ref}}" == qa || "${{github.ref}}" == refs/heads/qa ]]; then | |
echo "environment=QA" >> $GITHUB_OUTPUT | |
fi | |
if [[ "${{github.base_ref}}" == release* || "${{github.ref}}" == refs/heads/release* ]]; then | |
echo "environment=PROD" >> $GITHUB_OUTPUT | |
fi | |
#################################################################### | |
# Print out the selected environment to the log for troubleshooting. | |
# This informational job runs in parallel with the checkout-repo job. | |
#################################################################### | |
print-environment: | |
name: Environment information | |
runs-on: [self-hosted] | |
needs: [init] | |
steps: | |
- env: | |
ENVIRONMENT: ${{needs.init.outputs.environment}} | |
run: echo "The $ENVIRONMENT environment was selected." | |
#################################################################### | |
# Check out the source code and configuration | |
#################################################################### | |
checkout-repo: | |
name: Check out repositories | |
needs: [init] | |
runs-on: [self-hosted] | |
steps: | |
# Check out the source code | |
- name: Checkout Database Source repo | |
uses: actions/checkout@v3 | |
# Check out the Liquibase Configuration Repo to a folder, "liquibase-process" | |
- name: Checkout Liquibase Configuration repo | |
uses: actions/checkout@v4 | |
with: | |
repository: adeelmalik78/Automations | |
path: liquibase-process | |
##################################################################### | |
# Perform the Database change control operations specified | |
# in the flowfile. | |
##################################################################### | |
liquibase-deployment: | |
name: Database Deployment | |
needs: [checkout-repo, init] | |
runs-on: [self-hosted] | |
environment: ${{needs.init.outputs.environment}} | |
steps: | |
# Execute the Flow file. | |
- name: Run flow | |
run: | | |
liquibase --license-key=${{ secrets.LIQUIBASE_LICENSE_KEY }} flow \ | |
--flow-file=${{ env.FLOW_FILE }} \ | |
--logfile=logs/liquibase.log | |