Updated Linux YAML to contain auto-trigger on PRs #1
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
# This is a basic workflow to help you get started with Actions | |
name: GitHub-Flyway-AutoPilot-Pipeline-Linux | |
on: | |
pull_request: | |
branches: | |
- main | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
env: | |
# Enable this for additional debug logging | |
ACTIONS_RUNNER_DEBUG: false | |
### Step 1: Define Environment Secrets ### | |
### Environment Secrets - Create Environment Secrets ### | |
### Navigate to Settings > Secrets & Variables > Actions | |
# FLYWAY_EMAIL: Enter the email address linked to the Redgate Account that created the PAT | |
# FLYWAY_TOKEN: Enter the PAT Value (This should be treated like a password and thus as a secure variable. | |
# TARGET_DATABASE_USERNAME: Leave blank if using integratedSecurity (default). | |
# TARGET_DATABASE_PASSWORD: Leave blank if using integratedSecurity (default). | |
# CUSTOM_PARAMS: Optional - Used for passing custom Flyway Parameters to each Flyway command | |
### End of Environment Variables ### | |
# Step 3: Authenticate Flyway with Personal Access Tokens (PATs) | |
# Details on how to do this can be found here: https://documentation.red-gate.com/flyway/flyway-cli-and-api/tutorials/tutorial-personal-access-tokens | |
# Documentation on all available Authentication methods can be found here: https://documentation.red-gate.com/fd/flyway-licensing-263061944.html | |
FLYWAY_EMAIL: "${{ secrets.FLYWAY_EMAIL }}" # Enter the email address linked to the Redgate Account that created the PAT | |
FLYWAY_TOKEN: "${{ secrets.FLYWAY_TOKEN }}" # Enter the PAT Value (This should be treated like a password and thus as a secure variable. | |
BASELINE_VERSION: "001" # This should match the version number of your baseline script | |
FIRST_UNDO_SCRIPT: "002" # This should match the first undo version in your project | |
# Optional - Validate Flyway CLI installation for ephemeral agents | |
FLYWAY_CLI_INSTALL_CHECK: "${{ secrets.FLYWAY_CLI_INSTALL_CHECK }}" # Setting to false will skip the Flyway CLI check step | |
FLYWAY_VERSION: "Latest" # This outlines the version of Flyway CLI that will be downloaded if no Flyway CLI is detected on the target agent (Examples - '11.0.0' for specific version. Or 'Latest' for latest version) | |
FLYWAY_INSTALL_DIRECTORY: "" # The path on the agent machine where Flyway CLI will be installed | |
# Optional: Side Quest #1 - Setup Flyway Pipeline Integration - https://flyway.red-gate.com/ For More Details | |
FLYWAY_PUBLISH_RESULT: "true" # Set this value to true to enable Flyway Pipelines and track your releases centrally! | |
FLYWAY_DRIFT_ON_MIGRATE: "true" # Set this value to true to enable Flyway Pipelines drift detection and track your drift centrally! | |
### DO NOT EDIT BELOW THIS LINE - All variables set in the above section will be consumed by the jobs below and therefore do not require any updates to function ### | |
jobs: | |
# This workflow contains a single job called "build" | |
build: | |
name: Deploy Build | |
# The type of runner that the job will run on | |
runs-on: "self-hosted" # Options - self-hosted/ubuntu-latest/windows-latest (See here for more details on GitHub hosted runners - https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners) | |
environment: 'build' | |
env: | |
stage: 'Build' | |
displayName: 'Build' | |
DATABASE_NAME: 'AutoPilotBuild' | |
ENVIRONMENT: 'Build' # This variable refers to the environment name present in the Flyway Projects TOML file. | |
TARGET_DATABASE_USERNAME: "${{ secrets.TARGET_DATABASE_USERNAME }}" | |
TARGET_DATABASE_PASSWORD: "${{ secrets.TARGET_DATABASE_PASSWORD }}" | |
CUSTOM_PARAMS: "${{ secrets.CUSTOM_PARAMS }}" # Secure method of adding custom Flyway Parameters (Example -X for debug) | |
EXECUTE_BUILD: 'true' # Turn to false to skip the build stage tasks | |
publishArtifacts: 'true' # Turn to false to skip the artifact upload | |
steps: | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
- uses: actions/checkout@v4 | |
# Optional - If Enabled, Flyway CLI will be validated and installed if not present | |
- name: Flyway - CLI Automatic Validation and Install | |
run: bash ${{ GITHUB.WORKSPACE }}/Scripts/Flyway_DownloadAndInstallCLI_Unix.sh | |
if: env.FLYWAY_CLI_INSTALL_CHECK == 'true' | |
# Step 1 - Flyway License Authentication # | |
- name: Flyway Authentication | |
if: ${{ env.EXECUTE_BUILD == 'true' && success() }} | |
run: | | |
flyway auth -IAgreeToTheEula -email="${{ env.FLYWAY_EMAIL }}" -token="${{ env.FLYWAY_TOKEN }}" | |
# Step 2 - Ensure the Build Database is cleaned of all objects, meaning the build starts from scratch | |
- name: Clean Build DB | |
if: ${{ env.EXECUTE_BUILD == 'true' && success() }} | |
run: | | |
flyway info clean info -environment="${{ env.ENVIRONMENT }}" -user="${{ env.TARGET_DATABASE_USERNAME }}" -password="${{ env.TARGET_DATABASE_PASSWORD }}" -configFiles="${{ GITHUB.WORKSPACE }}/flyway.toml" -locations="filesystem:${{ GITHUB.WORKSPACE }}/migrations" -cleanDisabled='false' ${{ env.CUSTOM_PARAMS }} | |
# Step 3 - Migrate all scripts from the migration folder, to verify they can be deployed against an empty database. This is the quickest way to get feedback about problematic scripts | |
- name: Migrate Build DB | |
if: ${{ env.EXECUTE_BUILD == 'true' && success() }} | |
run: | | |
flyway info migrate info -environment="${{ env.ENVIRONMENT }}" -user="${{ env.TARGET_DATABASE_USERNAME }}" -password="${{ env.TARGET_DATABASE_PASSWORD }}" -configFiles="${{ GITHUB.WORKSPACE }}/flyway.toml" -locations="filesystem:${{ GITHUB.WORKSPACE }}/migrations" -cleanDisabled='false' -baselineOnMigrate="true" "-publishResult=${{ env.FLYWAY_PUBLISH_RESULT }}" "-flywayServicePublish.publishReport=${{ env.FLYWAY_PUBLISH_RESULT }}" "-reportEnabled=${{ env.FLYWAY_PUBLISH_RESULT }}" ${{ env.CUSTOM_PARAMS }} | |
# Step 4 (Optional) - Undo all relevant migrations using corresponding rollback script, to validate they can be run. This helps to reduce the chance the script will fail during a real life rollback scenario | |
- name: undo Build DB | |
if: ${{ env.EXECUTE_BUILD == 'true' && success() }} | |
run: | | |
flyway info undo info -environment="${{ env.ENVIRONMENT }}" -user=${{ env.TARGET_DATABASE_USERNAME }} -password=${{ env.TARGET_DATABASE_PASSWORD }} -configFiles="${{ GITHUB.WORKSPACE }}/flyway.toml" -locations="filesystem:${{ GITHUB.WORKSPACE }}/migrations" -baselineOnMigrate="true" -cleanDisabled='false' -target="${{ env.FIRST_UNDO_SCRIPT }}" ${{ env.CUSTOM_PARAMS }} | |
# GitHub - After migration scripts are validated, publish them as an artifact | |
- name: Publish Validated Migration Scripts as Artifact | |
if: ${{ env.publishArtifacts == 'true' && success() }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: flyway-build-artifact-${{ github.run_number }} | |
path: | | |
!${{ GITHUB.WORKSPACE }}/flyway-*/**/* | |
!${{ GITHUB.WORKSPACE }}/.git/**/* | |
!${{ GITHUB.WORKSPACE }}/.git*/**/* | |
${{ GITHUB.WORKSPACE }}/**/schema-model/**/* | |
${{ GITHUB.WORKSPACE }}/**/migrations/**/* | |
${{ GITHUB.WORKSPACE }}/**/Scripts/**/* | |
${{ GITHUB.WORKSPACE }}/**/backups/**/* | |
${{ GITHUB.WORKSPACE }}/**/flyway.toml | |
${{ GITHUB.WORKSPACE }}/**/Filter.scpf | |
test: | |
name: Deploy Test | |
# The type of runner that the job will run on | |
runs-on: "self-hosted" # Options - self-hosted/ubuntu-latest/windows-latest (See here for more details on GitHub hosted runners - https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners) | |
environment: 'test' # This refers to GitHub's Environment name | |
if: ${{ true }} #Set this variable to false to temporarily disable the job | |
needs: build | |
env: | |
stage: 'Test' | |
DATABASE_NAME: "AutoPilotTest" | |
ENVIRONMENT: "Test" # Refers to the environment in the Flyway Project TOML file. | |
TARGET_DATABASE_USERNAME: "${{ secrets.TARGET_DATABASE_USERNAME }}" | |
TARGET_DATABASE_PASSWORD: "${{ secrets.TARGET_DATABASE_PASSWORD }}" | |
REPORT_ENVIRONMENT: "Check" | |
REPORT_DATABASE_USERNAME: "${{ secrets.TARGET_DATABASE_USERNAME }}" # Optional - Change to a different secret if the connection details for the report database differs from the target | |
REPORT_DATABASE_PASSWORD: "${{ secrets.TARGET_DATABASE_PASSWORD }}" # Optional - Change to a different secret if the connection details for the report database differs from the target | |
CUSTOM_PARAMS: "${{ secrets.CUSTOM_PARAMS }}" # Secure method of adding custom Flyway Parameters (Example -X for debug) | |
generateReport: 'true' # Turn to false to skip the CHECK report stage tasks | |
FLYWAY_CHECK_DRIFT_ON_MIGRATE: 'true' # Turn to false to skip the Drift Report upload to Flyway Pipelines (If enabled) | |
# 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/download-artifact@v4 | |
with: | |
name: flyway-build-artifact-${{ github.run_number }} | |
# Optional - List out all build artifact files on disk, helpful for debugging | |
- name: Display structure of downloaded files | |
run: ls -R | |
# Optional - If Enabled, Flyway CLI will be validated and installed if not present | |
- name: Flyway - CLI Automatic Validation and Install | |
run: bash ${{ GITHUB.WORKSPACE }}/Scripts/Flyway_DownloadAndInstallCLI_Unix.sh | |
if: env.FLYWAY_CLI_INSTALL_CHECK == 'true' | |
# Step 1 - Flyway License Authentication # | |
- name: Flyway Authentication | |
if: success() | |
run: | | |
flyway auth -IAgreeToTheEula -email="${{ env.FLYWAY_EMAIL }}" -token="${{ env.FLYWAY_TOKEN }}" | |
# Step 2 - Create Check Report | |
- name: Create Check Reports | |
if: ${{ env.generateReport == 'true' && success() }} | |
run: | | |
flyway check -dryrun -changes -drift -environment="${{ env.ENVIRONMENT }}" -user=${{ env.TARGET_DATABASE_USERNAME }} -password=${{ env.TARGET_DATABASE_PASSWORD }} -configFiles="${{ GITHUB.WORKSPACE }}/flyway.toml" -locations="filesystem:${{ GITHUB.WORKSPACE }}/migrations" "-check.buildEnvironment=${{ env.REPORT_ENVIRONMENT }}" "-environments.${{ env.REPORT_ENVIRONMENT }}.user=${{ env.REPORT_DATABASE_USERNAME }}" "-environments.${{ env.REPORT_ENVIRONMENT }}.password=${{ env.REPORT_DATABASE_PASSWORD }}" "-reportFilename=${{ GITHUB.WORKSPACE }}/reports/${{ env.DATABASE_NAME }}-Run-${{ GITHUB.RUN_ID }}-${{ env.ENVIRONMENT }}-Check-Report.html" "-publishResult=${{ env.FLYWAY_PUBLISH_RESULT }}" "-flywayServicePublish.publishReport=${{ env.FLYWAY_PUBLISH_RESULT }}" "-reportEnabled=${{ env.FLYWAY_PUBLISH_RESULT }}" ${{ env.CUSTOM_PARAMS }} | |
continue-on-error: true | |
# Step 3 - Publish Check Report | |
- name: Publish Check Report as Artifact | |
if: ${{ env.generateReport == 'true' && success() }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: flyway-reports-test | |
path: ${{ GITHUB.WORKSPACE }}/reports/**/* | |
# Step 4 - Deploy pending migrations to target database | |
- name: Migrate Test DB | |
if: success() | |
run: | | |
flyway info migrate info -environment="${{ env.ENVIRONMENT }}" -user="${{ env.TARGET_DATABASE_USERNAME }}" -password="${{ env.TARGET_DATABASE_PASSWORD }}" -baselineOnMigrate="true" -configFiles="${{ GITHUB.WORKSPACE }}/flyway.toml" -locations="filesystem:${{ GITHUB.WORKSPACE }}/migrations" "-publishResult=${{ env.FLYWAY_PUBLISH_RESULT }}" "-flywayServicePublish.publishReport=${{ env.FLYWAY_PUBLISH_RESULT }}" "-reportEnabled=${{ env.FLYWAY_PUBLISH_RESULT }}" ${{ env.CUSTOM_PARAMS }} | |
prod: | |
name: Deploy Prod | |
# The type of runner that the job will run on | |
runs-on: "self-hosted" # Options - self-hosted/ubuntu-latest/windows-latest (See here for more details on GitHub hosted runners - https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners) | |
environment: 'prod' | |
if: ${{ true }} #Set this variable to false to temporarily disable the job | |
needs: test | |
env: | |
stage: 'Prod' | |
DATABASE_NAME: "AutoPilotProd" | |
ENVIRONMENT: "Prod" # Refers to the environment name in the Flyway Project TOML file. | |
TARGET_DATABASE_USERNAME: "${{ secrets.TARGET_DATABASE_USERNAME }}" | |
TARGET_DATABASE_PASSWORD: "${{ secrets.TARGET_DATABASE_PASSWORD }}" | |
REPORT_ENVIRONMENT: "Check" | |
REPORT_DATABASE_USERNAME: "${{ secrets.TARGET_DATABASE_USERNAME }}" # Optional - Change to a different secret if the connection details for the report database differs from the target | |
REPORT_DATABASE_PASSWORD: "${{ secrets.TARGET_DATABASE_PASSWORD }}" # Optional - Change to a different secret if the connection details for the report database differs from the target | |
CUSTOM_PARAMS: "${{ secrets.CUSTOM_PARAMS }}" # Secure method of adding custom Flyway Parameters (Example -X for debug) | |
generateReport: 'true' # Turn to false to skip the CHECK report stage tasks | |
FLYWAY_CHECK_DRIFT_ON_MIGRATE: 'true' # Turn to false to skip the Drift Report upload to Flyway Pipelines (If enabled) | |
steps: | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
- uses: actions/download-artifact@v4 | |
with: | |
name: flyway-build-artifact-${{ github.run_number }} | |
# Optional - List out all build artifact files on disk, helpful for debugging | |
- name: Display structure of downloaded files | |
run: ls -R | |
# Optional - If Enabled, Flyway CLI will be validated and installed if not present | |
- name: Flyway - CLI Automatic Validation and Install | |
run: bash ${{ GITHUB.WORKSPACE }}/Scripts/Flyway_DownloadAndInstallCLI_Unix.sh | |
if: env.FLYWAY_CLI_INSTALL_CHECK == 'true' | |
# Step 1 - Flyway License Authentication # | |
- name: Flyway Authentication | |
if: success() | |
run: | | |
flyway auth -IAgreeToTheEula -email="${{ env.FLYWAY_EMAIL }}" -token="${{ env.FLYWAY_TOKEN }}" | |
# Step 2 - Create Check Report | |
- name: Create Check Reports | |
if: ${{ env.generateReport == 'true' && success() }} | |
run: | | |
flyway check -dryrun -changes -drift -environment="${{ env.ENVIRONMENT }}" -user=${{ env.TARGET_DATABASE_USERNAME }} -password=${{ env.TARGET_DATABASE_PASSWORD }} -configFiles="${{ GITHUB.WORKSPACE }}/flyway.toml" -locations="filesystem:${{ GITHUB.WORKSPACE }}/migrations" "-check.buildEnvironment=${{ env.REPORT_ENVIRONMENT }}" "-environments.${{ env.REPORT_ENVIRONMENT }}.user=${{ env.REPORT_DATABASE_USERNAME }}" "-environments.${{ env.REPORT_ENVIRONMENT }}.password=${{ env.REPORT_DATABASE_PASSWORD }}" "-reportFilename=${{ GITHUB.WORKSPACE }}/reports/${{ env.DATABASE_NAME }}-Run-${{ GITHUB.RUN_ID }}-${{ env.ENVIRONMENT }}-Check-Report.html" "-publishResult=${{ env.FLYWAY_PUBLISH_RESULT }}" "-flywayServicePublish.publishReport=${{ env.FLYWAY_PUBLISH_RESULT }}" "-reportEnabled=${{ env.FLYWAY_PUBLISH_RESULT }}" ${{ env.CUSTOM_PARAMS }} | |
continue-on-error: true | |
# Step 3 - Publish Check Report | |
- name: Publish Check Report as Artifact | |
if: ${{ env.generateReport == 'true' && success() }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: flyway-reports-prod | |
path: ${{ GITHUB.WORKSPACE }}/reports/**/* | |
# Step 4 - Deploy pending migrations to target database | |
- name: Migrate Production DB | |
if: success() | |
run: | | |
flyway info migrate info -environment="${{ env.ENVIRONMENT }}" -user="${{ env.TARGET_DATABASE_USERNAME }}" -password="${{ env.TARGET_DATABASE_PASSWORD }}" -baselineOnMigrate="true" -configFiles="${{ GITHUB.WORKSPACE }}/flyway.toml" -locations="filesystem:${{ GITHUB.WORKSPACE }}/migrations" "-publishResult=${{ env.FLYWAY_PUBLISH_RESULT }}" "-flywayServicePublish.publishReport=${{ env.FLYWAY_PUBLISH_RESULT }}" "-reportEnabled=${{ env.FLYWAY_PUBLISH_RESULT }}" ${{ env.CUSTOM_PARAMS }} |