Skip to content

Commit

Permalink
dotnet 8 sdk (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
smoothdeveloper authored Dec 6, 2023
1 parent 103fb5e commit c6e48a4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 33 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.400
dotnet-version: 8.0.100

- name: Install SQL Server
# reference @ https://github.com/Particular/install-sql-server-action
uses: Particular/[email protected]
with:
connection-string-env-var: SQL_SERVER_CONNECTION_STRING
catalog: AdventureWroks
connection-string-env-var: GITHUB_ACTION_SQL_SERVER_CONNECTION_STRING
catalog: AdventureWorks2012
extra-params: ""
- name: Build
env:
Expand Down
90 changes: 64 additions & 26 deletions build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ let dotnetBuildDisableBinLog (args: DotNet.BuildOptions) =
let dnDefault =
dotnetBuildDisableBinLog
>> DotNet.Options.withVerbosity (Some DotNet.Verbosity.Quiet)
>> DotNet.Options.withCustomParams (Some "--tl")

Target.create "Build" (fun _ ->
DotNet.build
Expand All @@ -154,33 +155,55 @@ open System.IO.Compression
open Fake.DotNet.Testing

Target.create "DeployTestDB" (fun _ ->
let testsSourceRoot = Path.GetFullPath(@"tests\SqlClient.Tests")
let map = ExeConfigurationFileMap()
map.ExeConfigFilename <- testsSourceRoot @@ "app.config"
let connStr =
let x =
ConfigurationManager
.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None)
let testsSourceRoot = Path.GetFullPath(@"tests\SqlClient.Tests")
let mutable database = None
let mutable testConnStr = None
let mutable conn = None

pipeline "DeployTestDB" {

stage "adjust config file connection strings" {
run (fun ctx ->
let map = ExeConfigurationFileMap()
map.ExeConfigFilename <- testsSourceRoot @@ "app.config"
let testConfigFile = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None)
let connStr =
let connStr =
let gitHubActionSqlConnectionString = System.Environment.GetEnvironmentVariable "GITHUB_ACTION_SQL_SERVER_CONNECTION_STRING"
if String.IsNullOrWhiteSpace gitHubActionSqlConnectionString then
testConfigFile
.ConnectionStrings
.ConnectionStrings.["AdventureWorks"]
.ConnectionString
SqlConnectionStringBuilder(x)

let database = connStr.InitialCatalog
use conn =
connStr.InitialCatalog <- ""
new SqlConnection(string connStr)
else
// we run under Github Actions, update the test config file connection string.
testConfigFile
.ConnectionStrings
.ConnectionStrings.["AdventureWorks"]
.ConnectionString <- gitHubActionSqlConnectionString
testConfigFile.Save()
gitHubActionSqlConnectionString
SqlConnectionStringBuilder connStr
testConnStr <- Some connStr
database <- Some connStr.InitialCatalog
conn <-
connStr.InitialCatalog <- ""
let cnx = new SqlConnection(string connStr)
cnx.Open()
Some cnx
)
}

conn.Open()
stage "attach database to server" {
run (fun ctx ->

do //attach
//attach
let dbIsMissing =
let query = sprintf "SELECT COUNT(*) FROM sys.databases WHERE name = '%s'" database
use cmd = new SqlCommand(query, conn)
let query = sprintf "SELECT COUNT(*) FROM sys.databases WHERE name = '%s'" database.Value
use cmd = new SqlCommand(query, conn.Value)
cmd.ExecuteScalar() = box 0

if dbIsMissing
then
if dbIsMissing then
let dataFileName = "AdventureWorks2012_Data"
//unzip
let sourceMdf = testsSourceRoot @@ (dataFileName + ".mdf")
Expand All @@ -189,32 +212,47 @@ Target.create "DeployTestDB" (fun _ ->

ZipFile.ExtractToDirectory(testsSourceRoot @@ (dataFileName + ".zip"), testsSourceRoot)


let dataPath =
use cmd = new SqlCommand("SELECT SERVERPROPERTY('InstanceDefaultDataPath')", conn)
use cmd = new SqlCommand("SELECT SERVERPROPERTY('InstanceDefaultDataPath')", conn.Value)
cmd.ExecuteScalar() |> string
do
let destFileName = dataPath @@ Path.GetFileName(sourceMdf)
File.Copy(sourceMdf, destFileName, overwrite = true)
File.Delete( sourceMdf)
use cmd = conn.CreateCommand(CommandText = sprintf "CREATE DATABASE [%s] ON ( FILENAME = N'%s' ) FOR ATTACH" database destFileName)
use cmd = conn.Value.CreateCommand(CommandText = sprintf "CREATE DATABASE [%s] ON ( FILENAME = N'%s' ) FOR ATTACH" database.Value destFileName)
cmd.ExecuteNonQuery() |> ignore
)
}

do //create extra object to test corner case
//create extra object to test corner case
stage "patch adventure works" {
run (fun ctx ->
use _ = conn.Value
let script = File.ReadAllText(testsSourceRoot @@ "extensions.sql")
for batch in script.Split([|"GO";"go"|], StringSplitOptions.RemoveEmptyEntries) do
use cmd = conn.CreateCommand(CommandText = batch)
try
use cmd = conn.Value.CreateCommand(CommandText = batch)
cmd.ExecuteNonQuery() |> ignore
with
e ->
let message = $"error while patching test db:\n{e.Message}\n{batch}"
printfn $"{message}"
raise (Exception(message, e))

)
}
runImmediate
}
)

let funBuildRestore stageName sln =
stage $"dotnet restore %s{stageName} '{sln}'" {
run $"dotnet restore {sln}"
run $"dotnet restore {sln} --tl"
}
let funBuildRunMSBuild stageName sln =
let msbuild = $"\"{msBuildPaths [] }\""
stage $"run MsBuild %s{stageName}" {
run $"{msbuild} {sln} -verbosity:quiet"
run $"{msbuild} {sln} -verbosity:quiet --tl"
}

Target.create "BuildTestProjects" (fun _ ->
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "sdk": { "version": "7.0.400", "rollForward": "latestMinor" } }
{ "sdk": { "version": "8.0.100", "rollForward": "latestMinor" } }
3 changes: 2 additions & 1 deletion src/SqlClient.DesignTime/SqlClient.DesignTime.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
note: TypeProvider SDK comes with few warnings
FS0026: This rule will never be matched
FS3218: The argument names in the signature 'measure' and implementation 'm' do not match. The argument name from the signature file will be used. This may cause problems when debugging or profiling.
FS3548: Pattern discard is not allowed for union case that takes no data.
-->
<WarningsNotAsErrors>$(WarningsNotAsErrors);FS0026;FS3218</WarningsNotAsErrors>
<WarningsNotAsErrors>$(WarningsNotAsErrors);FS0026;FS3218;FS3548</WarningsNotAsErrors>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<DisableImplicitSystemValueTupleReference>true</DisableImplicitSystemValueTupleReference>
<DefineConstants>$(DefineConstants);DESIGNTIME_CODE_ONLY;WITH_LEGACY_NAMESPACE</DefineConstants>
Expand Down

0 comments on commit c6e48a4

Please sign in to comment.