Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #25 from StevenMassaro/DAT-8009
Browse files Browse the repository at this point in the history
support running quality checks and add proLicenseKey param (DAT-8009)
  • Loading branch information
mcred authored Apr 7, 2022
2 parents f6984c0 + 2d6f709 commit 7377186
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 12 deletions.
73 changes: 71 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ steps:
### Required Inputs
`operation`, `username`, `password`, and `url` are required for every use.
`operation` is required for every use.

The `operation` input expects one of the following:

Expand All @@ -53,63 +53,107 @@ The `operation` input expects one of the following:
- status
- history
- diff
- 'checks run' (note that the `checks run` command must be wrapped with quotes in your `build.yml` because the command has a space in it)

### Optional Inputs

`classpath`, `changeLogFile`, `count`, `tag`, `date`, and `referenceUrl` are optional inputs that may be required by some operations. The following operations have the subsequent required inputs:
`username`, `password`, `url`, `classpath`, `changeLogFile`, `count`, `tag`, `date`, `referenceUrl`, `proLicenseKey` and `hubApiKey` are optional inputs that may be required by some operations.

It is recommended that `proLicenseKey` and `hubApiKey` are not stored in plaintext, but rather using a [GitHub secret](https://docs.github.com/en/actions/security-guides/encrypted-secrets):

```
proLicenseKey: ${{ secrets.PRO_LICENSE_KEY }}
```

The following operations have the subsequent required inputs:

#### updateCount

- username
- password
- url
- classpath
- changeLogFile
- count

#### tag

- username
- password
- url
- tag

#### updateToTag

- username
- password
- url
- classpath
- changeLogFile
- tag

#### rollback

- username
- password
- url
- classpath
- changeLogFile
- tag

#### rollbackCount

- username
- password
- url
- classpath
- changeLogFile
- count

#### rollbackToDate

- username
- password
- url
- classpath
- changeLogFile
- date

#### updateSQL

- username
- password
- url
- changeLogFile

#### futureRollbackSQL

- username
- password
- url
- classpath
- changeLogFile

#### status

- username
- password
- url
- classpath
- changeLogFile

#### diff

- username
- password
- url
- referenceUrl

#### checks run

- changeLogFile
- checksSettingsFile

### Secrets

It is a good practice to protect your database credentials with [Github Secrets](https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets)
Expand All @@ -118,3 +162,28 @@ It is a good practice to protect your database credentials with [Github Secrets]

Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on our
guidelines for [contributing](https://www.liquibase.org/community/index.html)!

#### Developer instructions

We've found that the easiest way to test changes to this GitHub action is to:
- fork this repo to your personal account
- create a sample `build.yml` to trigger the action, noting that the `uses` line specifies the relative path, which will run the action as specified in your fork (rather than the action that is published by Liquibase)
```
name: Build and Test
on: [push, pull_request]
jobs:
runchecks:
name: "Run Liquibase Quality Checks"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
with:
operation: 'checks run'
changeLogFile: 'mychangelog.sql'
checksSettingsFile: 'liquibasech.conf'
proLicenseKey: ${{ secrets.PRO_LICENSE_KEY }}
```
- make changes as desired and observe the execution in GitHub
20 changes: 16 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: 'Liquibase Github Action'
description: 'Validate, Prepare and Execute Liquibase CLI'
inputs:
operation: # [update, updateCount, tag, updateToTag, rollback, rollbackCount, rollbackToDate, updateSQL, futureRollbackSQL, status, history, diff]
operation: # [update, updateCount, tag, updateToTag, rollback, rollbackCount, rollbackToDate, updateSQL, futureRollbackSQL, status, history, diff, checks run]
description: 'Operation to run'
required: true
classpath: # string
Expand All @@ -13,13 +13,13 @@ inputs:
required: false
username: # string
description: 'Database Username'
required: true
required: false
password: # string
description: 'Database Password'
required: true
required: false
url: # string
description: 'Database URL'
required: true
required: false
count: # integer
description: 'Count for updateCount and rollbackCount'
required: false
Expand All @@ -32,6 +32,15 @@ inputs:
referenceUrl: # string
description: 'Reference URL for diff'
required: false
checksSettingsFile: # string
description: 'Configuration file for checks execution'
required: false
proLicenseKey: # string
description: 'Liquibase Pro license key used to unlock paid capabilities'
required: false
hubApiKey: # string
description: 'Liquibase Hub API key for operations'
required: false
runs:
using: 'docker'
image: 'Dockerfile'
Expand All @@ -46,6 +55,9 @@ runs:
- ${{ inputs.tag }}
- ${{ inputs.date }}
- ${{ inputs.referenceUrl }}
- ${{ inputs.checksSettingsFile }}
- ${{ inputs.proLicenseKey }}
- ${{ inputs.hubApiKey }}
branding:
icon: database
color: red
69 changes: 63 additions & 6 deletions entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,118 +10,175 @@ COUNT=$7
TAG=$8
DATE=$9
REFERENCEURL=${10}
CHECKSSETTINGSFILE=${11}
PROLICENSEKEY=${12}
HUBAPIKEY=${13}

PARAMS=()
VALUES=()
# Liquibase requires some parameters to come after the command name, those parameters should be added to this list.
SECONDPARAMS=()

function check_required_param() {
local OP=$1
local KEY=$2
local VAL=$3
local IsVALUE=${4:-false}
local IsSecondParam=${5:-false}
if [ -z "$VAL" ]
then
echo "$OP requires $KEY to not be empty"
exit 1
fi
if [ "$IsVALUE" = true ]
check_optional_param "$OP" "$KEY" "$VAL" "$IsVALUE" "$IsSecondParam"
}

function check_optional_param() {
local OP=$1
local KEY=$2
local VAL=$3
local IsVALUE=${4:-false}
local IsSecondParam=${5:-false}

if [ -z "$VAL" ]
then
VALUES+=($VAL)
echo "$KEY is empty"
else
PARAMS+=(--$KEY=$VAL)
if [ "$IsVALUE" = true ]
then
VALUES+=($VAL)
else
if [ "$IsSecondParam" = true ]
then
SECONDPARAMS+=(--$KEY=$VAL)
else
PARAMS+=(--$KEY=$VAL)
fi
fi
fi
}


function validate_operation() {
case $OPERATION in
update)
check_required_param update username $USERNAME
check_required_param update password $PASSWORD
check_required_param update classpath $CLASSPATH
check_required_param update changeLogFile $CHANGELOGFILE
check_required_param update url $URL
;;

updateCount)
check_required_param updateCount username $USERNAME
check_required_param updateCount password $PASSWORD
check_required_param updateCount classpath $CLASSPATH
check_required_param updateCount changeLogFile $CHANGELOGFILE
check_required_param updateCount url $URL
check_required_param updateCount count $COUNT true
;;

tag)
check_required_param tag username $USERNAME
check_required_param tag password $PASSWORD
check_required_param tag url $URL
check_required_param tag tag $TAG true
;;

updateToTag)
check_required_param updateToTag username $USERNAME
check_required_param updateToTag password $PASSWORD
check_required_param updateToTag classpath $CLASSPATH
check_required_param updateToTag changeLogFile $CHANGELOGFILE
check_required_param updateToTag url $URL
check_required_param updateToTag tag $TAG true
;;

rollback)
check_required_param rollback username $USERNAME
check_required_param rollback password $PASSWORD
check_required_param rollback classpath $CLASSPATH
check_required_param rollback changeLogFile $CHANGELOGFILE
check_required_param rollback url $URL
check_required_param rollback tag $TAG true
;;

rollbackCount)
check_required_param rollbackCount username $USERNAME
check_required_param rollbackCount password $PASSWORD
check_required_param rollbackCount classpath $CLASSPATH
check_required_param rollbackCount changeLogFile $CHANGELOGFILE
check_required_param rollbackCount url $URL
check_required_param rollbackCount count $COUNT true
;;

rollbackToDate)
check_required_param rollbackToDate username $USERNAME
check_required_param rollbackToDate password $PASSWORD
check_required_param rollbackToDate classpath $CLASSPATH
check_required_param rollbackToDate changeLogFile $CHANGELOGFILE
check_required_param rollbackToDate url $URL
check_required_param rollbackToDate date $DATE true
;;

updateSQL)
check_required_param updateSQL username $USERNAME
check_required_param updateSQL password $PASSWORD
check_required_param updateSQL classpath $CLASSPATH
check_required_param updateSQL changeLogFile $CHANGELOGFILE
check_required_param updateSQL url $URL
;;

futureRollbackSQL)
check_required_param futureRollbackSQL username $USERNAME
check_required_param futureRollbackSQL password $PASSWORD
check_required_param futureRollbackSQL classpath $CLASSPATH
check_required_param futureRollbackSQL changeLogFile $CHANGELOGFILE
check_required_param futureRollbackSQL url $URL true
;;

status)
check_required_param status username $USERNAME
check_required_param status password $PASSWORD
check_required_param status classpath $CLASSPATH
check_required_param status changeLogFile $CHANGELOGFILE
check_required_param status url $URL
;;

history)
check_required_param history username $USERNAME
check_required_param history password $PASSWORD
check_required_param history url $URL
;;

diff)
check_required_param diff username $USERNAME
check_required_param diff password $PASSWORD
check_required_param diff url $URL
check_required_param diff referenceUrl $REFERENCEURL true
;;

validate)
check_required_param validate username $USERNAME
check_required_param validate password $PASSWORD
check_required_param validate url $URL
check_required_param validate changeLogFile $CHANGELOGFILE
;;

"checks run")
check_required_param "checks run" changeLogFile $CHANGELOGFILE
check_required_param "checks run" checksSettingsFile $CHECKSSETTINGSFILE false true
;;

*)
echo "$OPERATION is not a valid operation"
exit 1
;;
esac
}

check_required_param $OPERATION username $USERNAME
check_required_param $OPERATION password $PASSWORD
check_optional_param "$OPERATION" proLicenseKey $PROLICENSEKEY
check_optional_param "$OPERATION" hubApiKey $HUBAPIKEY
validate_operation

docker-entrypoint.sh "${PARAMS[@]}" $OPERATION "${VALUES[@]}"
docker-entrypoint.sh "${PARAMS[@]}" $OPERATION "${VALUES[@]}" "${SECONDPARAMS[@]}"

0 comments on commit 7377186

Please sign in to comment.