Example GitHub Action for State-based pipelines
Published 14 May 2025
ENTERPRISE
Deploy
The following example deploys the schema model to a target database whose connection information is stored as a secret.
This example shows how to automate "prepare" and "deploy" in one leap. In practice, most teams split these into separate steps so the generated script can be reviewed and approved before it’s applied to production.
Automating state-based deployments is available in Flyway Enterprise and a personal access token and email address need to be provided. These should also be provided as secrets.
name: Redgate Flyway
on:
push:
branches:
- main
jobs:
deploy:
name: Redgate Flyway Deploy
runs-on: ubuntu-latest
env:
FLYWAY_EMAIL: ${{ secrets.FLYWAY_EMAIL }}
FLYWAY_TOKEN: ${{ secrets.FLYWAY_TOKEN }}
steps:
- name: Setup Flyway
uses: red-gate/setup-flyway@v1
- name: Redgate Flyway Deploy
run: |
flyway prepare deploy \
-prepare.source=schemaModel \
-prepare.target=production \
-environment=production
-environments.production.url="${{ secrets.FLYWAY_URL }}" \
-environments.production.user="${{ secrets.FLYWAY_USER }}" \
-environments.production.password="${{ secrets.FLYWAY_PASSWORD }}"
Deploy (with manual review)
The following example deploys the schema model to a target database whose connection information is stored as a secret.
A GitHub Environment named "Production" is used to control the deployment and stop the workflow until the deployment is approved. For details on how to configure an Environment to require a review before deployment see the GitHub documentation. Please note this feature is not available for private repositories on the GitHub free plan.
Automating state-based deployments is available in Flyway Enterprise and a personal access token and email address need to be provided. These should also be provided as secrets.
name: Redgate Flyway
on:
push:
branches:
- main
jobs:
prepare:
name: Redgate Flyway Prepare
runs-on: ubuntu-latest
env:
FLYWAY_EMAIL: ${{ secrets.FLYWAY_EMAIL }}
FLYWAY_TOKEN: ${{ secrets.FLYWAY_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Flyway
uses: red-gate/setup-flyway@v1
- name: Redgate Flyway Prepare
run: |
flyway prepare \
-prepare.source=schemaModel \
-prepare.target=production \
-environments.production.url="${{ secrets.FLYWAY_URL }}" \
-environments.production.user="${{ secrets.FLYWAY_USER }}" \
-environments.production.password="${{ secrets.FLYWAY_PASSWORD }}"
- name: Upload Deployment Script
uses: actions/upload-artifact@v4
with:
name: database-deployment-script
path: deployments/D__deployment.sql
deploy:
name: Redgate Flyway Deploy
runs-on: ubuntu-latest
needs: prepare
environment:
name: Production
env:
FLYWAY_EMAIL: ${{ secrets.FLYWAY_EMAIL }}
FLYWAY_TOKEN: ${{ secrets.FLYWAY_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Flyway
uses: red-gate/setup-flyway@v1
- name: Download Deployment Script
uses: actions/download-artifact@v4
with:
name: database-deployment-script
path: deployments
- name: Redgate Flyway Deploy
run: |
flyway deploy \
-environment=production \
-environments.production.url="${{ secrets.FLYWAY_URL }}" \
-environments.production.user="${{ secrets.FLYWAY_USER }}" \
-environments.production.password="${{ secrets.FLYWAY_PASSWORD }}"Additional examples
See additional examples using Windows and Linux agents for our sample Flyway Autopilot project on GitHub.