generated from im-open/composite-action-template
-
Notifications
You must be signed in to change notification settings - Fork 4
/
action.yml
204 lines (185 loc) · 9.83 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
name: Build SQL Database
description: Build a SQL Database with Flyway
inputs:
db-server-name:
description: The name of the database server to build the database on.
required: true
default: 'localhost'
db-server-port:
description: The port that the database server listens on.
required: false
default: '1433'
db-name:
description: The name of the database to build.
required: true
use-integrated-security:
description: Use domain integrated security. This only works on windows. If running on a linux runner, set this to false or don't specify a value. If false, a db-username and db-password should be specified; if they aren't then the action will attempt to use integrated security. If true, those parameters will be ignored if specified.
required: false
default: 'false'
trust-server-certificate:
description: Trust Server certificate if it is self signed
required: false
default: 'false'
db-username:
description: The username to use to login to the database. This is required if use-integrated-security is false, otherwise it's optional and will be ignored.
required: false
db-password:
description: The password for the user logging in to the database. This is required if use-integrated-security is false, otherwise it's optional and will be ignored.
required: false
migration-files-path:
description: The path to the base directory containing the migration files to process with flyway. Can be a comma separated list of directories.
required: true
install-mock-db-objects:
description: Specifies whether mock db objects should be used to fill out dependencies. If set to true mock-db-object-dependency-list must also be set, otherwise an error will occur. The expected value is true or false.
required: false
default: 'false'
mock-db-object-dependency-list:
description: A json string containing a list of objects with the name of the dependency package, the version, the url where the package is stored, and optionally a bearer token for authentication.
required: false
incremental:
description: Specifies whether to drop and recreate the database before building, or apply to the current database. The expected value is true or false. If true, the create-database-file property will not be used.
required: false
default: 'false'
create-database-file:
description: The file path to the sql file that initializes the database. This script will only be run if the incremental property is false.
required: false
run-tests:
description: Specifies whether or not to run tests. The expected values are true and false. If true, test-files-path should also be set. If false, test-files-path will be ignored.
required: false
default: 'false'
test-files-path:
description: The path to the files with tSQLt tests.
required: false
test-timeout:
description: An optional setting for the allowed wait time, in seconds, for the tests to execute. If tests sometimes hang, or shouldn't take longer than a certain amount of time, this parameter can be helpful.
required: false
default: '300'
drop-db-after-build:
description: Specifies whether or not to drop the database after building. The expected values are true and false. Set this to false if other steps in the job rely on the database existing.
required: false
default: 'false'
should-validate-migrations:
description: Determines whether flyway will validate the migration scripts before running them.
required: false
default: 'false'
seed-data:
description: A switch specifying whether or not to seed data into the database. The expected values are true and false. If true, seed-data-files-path must also be set.
required: false
default: 'false'
seed-data-files-path:
description: The path to the files with seeding database.
required: false
managed-schemas:
description: A comma separated list of schemas that are to be managed by flyway.
required: false
default: 'dbo'
runs:
using: 'composite'
steps:
- name: Set integrated security flag
id: set-auth-method
shell: pwsh
run: |
$useIntegratedSecurity = "${{ inputs.use-integrated-security }}"
if ((!$useIntegratedSecurity -or $useIntegratedSecurity.ToLower() -eq "false") -and !"${{ inputs.db-username }}" -and !"${{ inputs.db-password }}") {
$useIntegratedSecurity = "true"
}
"use_integrated_security=$useIntegratedSecurity" >> $env:GITHUB_OUTPUT
- name: Set trust-server-certificate flag
id: trust-server-certificate
shell: pwsh
run: |
$trustServerCertificate = "${{ inputs.trust-server-certificate }}"
"trust_server_certificate=$trustServerCertificate" >> $env:GITHUB_OUTPUT
- name: Install SQL Powershell Module
shell: pwsh
run: |
if (get-module SqlServer -ListAvailable) {
Write-Output "Importing SqlServer module"
Import-Module SqlServer
}
else {
Write-Output "Installing SqlServer module"
$repo = Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue
if (!$repo) {
Write-Output "Registering PSGallery as as PSRepository"
Register-PSRepository -Name "PSGallery" -SourceLocation "https://www.powershellgallery.com/api/v2/" -InstallationPolicy Trusted
}
PowerShellGet\Install-Module SqlServer -Repository PSGallery -Force -AllowClobber
Import-Module SqlServer
}
- name: Create Database
shell: pwsh
run: |
Write-Output "Creating the database"
[System.Security.SecureString] $securePassword = if(!!"${{ inputs.db-password }}") { ConvertTo-SecureString "${{ inputs.db-password }}" -AsPlainText -Force } else { $null }
${{ github.action_path }}/src/create-db/create-db.ps1 `
-dbServer "${{ inputs.db-server-name }}" `
-dbServerPort "${{ inputs.db-server-port }}" `
-dbName "${{ inputs.db-name }}" `
-incremental:$${{ inputs.incremental }} `
-pathToCreateDbFile "${{ inputs.create-database-file }}" `
-installMockDbObjects:$${{ inputs.install-mock-db-objects }} `
-mockDependencyObjectList "${{ inputs.mock-db-object-dependency-list }}" `
-useIntegratedSecurity:$${{ steps.set-auth-method.outputs.use_integrated_security }} `
-trustServerCertificate:$${{ steps.trust-server-certificate.outputs.trust_server_certificate }} `
-username "${{ inputs.db-username }}" `
-password $securePassword
- name: Run migration scripts
shell: pwsh
run: |
Write-Output "Running migration scripts"
[System.Security.SecureString] $securePassword = if(!!"${{ inputs.db-password }}") { ConvertTo-SecureString "${{ inputs.db-password }}" -AsPlainText -Force } else { $null }
$baselineVersion = 0
if ('${{ inputs.incremental }}' -eq 'true')
{
$baselineVersion = 0.1 # this will allow us to ignore missing migrations when running flyway
}
${{ github.action_path }}/src/run-flyway/run-flyway-migrate.ps1 `
-dbServer "${{ inputs.db-server-name }}" `
-dbServerPort "${{ inputs.db-server-port }}" `
-dbName "${{ inputs.db-name }}" `
-pathToMigrationFiles "${{ inputs.migration-files-path }}" `
-migrationHistoryTable "MigrationHistory" `
-baselineVersion $baselineVersion `
-managedSchemas "${{ inputs.managed-schemas }}" `
-validateMigrations:$${{ inputs.should-validate-migrations }} `
-useIntegratedSecurity:$${{ steps.set-auth-method.outputs.use_integrated_security }} `
-trustServerCertificate:$${{ steps.trust-server-certificate.outputs.trust_server_certificate }} `
-username "${{ inputs.db-username }}" `
-password $securePassword
- name: Run tests
if: ${{ inputs.run-tests == 'true' }}
shell: pwsh
run: |
Write-Output "Running Tests"
[System.Security.SecureString] $securePassword = if(!!"${{ inputs.db-password }}") { ConvertTo-SecureString "${{ inputs.db-password }}" -AsPlainText -Force } else { $null }
${{ github.action_path }}/src/tsqlt/run-tests.ps1 `
-dbServer "${{ inputs.db-server-name }}" `
-dbServerPort "${{ inputs.db-server-port }}" `
-dbName "${{ inputs.db-name }}" `
-pathToTests "${{ inputs.test-files-path }}" `
-managedSchemas "${{ inputs.managed-schemas }}" `
-testTimeout "${{ inputs.test-timeout }}" `
-useIntegratedSecurity:$${{ steps.set-auth-method.outputs.use_integrated_security }} `
-trustServerCertificate:$${{ steps.trust-server-certificate.outputs.trust_server_certificate }} `
-username "${{ inputs.db-username }}" `
-password $securePassword
- name: Run seed data scripts
if: ${{ inputs.seed-data == 'true' }}
shell: pwsh
run: |
Write-Output "Seeding data into the database"
[System.Security.SecureString] $securePassword = if(!!"${{ inputs.db-password }}") { ConvertTo-SecureString "${{ inputs.db-password }}" -AsPlainText -Force } else { $null }
${{ github.action_path }}/src/run-flyway/run-flyway-migrate.ps1 `
-dbServer "${{ inputs.db-server-name }}" `
-dbServerPort "${{ inputs.db-server-port }}" `
-dbName "${{ inputs.db-name }}" `
-pathToMigrationFiles "${{ inputs.seed-data-files-path }}" `
-migrationHistoryTable "SeedDataHistory" `
-managedSchemas "${{ inputs.managed-schemas }}" `
-validateMigrations `
-useIntegratedSecurity:$${{ steps.set-auth-method.outputs.use_integrated_security }} `
-trustServerCertificate:$${{ steps.trust-server-certificate.outputs.trust_server_certificate }} `
-username "${{ inputs.db-username }}" `
-password $securePassword