Skip to content

Commit 4373c57

Browse files
CopilotThorium
andcommitted
Improve SQL Server setup reliability and add GitHub Actions workflow
Co-authored-by: Thorium <[email protected]>
1 parent 1ad10b7 commit 4373c57

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed

.github/workflows/dotnet.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: .NET
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
services:
14+
postgres:
15+
image: postgres:13
16+
env:
17+
POSTGRES_PASSWORD: Password12!
18+
POSTGRES_USER: postgres
19+
POSTGRES_DB: sqlprovider
20+
options: >-
21+
--health-cmd pg_isready
22+
--health-interval 10s
23+
--health-timeout 5s
24+
--health-retries 5
25+
ports:
26+
- 5432:5432
27+
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- name: Setup .NET
32+
uses: actions/setup-dotnet@v4
33+
with:
34+
dotnet-version: 8.0.x
35+
36+
- name: Restore tools
37+
run: dotnet tool restore
38+
39+
- name: Restore dependencies
40+
run: dotnet paket restore
41+
42+
- name: Build
43+
run: dotnet fake run build.fsx -t Build
44+
45+
- name: Test
46+
run: dotnet fake run build.fsx -t RunTests

build.fsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,21 +285,27 @@ let setupMssql url saPassword =
285285
connBuilder.UserID <- "sa"
286286
connBuilder.DataSource <- url
287287
connBuilder.Password <- saPassword
288+
connBuilder.TrustServerCertificate <- true
288289

289290
let runCmd query =
290-
// We wait up to 30 seconds for MSSQL to be initialized
291+
// We wait up to 60 seconds for MSSQL to be initialized on AppVeyor
292+
let maxAttempts = if Fake.Core.BuildServer.buildServer = AppVeyor then 60 else 30
291293
let rec runCmd' attempt =
292294
try
293295
use conn = new SqlConnection(connBuilder.ConnectionString)
294296
conn.Open()
295297
use cmd = new SqlCommand(query, conn)
296298
cmd.ExecuteNonQuery() |> ignore
297299
with e ->
298-
printfn "Connection attempt %i: %A" attempt e
299-
Threading.Thread.Sleep 1000
300-
if attempt < 30 then runCmd' (attempt + 1)
300+
printfn "Connection attempt %i/%i: %A" attempt maxAttempts e
301+
if attempt < maxAttempts then
302+
Threading.Thread.Sleep 1000
303+
runCmd' (attempt + 1)
304+
else
305+
printfn "Failed to connect to SQL Server after %i attempts. Last error: %A" maxAttempts e
306+
reraise()
301307

302-
runCmd' 0
308+
runCmd' 1
303309

304310
let runScript fileLines =
305311

@@ -330,10 +336,12 @@ let setupMssql url saPassword =
330336
(url,saPassword) |> ignore
331337

332338
Target.create "SetupMSSQL2008R2" (fun _ ->
339+
printfn "Setting up MSSQL for AppVeyor (compatibility target for SQL2008R2)"
333340
setupMssql "(local)\\SQL2022" "Password12!"
334341
)
335342

336343
Target.create "SetupMSSQL2017" (fun _ ->
344+
printfn "Setting up MSSQL for AppVeyor (compatibility target for SQL2017)"
337345
setupMssql "(local)\\SQL2022" "Password12!"
338346
)
339347

tests/SqlProvider.Tests/SqlServerTests.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ let runtimeConnStr = connStr2008R2
1212
#else
1313
module SqlServerTests
1414

15-
let [<Literal>] connStr2008R2 = "Data Source=(local)\SQL2022;User Id=sa;Password=Password12!; Initial Catalog=sqlprovider;"
16-
let [<Literal>] connStr2017 = "Data Source=(local)\SQL2022;User Id=sa;Password=Password12!; Initial Catalog=sqlprovider;"
15+
let [<Literal>] connStr2008R2 = "Data Source=(local)\SQL2022;User Id=sa;Password=Password12!; Initial Catalog=sqlprovider; TrustServerCertificate=true;"
16+
let [<Literal>] connStr2017 = "Data Source=(local)\SQL2022;User Id=sa;Password=Password12!; Initial Catalog=sqlprovider; TrustServerCertificate=true;"
1717

1818
#endif
1919

0 commit comments

Comments
 (0)