@@ -141,6 +141,7 @@ let dotnetBuildDisableBinLog (args: DotNet.BuildOptions) =
141141let dnDefault =
142142 dotnetBuildDisableBinLog
143143 >> DotNet.Options.withVerbosity ( Some DotNet.Verbosity.Quiet)
144+ >> DotNet.Options.withCustomParams ( Some " --tl" )
144145
145146Target.create " Build" ( fun _ ->
146147 DotNet.build
@@ -154,33 +155,55 @@ open System.IO.Compression
154155open Fake.DotNet .Testing
155156
156157Target.create " DeployTestDB" ( fun _ ->
157- let testsSourceRoot = Path.GetFullPath( @" tests\SqlClient.Tests" )
158- let map = ExeConfigurationFileMap()
159- map.ExeConfigFilename <- testsSourceRoot @@ " app.config"
160- let connStr =
161- let x =
162- ConfigurationManager
163- .OpenMappedExeConfiguration( map, ConfigurationUserLevel.None)
158+ let testsSourceRoot = Path.GetFullPath( @" tests\SqlClient.Tests" )
159+ let mutable database = None
160+ let mutable testConnStr = None
161+ let mutable conn = None
162+
163+ pipeline " DeployTestDB" {
164+
165+ stage " adjust config file connection strings" {
166+ run ( fun ctx ->
167+ let map = ExeConfigurationFileMap()
168+ map.ExeConfigFilename <- testsSourceRoot @@ " app.config"
169+ let testConfigFile = ConfigurationManager.OpenMappedExeConfiguration( map, ConfigurationUserLevel.None)
170+ let connStr =
171+ let connStr =
172+ let gitHubActionSqlConnectionString = System.Environment.GetEnvironmentVariable " GITHUB_ACTION_SQL_SERVER_CONNECTION_STRING"
173+ if String.IsNullOrWhiteSpace gitHubActionSqlConnectionString then
174+ testConfigFile
164175 .ConnectionStrings
165176 .ConnectionStrings.[ " AdventureWorks" ]
166177 .ConnectionString
167- SqlConnectionStringBuilder( x)
168-
169- let database = connStr.InitialCatalog
170- use conn =
171- connStr.InitialCatalog <- " "
172- new SqlConnection( string connStr)
178+ else
179+ // we run under Github Actions, update the test config file connection string.
180+ testConfigFile
181+ .ConnectionStrings
182+ .ConnectionStrings.[ " AdventureWorks" ]
183+ .ConnectionString <- gitHubActionSqlConnectionString
184+ testConfigFile.Save()
185+ gitHubActionSqlConnectionString
186+ SqlConnectionStringBuilder connStr
187+ testConnStr <- Some connStr
188+ database <- Some connStr.InitialCatalog
189+ conn <-
190+ connStr.InitialCatalog <- " "
191+ let cnx = new SqlConnection( string connStr)
192+ cnx.Open()
193+ Some cnx
194+ )
195+ }
173196
174- conn.Open()
197+ stage " attach database to server" {
198+ run ( fun ctx ->
175199
176- do //attach
200+ //attach
177201 let dbIsMissing =
178- let query = sprintf " SELECT COUNT(*) FROM sys.databases WHERE name = '%s '" database
179- use cmd = new SqlCommand( query, conn)
202+ let query = sprintf " SELECT COUNT(*) FROM sys.databases WHERE name = '%s '" database.Value
203+ use cmd = new SqlCommand( query, conn.Value )
180204 cmd.ExecuteScalar() = box 0
181205
182- if dbIsMissing
183- then
206+ if dbIsMissing then
184207 let dataFileName = " AdventureWorks2012_Data"
185208 //unzip
186209 let sourceMdf = testsSourceRoot @@ ( dataFileName + " .mdf" )
@@ -189,32 +212,47 @@ Target.create "DeployTestDB" (fun _ ->
189212
190213 ZipFile.ExtractToDirectory( testsSourceRoot @@ ( dataFileName + " .zip" ), testsSourceRoot)
191214
192-
193215 let dataPath =
194- use cmd = new SqlCommand( " SELECT SERVERPROPERTY('InstanceDefaultDataPath')" , conn)
216+ use cmd = new SqlCommand( " SELECT SERVERPROPERTY('InstanceDefaultDataPath')" , conn.Value )
195217 cmd.ExecuteScalar() |> string
196218 do
197219 let destFileName = dataPath @@ Path.GetFileName( sourceMdf)
198220 File.Copy( sourceMdf, destFileName, overwrite = true )
199221 File.Delete( sourceMdf)
200- use cmd = conn.CreateCommand( CommandText = sprintf " CREATE DATABASE [%s ] ON ( FILENAME = N'%s ' ) FOR ATTACH" database destFileName)
222+ use cmd = conn.Value. CreateCommand( CommandText = sprintf " CREATE DATABASE [%s ] ON ( FILENAME = N'%s ' ) FOR ATTACH" database.Value destFileName)
201223 cmd.ExecuteNonQuery() |> ignore
224+ )
225+ }
202226
203- do //create extra object to test corner case
227+ //create extra object to test corner case
228+ stage " patch adventure works" {
229+ run ( fun ctx ->
230+ use _ = conn.Value
204231 let script = File.ReadAllText( testsSourceRoot @@ " extensions.sql" )
205232 for batch in script.Split([| " GO" ; " go" |], StringSplitOptions.RemoveEmptyEntries) do
206- use cmd = conn.CreateCommand( CommandText = batch)
233+ try
234+ use cmd = conn.Value.CreateCommand( CommandText = batch)
207235 cmd.ExecuteNonQuery() |> ignore
236+ with
237+ e ->
238+ let message = $" error while patching test db:\n {e.Message}\n {batch}"
239+ printfn $" {message}"
240+ raise ( Exception( message, e))
241+
242+ )
243+ }
244+ runImmediate
245+ }
208246)
209247
210248let funBuildRestore stageName sln =
211249 stage $" dotnet restore %s {stageName} '{sln}'" {
212- run $" dotnet restore {sln}"
250+ run $" dotnet restore {sln} --tl "
213251 }
214252let funBuildRunMSBuild stageName sln =
215253 let msbuild = $" \" {msBuildPaths [] }\" "
216254 stage $" run MsBuild %s {stageName}" {
217- run $" {msbuild} {sln} -verbosity:quiet"
255+ run $" {msbuild} {sln} -verbosity:quiet --tl "
218256 }
219257
220258Target.create " BuildTestProjects" ( fun _ ->
0 commit comments