@@ -5,7 +5,7 @@ name: pr-check
55# with no secrets and no elevated permissions.
66#
77# - Linux runners: spin up SQL Server 2022 in a Docker container with SA auth.
8- # - Windows runners: use the pre-installed SQL Server Express with Integrated Security .
8+ # - Windows runners: install SQL Server 2025 Express directly from Microsoft with SA auth .
99
1010on :
1111 pull_request :
2525
2626 env :
2727 TEST_DB : SqlActionTest
28- MSSQL_IMAGE : mcr.microsoft.com/mssql/server:2022-latest
2928
3029 defaults :
3130 run :
@@ -37,135 +36,23 @@ jobs:
3736 with :
3837 ref : ${{ github.event.pull_request.head.sha }}
3938
40- # --- Linux setup: Docker container + SA auth with rotated password ---
41-
42- - name : Start SQL Server container (Linux)
43- if : runner.os == 'Linux'
44- run : |
45- docker run -d --name sqlserver \
46- -e "ACCEPT_EULA=Y" \
47- -e "MSSQL_SA_PASSWORD=Bootstrap1!" \
48- -p 1433:1433 \
49- "$MSSQL_IMAGE"
50-
51- - name : Wait for SQL Server to be ready (Linux)
52- if : runner.os == 'Linux'
53- run : |
54- for i in $(seq 1 30); do
55- if docker exec sqlserver /opt/mssql-tools18/bin/sqlcmd \
56- -S localhost -U sa -P 'Bootstrap1!' -C -Q 'SELECT 1' >/dev/null 2>&1; then
57- echo "SQL Server is ready"
58- exit 0
59- fi
60- echo "Waiting for SQL Server... ($i/30)"
61- sleep 5
62- done
63- echo "SQL Server did not become ready in time"
64- docker logs sqlserver
65- exit 1
66-
67- - name : Rotate SA password and set connection string (Linux)
68- if : runner.os == 'Linux'
69- run : |
70- SA_PASSWORD="$(openssl rand -base64 18 | tr -d '/+=')Aa1!"
71- docker exec sqlserver /opt/mssql-tools18/bin/sqlcmd \
72- -S localhost -U sa -P 'Bootstrap1!' -C \
73- -Q "ALTER LOGIN sa WITH PASSWORD='${SA_PASSWORD}'"
74- echo "BASE_CS=Server=localhost;User ID=sa;Password=${SA_PASSWORD};TrustServerCertificate=True;" >> "$GITHUB_ENV"
75-
76- # --- Windows setup: install SQL Server 2022 Express directly from Microsoft ---
77-
78- - name : Generate SA password (Windows)
79- if : runner.os == 'Windows'
39+ - name : Generate SA password
8040 run : |
8141 SA_PASSWORD="$(openssl rand -base64 18 | tr -d '/+=')Aa1!"
8242 echo "::add-mask::${SA_PASSWORD}"
8343 echo "SA_PASSWORD=${SA_PASSWORD}" >> "$GITHUB_ENV"
8444
85- - name : Download SQL Server 2025 Express installer (Windows)
86- if : runner.os == 'Windows'
87- shell : pwsh
88- run : |
89- $ssei = Join-Path $env:RUNNER_TEMP 'SQL2025-SSEI-Expr.exe'
90- $media = Join-Path $env:RUNNER_TEMP 'sql-media'
91- # Stable Microsoft fwlink redirecting to the SQL Server 2025 Express bootstrapper (SSEI)
92- Invoke-WebRequest -Uri 'https://go.microsoft.com/fwlink/?linkid=2216019' -OutFile $ssei
93- Write-Host "Downloaded SSEI: $((Get-Item $ssei).Length) bytes"
94-
95- # Run SSEI in download-only mode. Use Start-Process -Wait so we get a real exit code
96- # (PowerShell's `&` returns asynchronously for installer-class executables).
97- $p = Start-Process -FilePath $ssei -Wait -PassThru -ArgumentList @(
98- '/Quiet',
99- '/Action=Download',
100- '/Language=en-US',
101- "/MediaPath=$media",
102- '/MediaType=Core',
103- '/HideProgressBar'
104- )
105- if ($p.ExitCode -ne 0) { throw "SSEI download failed with exit code $($p.ExitCode)" }
106-
107- Write-Host "=== Media directory contents ==="
108- Get-ChildItem $media
109-
110- - name : Install SQL Server Express with SA auth (Windows)
111- if : runner.os == 'Windows'
112- shell : pwsh
113- run : |
114- $media = Join-Path $env:RUNNER_TEMP 'sql-media'
115- $selfExtract = Get-ChildItem $media -Filter 'SQLEXPR*.exe' | Select-Object -First 1
116- if (-not $selfExtract) { throw "Installer EXE not found in $media" }
117-
118- $extracted = Join-Path $env:RUNNER_TEMP 'sql-extracted'
119- Write-Host "Extracting $($selfExtract.FullName) -> $extracted"
120- $extract = Start-Process -FilePath $selfExtract.FullName -Wait -PassThru `
121- -ArgumentList '/Q', "/X:$extracted"
122- if ($extract.ExitCode -ne 0) { throw "Extraction failed with exit code $($extract.ExitCode)" }
123-
124- $setup = Join-Path $extracted 'setup.exe'
125- if (-not (Test-Path $setup)) { throw "setup.exe not found at $setup" }
126-
127- Write-Host "Running $setup with SECURITYMODE=SQL"
128- $install = Start-Process -FilePath $setup -Wait -PassThru -ArgumentList @(
129- '/Q',
130- '/ACTION=Install',
131- '/FEATURES=SQLEngine',
132- '/INSTANCENAME=MSSQLSERVER',
133- '/SECURITYMODE=SQL',
134- "/SAPWD=$env:SA_PASSWORD",
135- '/TCPENABLED=1',
136- '/IACCEPTSQLSERVERLICENSETERMS',
137- '/UPDATEENABLED=False',
138- '/SQLSYSADMINACCOUNTS=BUILTIN\Administrators'
139- )
140-
141- if ($install.ExitCode -ne 0) {
142- Write-Host "Setup failed with exit code $($install.ExitCode)"
143- $logRoot = 'C:\Program Files\Microsoft SQL Server'
144- if (Test-Path $logRoot) {
145- Get-ChildItem $logRoot -Recurse -Filter 'Summary*.txt' -ErrorAction SilentlyContinue |
146- Sort-Object LastWriteTime -Descending | Select-Object -First 1 |
147- ForEach-Object { Write-Host "=== $($_.FullName) ==="; Get-Content $_.FullName }
148- }
149- throw "SQL Server install failed"
150- }
151- Get-Service | Where-Object { $_.Name -like 'MSSQL*' } | Format-Table
152-
153- - name : Verify SQL auth (Windows)
154- if : runner.os == 'Windows'
155- shell : pwsh
156- run : |
157- $sqlcmd = (Get-ChildItem 'C:\Program Files\Microsoft SQL Server' -Recurse -Filter sqlcmd.exe -ErrorAction SilentlyContinue |
158- Select-Object -First 1).FullName
159- if (-not $sqlcmd) { throw "sqlcmd.exe not found after install" }
160- & $sqlcmd -S 'localhost' -U sa -P $env:SA_PASSWORD -b -Q "SELECT @@VERSION"
161- if ($LASTEXITCODE -ne 0) { throw "SQL auth verification failed" }
45+ - name : Set up SQL Server (Linux)
46+ if : runner.os == 'Linux'
47+ uses : ./.github/actions/setup-sql-linux
48+ with :
49+ sa-password : ${{ env.SA_PASSWORD }}
16250
163- - name : Set connection string (Windows)
51+ - name : Set up SQL Server (Windows)
16452 if : runner.os == 'Windows'
165- run : |
166- echo "BASE_CS=Server=localhost;User ID=sa;Password=${SA_PASSWORD};TrustServerCertificate=True;" >> "$GITHUB_ENV"
167-
168- # --- Common build and test steps ---
53+ uses : ./.github/actions/setup-sql-windows
54+ with :
55+ sa-password : ${{ env.SA_PASSWORD }}
16956
17057 - name : Build GitHub Action
17158 run : npm ci --ignore-scripts && npm run build
0 commit comments