Skip to content

Commit cf63fb1

Browse files
2 parents f84e04b + 63c0494 commit cf63fb1

3 files changed

Lines changed: 88 additions & 89 deletions

File tree

github-actions/workflows/deploy-build.yml

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,47 @@ on:
44
branches:
55
- Development
66
paths:
7-
- 'migrations/**'
7+
- "migrations/**"
88

99
# Environment Variables
1010
env:
11-
# Repository Variables - Create these in Project Settings > Variables > Actions
12-
EMAIL: ${{ vars.USER_EMAIL }} # Use with ${{ env.EMAIL }}
13-
DB_SERVER: ${{ vars.DB_SERVER }}
14-
DB_Build: ${{ vars.DB_NAME_Build }}
15-
ENCRYPT: ${{ vars.ENCRYPT_BOOL }}
16-
TRUST_CERT: ${{ vars.TRUST_CERT_BOOL }}
17-
# BASELINE_VERSION: ${{ vars.BASELINE_VERSION }}
18-
19-
# Repository Secrets - Create these in Project Settings > Secrets > Actions
20-
TOKEN: ${{ secrets.FLYWAY_TOKEN }}
21-
DB_USER_Build: ${{ secrets.DB_USER_NAME_QA }}
22-
DB_USER_PW_Build: ${{ secrets.DB_USER_PW_QA }}
23-
FIRST_UNDO_SCRIPT: ${{ secrets.FIRST_UNDO_SCRIPT }} # Validates all undo scripts up to and including the specified script
24-
11+
# Repository Variables - Create these in Project Settings > Variables > Actions
12+
EMAIL: ${{ vars.USER_EMAIL }} # Use with ${{ env.EMAIL }}
13+
JDBC_BUILD: ${{ vars.JDBC_BUILD }}
14+
# BASELINE_VERSION: ${{ vars.BASELINE_VERSION }}
2515

16+
# Repository Secrets - Create these in Project Settings > Secrets > Actions
17+
TOKEN: ${{ secrets.FLYWAY_TOKEN }}
18+
DB_USER_Build: ${{ secrets.DB_USER_NAME_QA }}
19+
DB_USER_PW_Build: ${{ secrets.DB_USER_PW_QA }}
20+
FIRST_UNDO_SCRIPT: ${{ secrets.FIRST_UNDO_SCRIPT }} # Validates all undo scripts up to and including the specified script
2621

2722
# jobs are the steps executed in the workflow
2823
jobs:
29-
flyway-build: # Job name
30-
runs-on: self-hosted # Runner to execute the job
31-
# runs-on: ubuntu-latest
32-
defaults:
33-
run:
34-
shell: cmd # Default shell. Use Windows Command Prompt
35-
36-
steps: # Steps are the individual tasks that are executed in the job
37-
- name: Checkout Repository # Step to check out the repository
38-
uses: actions/checkout@v4
39-
with:
40-
ref: "Development" # Branch to check out
41-
fetch-depth: 0 # Fetch the entire history to avoid shallow clone issues
42-
clean: true # Ensure the repository is cleaned before the workflow runs
24+
flyway-build: # Job name
25+
runs-on: self-hosted # Runner to execute the job
26+
# runs-on: ubuntu-latest
27+
defaults:
28+
run:
29+
shell: cmd # Default shell. Use Windows Command Prompt
30+
steps: # Steps are the individual tasks that are executed in the job
31+
- name: Checkout Repository # Step to check out the repository
32+
uses: actions/checkout@v4
33+
with:
34+
ref: "Development" # Branch to check out
35+
fetch-depth: 0 # Fetch the entire history to avoid shallow clone issues
36+
clean: true # Ensure the repository is cleaned before the workflow runs
37+
38+
# Runs the Flyway Clean command against the Build database
39+
- name: Clean Build DB
40+
run: |
41+
flyway -email=${{ env.EMAIL }} -token=${{ env.TOKEN }} info clean info -cleanDisabled="false" -user=${{ env.DB_USER_Build }} -password=${{ env.DB_USER_PW_Build }} -url=${{ env.JDBC_BUILD }} -IAgreeToTheEula -locations="filesystem:${{ github.workspace }}/migrations" -configFiles="${{ github.workspace }}/flyway.toml" -baselineOnMigrate=true -errorOverrides=S0001:0:I-
4342
43+
- name: Migrate Build # Step to run Flyway migrations
44+
# To use username and password instead of windows integrated security Ensure that SQL Server is configured to allow SQL Server authentication. You can check this in SQL Server Management Studio (SSMS) under the server properties -> Security -> Server authentication. Ensure "SQL Server and Windows Authentication mode" is selected.
45+
run: flyway -email=${{ env.EMAIL }} -token=${{ env.TOKEN }} migrate -cleanDisabled="false" -user=${{ env.DB_USER_Build }} -password=${{ env.DB_USER_PW_Build }} -url=${{ env.JDBC_BUILD }} -IAgreeToTheEula -locations="filesystem:${{ github.workspace }}/migrations" -configFiles="${{ github.workspace }}/flyway.toml" -baselineOnMigrate=true -errorOverrides=S0001:0:I-
46+
working-directory: ./migrations
4447

45-
# Runs the Flyway Clean command against the Build database
46-
- name: Clean Build DB
47-
run: |
48-
flyway -email=${{ env.EMAIL }} -token=${{ env.TOKEN }} info clean info -cleanDisabled="false" -user=${{ env.DB_USER_Build }} -password=${{ env.DB_USER_PW_Build }} -url="${{ env.DB_SERVER }};databaseName=${{ env.DB_Build }};encrypt=${{ env.ENCRYPT }};trustServerCertificate=${{ env.TRUST_CERT }}" -IAgreeToTheEula -locations="filesystem:${{ github.workspace }}/migrations" -configFiles="${{ github.workspace }}/flyway.toml" -baselineOnMigrate=true -errorOverrides=S0001:0:I-
49-
50-
- name: Migrate Build # Step to run Flyway migrations
51-
# To use username and password instead of windows integrated security Ensure that SQL Server is configured to allow SQL Server authentication. You can check this in SQL Server Management Studio (SSMS) under the server properties -> Security -> Server authentication. Ensure "SQL Server and Windows Authentication mode" is selected.
52-
run: flyway -email=${{ env.EMAIL }} -token=${{ env.TOKEN }} migrate -cleanDisabled="false" -user=${{ env.DB_USER_Build }} -password=${{ env.DB_USER_PW_Build }} -url="${{ env.DB_SERVER }};databaseName=${{ env.DB_Build }};encrypt=${{ env.ENCRYPT }};trustServerCertificate=${{ env.TRUST_CERT }}" -IAgreeToTheEula -locations="filesystem:${{ github.workspace }}/migrations" -configFiles="${{ github.workspace }}/flyway.toml" -baselineOnMigrate=true -errorOverrides=S0001:0:I-
53-
working-directory: ./migrations
54-
55-
- name: Rollback Build # Step to run Flyway migrations
56-
run: flyway -email=${{ env.EMAIL }} -token=${{ env.TOKEN }} undo -cleanDisabled="false" -user=${{ env.DB_USER_Build }} -password=${{ env.DB_USER_PW_Build }} -url="${{ env.DB_SERVER }};databaseName=${{ env.DB_Build }};encrypt=${{ env.ENCRYPT }};trustServerCertificate=${{ env.TRUST_CERT }}" -target="${{ env.FIRST_UNDO_SCRIPT }}" -IAgreeToTheEula -locations="filesystem:${{ github.workspace }}/migrations" -configFiles="${{ github.workspace }}/flyway.toml" -baselineOnMigrate=true -errorOverrides=S0001:0:I-
57-
working-directory: ./migrations
48+
- name: Rollback Build # Step to run Flyway migrations
49+
run: flyway -email=${{ env.EMAIL }} -token=${{ env.TOKEN }} undo -cleanDisabled="false" -user=${{ env.DB_USER_Build }} -password=${{ env.DB_USER_PW_Build }} -url=${{ env.JDBC_BUILD }} -target=${{ env.FIRST_UNDO_SCRIPT }} -IAgreeToTheEula -locations="filesystem:${{ github.workspace }}/migrations" -configFiles="${{ github.workspace }}/flyway.toml" -baselineOnMigrate=true -errorOverrides=S0001:0:I-
50+
working-directory: ./migrations

github-actions/workflows/deploy-prod.yml

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,92 +3,103 @@ on:
33
push:
44
branches:
55
- Production
6-
# paths:
7-
# - 'migrations/**'
6+
paths:
7+
- "migrations/**"
88

99
# Environment Variables
1010
env:
1111
# Repository Variables - Create these in Project Settings > Variables > Actions
1212
EMAIL: ${{ vars.USER_EMAIL }} # Use with ${{ env.EMAIL }}
13-
DB_SERVER: ${{ vars.DB_SERVER }}
14-
DB_CHECK: ${{ vars.DB_NAME_CHECK }}
15-
DB_PROD_1: ${{ vars.DB_NAME_PROD_1 }}
16-
DB_PROD_2: ${{ vars.DB_NAME_PROD_2 }}
17-
ENCRYPT: ${{ vars.ENCRYPT_BOOL }}
18-
TRUST_CERT: ${{ vars.TRUST_CERT_BOOL }}
19-
# BASELINE_VERSION: ${{ vars.BASELINE_VERSION }}
20-
13+
JDBC_PROD1: ${{ vars.JDBC_PROD1 }}
14+
JDBC_PROD2: ${{ vars.JDBC_PROD2 }}
15+
JDBC_CHECK: ${{ vars.JDBC_CHECK }}
16+
DB_PROD_2: ${{ vars.DB_NAME_PROD_2 }} # Used in report filename
17+
2118
# Repository Secrets - Create these in Project Settings > Secrets > Actions
22-
TOKEN: ${{ secrets.FLYWAY_TOKEN }}
19+
TOKEN: ${{ secrets.FLYWAY_TOKEN }}
2320
DB_USER_PROD: ${{ secrets.DB_USER_NAME_QA }}
2421
DB_USER_PW_PROD: ${{ secrets.DB_USER_PW_QA }}
25-
# FIRST_UNDO_SCRIPT: ${{ secrets.FIRST_UNDO_SCRIPT }} # Validates all undo scripts up to and including the specified script
26-
PROD_1_JDBC: "${{ vars.DB_SERVER }};databaseName=${{ vars.DB_NAME_PROD_1 }};encrypt=${{ vars.ENCRYPT_BOOL }};trustServerCertificate=${{ vars.TRUST_CERT_BOOL }}"
27-
PROD_2_JDBC: "${{ vars.DB_SERVER }};databaseName=${{ vars.DB_NAME_PROD_2 }};encrypt=${{ vars.ENCRYPT_BOOL }};trustServerCertificate=${{ vars.TRUST_CERT_BOOL }}"
28-
CHECK_JDBC: "${{ vars.DB_SERVER }};databaseName=${{ vars.DB_CHECK }};encrypt=${{ vars.ENCRYPT_BOOL }};trustServerCertificate=${{ vars.TRUST_CERT_BOOL }}"
29-
3022
# End of Environment Secrets #
23+
3124
generateDriftAndChangeReport: true
3225
failReleaseIfDriftDetected: false
3326
staticCodeAnalysis: false #Currently not setup in this pipeline
3427
publishArtifacts: true
3528

3629
# jobs are the steps executed in the workflow
30+
# Rules location -check.rulesLocation="$(Build.SourcesDirectory)\templates\rules"
3731
jobs:
38-
39-
flyway-report-prod:
32+
flyway-report:
4033
name: Generate Report
4134
runs-on: self-hosted # Runner to execute the job
4235
defaults:
4336
run:
4437
shell: cmd # Default shell. Use Windows Command Prompt
45-
38+
4639
steps: # Steps are the individual tasks that are executed in the job
4740
- uses: actions/checkout@v4 # Check out the repository
4841
with: # Additional options for the action
4942
ref: "Production" # Branch to check out
5043

5144
- name: Create Drift and Change Report
5245
run: |
53-
flyway -email=${{ env.EMAIL }} -token=${{ env.TOKEN }} check -dryrun -changes -drift -check.buildUser=${{ env.DB_USER_PROD }} -check.buildPassword=${{ env.DB_USER_PW_PROD }} -check.buildEnvironment="${{ env.CHECK_JDBC }}" -user=${{ env.DB_USER_PROD }} -password=${{ env.DB_USER_PW_PROD }} -url="${{ env.DB_SERVER }};databaseName=${{ env.DB_PROD_2 }};encrypt=${{ env.ENCRYPT }};trustServerCertificate=${{ env.TRUST_CERT }}" -reportFilename="${{ github.workspace }}\reports\${{ env.DB_PROD_2 }}-Run-${{ github.run_id }}-Check-Report.html" -IAgreeToTheEula -locations="filesystem:${{ github.workspace }}/migrations" -configFiles="${{ github.workspace }}/flyway.toml" -baselineOnMigrate=true -errorOverrides=S0001:0:I-
46+
flyway -email=${{ env.EMAIL }} -token=${{ env.TOKEN }} check -code -changes -drift -dryrun -cleanDisabled="false" -user=${{ env.DB_USER_PROD }} -password=${{ env.DB_USER_PW_PROD }} -url=${{ env.JDBC_PROD2 }} -check.buildUser=${{ env.DB_USER_PROD }} -check.buildPassword=${{ env.DB_USER_PW_PROD }} -check.buildUrl="${{ env.JDBC_CHECK }}" -reportFilename="${{ github.workspace }}\reports\${{ env.DB_PROD_2 }}-Run-${{ github.run_id }}-Check-Report.html" -IAgreeToTheEula -locations="filesystem:${{ github.workspace }}\migrations" -configFiles="${{ github.workspace }}/flyway.toml" -baselineOnMigrate=true -errorOverrides=S0001:0:I-
5447
continue-on-error: true
5548

5649
# Create a directory to stage the artifact files
5750
- name: Stage files for publishing
5851
run: |
59-
xcopy /E /I "${{ github.workspace }}\reports" "Artifact_Files\Reports\"
52+
xcopy /E /I "C:\Projects\DemoDB\reports" "reports/"
6053
6154
- name: Publish Check Report as Artifact
6255
uses: actions/upload-artifact@v4
63-
with:
56+
with:
6457
name: flyway-reports
65-
path: Artifact_Files/Reports/
58+
path: reports/
6659

60+
# GitHub Actions doesn't natively support manual approval steps like some other CI/CD tools (e.g., Azure DevOps or GitLab).
61+
# You can achieve similar functionality using environments with required reviewers or by integrating external approval mechanisms.
62+
# Alternatively maybe a Review Branch prior to pulling to Production or another downstream environment.
6763

68-
flyway-deploy-prod:
64+
# Separate Prod 1 and Prod 2 into separate simulatneous jobs, only make one of them dependent on the manual approval step for demo purposes
65+
flyway-deploy-prod-1:
66+
name: Flyway Deploy Production 1
6967
runs-on: self-hosted # Runner to execute the job
7068
defaults:
7169
run:
7270
shell: cmd # Default shell. Use Windows Command Prompt
71+
needs: flyway-report # This job depends on the completion of the flyway-report job
7372

7473
steps: # Steps are the individual tasks that are executed in the job
7574
- uses: actions/checkout@v4 # Check out the repository
7675
with: # Additional options for the action
7776
ref: "Production" # Branch to check out
7877

79-
- name: Deploy to Prod 1 # Step to run Flyway migrations
80-
# To use username and password instead of windows integrated security Ensure that SQL Server is configured to allow SQL Server authentication. You can check this in SQL Server Management Studio (SSMS) under the server properties -> Security -> Server authentication. Ensure "SQL Server and Windows Authentication mode" is selected.
81-
run: flyway -email=${{ env.EMAIL }} -token=${{ env.TOKEN }} migrate -user=${{ env.DB_USER_PROD }} -password=${{ env.DB_USER_PW_PROD }} -url="${{ env.DB_SERVER }};databaseName=${{ env.DB_PROD_1 }};encrypt=${{ env.ENCRYPT }};trustServerCertificate=${{ env.TRUST_CERT }}" -IAgreeToTheEula -locations="filesystem:${{ github.workspace }}/migrations" -configFiles="${{ github.workspace }}/flyway.toml" -baselineOnMigrate=true -errorOverrides=S0001:0:I-
82-
# Multi-tenant deployment. Add second deployment to PROD2 here
78+
- name: Deploy Prod 1 # Step to run Flyway migrations
79+
# To use username and password instead of windows integrated security Ensure that SQL Server is configured to allow SQL Server authentication. You can check this in SQL Server Management Studio (SSMS) under the server properties -> Security -> Server authentication. Ensure "SQL Server and Windows Authentication mode" is selected.
80+
run: flyway -email=${{ env.EMAIL }} -token=${{ env.TOKEN }} migrate -user=${{ env.DB_USER_PROD }} -password=${{ env.DB_USER_PW_PROD }} -url="${{ env.JDBC_PROD1 }}" -IAgreeToTheEula -locations="filesystem:${{ github.workspace }}/migrations" -configFiles="${{ github.workspace }}/flyway.toml" -baselineOnMigrate=true -errorOverrides=S0001:0:I-
8381
working-directory: ./migrations
8482

85-
- name: Deploy to Prod 2 # Step to run Flyway migrations
86-
# To use username and password instead of windows integrated security Ensure that SQL Server is configured to allow SQL Server authentication. You can check this in SQL Server Management Studio (SSMS) under the server properties -> Security -> Server authentication. Ensure "SQL Server and Windows Authentication mode" is selected.
87-
run: flyway -email=${{ env.EMAIL }} -token=${{ env.TOKEN }} info migrate info -user=${{ env.DB_USER_PROD }} -password=${{ env.DB_USER_PW_PROD }} -url="${{ env.DB_SERVER }};databaseName=${{ env.DB_PROD_2 }};encrypt=${{ env.ENCRYPT }};trustServerCertificate=${{ env.TRUST_CERT }}" -IAgreeToTheEula -locations="filesystem:${{ github.workspace }}/migrations" -configFiles="${{ github.workspace }}/flyway.toml" -baselineOnMigrate=true -errorOverrides=S0001:0:I-
83+
flyway-deploy-prod-2:
84+
name: Flyway Deploy Production 2
85+
runs-on: self-hosted # Runner to execute the job
86+
defaults:
87+
run:
88+
shell: cmd # Default shell. Use Windows Command Prompt
89+
needs: flyway-report # This job depends on the completion of the flyway-report job
90+
91+
steps: # Steps are the individual tasks that are executed in the job
92+
- uses: actions/checkout@v4 # Check out the repository
93+
with: # Additional options for the action
94+
ref: "Production" # Branch to check out
95+
96+
# Multi-tenant deployment. PROD 2
97+
- name: Deploy Prod 2 # Step to run Flyway migrations
98+
run: flyway -email=${{ env.EMAIL }} -token=${{ env.TOKEN }} info migrate info -user=${{ env.DB_USER_PROD }} -password=${{ env.DB_USER_PW_PROD }} -url="${{ env.JDBC_PROD2 }}" -IAgreeToTheEula -locations="filesystem:${{ github.workspace }}/migrations" -configFiles="${{ github.workspace }}/flyway.toml" -baselineOnMigrate=true -errorOverrides=S0001:0:I-
8899
# Multi-tenant deployment. Add second deployment to PROD2 here
89100
working-directory: ./migrations
90101

91102
# Sample for integrated security instead of user name and password
92-
# -url="${{ env.DB_SERVER }};databaseName=${{ env.DB_PROD_1 }};encrypt=${{ env.ENCRYPT }};integratedSecurity=true;trustServerCertificate=${{ env.TRUST_CERT }}"
103+
# -url="jdbc:sqlserver://localhost;databaseName=DemoDBProd1;integratedSecurity=true;trustServerCertificate=true"
93104
# -baselineVersion=${{ env.BASELINE_VERSION }}
94-
# -user=${{ env.DB_USER_PROD }} -password=${{ env.DB_USER_PW_PROD }}
105+
# -user=${{ env.DB_USER_PROD }} -password=${{ env.DB_USER_PW_PROD }}
Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
1-
name: Flyway GitHub Actions QA Workflow
1+
name: Flyway GitHub Actions QA Workflow
22
on:
33
push:
44
branches:
55
- QA
66
paths:
7-
- 'migrations/**'
7+
- "migrations/**"
88

99
env:
10-
EMAIL: ${{ vars.USER_EMAIL }}
11-
DB_SERVER: ${{ vars.DB_SERVER }}
12-
DB_QA: ${{ vars.DB_NAME_QA }}
13-
ENCRYPT: ${{ vars.ENCRYPT_BOOL }}
14-
TRUST_CERT: ${{ vars.TRUST_CERT_BOOL }}
15-
TOKEN: ${{ secrets.FLYWAY_TOKEN }}
10+
# Variables - Create these in Project Settings > Variables > Actions
11+
EMAIL: ${{ vars.USER_EMAIL }}
12+
JDBC_QA: ${{ vars.JDBC_QA }}
13+
# Secrets - Create these in Project Settings > Secrets > Actions
14+
TOKEN: ${{ secrets.FLYWAY_TOKEN }}
1615
DB_USER_QA: ${{ secrets.DB_USER_NAME_QA }}
1716
DB_USER_PW_QA: ${{ secrets.DB_USER_PW_QA }}
18-
# BASELINE_VERSION: ${{ vars.BASELINE_VERSION }}
19-
# FIRST_UNDO_SCRIPT: ${{ secrets.FIRST_UNDO_SCRIPT }}
20-
2117

2218
jobs:
23-
flyway-deploy-qa:
19+
flyway-deploy-qa:
2420
runs-on: self-hosted # Runner to execute the job
2521
# runs-on: ubuntu-latest
2622
defaults:
@@ -34,6 +30,5 @@ jobs:
3430

3531
- name: Deploy to QA # Step to run Flyway migrations
3632
# To use username and password instead of windows integrated security Ensure that SQL Server is configured to allow SQL Server authentication. You can check this in SQL Server Management Studio (SSMS) under the server properties -> Security -> Server authentication. Ensure "SQL Server and Windows Authentication mode" is selected.
37-
run: flyway -email=${{ env.EMAIL }} -token=${{ env.TOKEN }} info migrate info -user=${{ env.DB_USER_QA }} -password=${{ env.DB_USER_PW_QA }} -url="${{ env.DB_SERVER }};databaseName=${{ env.DB_QA }};encrypt=${{ env.ENCRYPT }};trustServerCertificate=${{ env.TRUST_CERT }}" -IAgreeToTheEula -locations="filesystem:${{ github.workspace }}/migrations" -configFiles="${{ github.workspace }}/flyway.toml" -baselineOnMigrate=true -errorOverrides=S0001:0:I-
33+
run: flyway -email=${{ env.EMAIL }} -token=${{ env.TOKEN }} info migrate info -user=${{ env.DB_USER_QA }} -password=${{ env.DB_USER_PW_QA }} -url=${{ env.JDBC_QA }} -IAgreeToTheEula -locations="filesystem:${{ github.workspace }}/migrations" -configFiles="${{ github.workspace }}/flyway.toml" -baselineOnMigrate=true -errorOverrides=S0001:0:I-
3834
working-directory: ./migrations
39-

0 commit comments

Comments
 (0)