Skip to content

Commit 2a75f69

Browse files
committed
feat: use GitHub Actions service container for MSSQL
- Replace direct docker run with service container configuration - Add health check using sqlcmd for proper startup detection - Simplify database setup by removing manual container management - All databases now use consistent service container approach
1 parent e61084f commit 2a75f69

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

.github/workflows/example.yaml

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,28 @@ jobs:
102102
mssql-preview:
103103
runs-on: ubuntu-latest
104104

105+
services:
106+
mssql:
107+
image: mcr.microsoft.com/mssql/server:2022-latest
108+
env:
109+
ACCEPT_EULA: Y
110+
SA_PASSWORD: Passw0rd
111+
options: >-
112+
--health-cmd "/opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P Passw0rd -Q 'SELECT 1' -C || /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P Passw0rd -Q 'SELECT 1'"
113+
--health-interval 10s
114+
--health-timeout 5s
115+
--health-retries 10
116+
--health-start-period 20s
117+
ports:
118+
- 1433:1433
119+
105120
steps:
106121
- name: Checkout code
107122
uses: actions/checkout@v5
108123
with:
109124
fetch-depth: 0
110125

111-
- name: Start MSSQL
112-
run: |
113-
docker run -d \
114-
--name mssql \
115-
-e "ACCEPT_EULA=Y" \
116-
-e "SA_PASSWORD=Passw0rd" \
117-
-p 1433:1433 \
118-
mcr.microsoft.com/mssql/server:2022-latest
119-
120-
- name: Wait for MSSQL
126+
- name: Setup MSSQL database
121127
run: |
122128
# Install sqlcmd tools
123129
sudo apt-get update && sudo apt-get install -y curl gnupg
@@ -126,16 +132,6 @@ jobs:
126132
sudo apt-get update
127133
sudo ACCEPT_EULA=Y apt-get install -y mssql-tools18
128134
129-
# Wait for MSSQL to be ready
130-
for i in {1..60}; do
131-
if /opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P "Passw0rd" -Q "SELECT 1" -C >/dev/null 2>&1; then
132-
echo "MSSQL is ready"
133-
break
134-
fi
135-
echo "Waiting for MSSQL..."
136-
sleep 3
137-
done
138-
139135
# Create the test database
140136
/opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P "Passw0rd" -Q "CREATE DATABASE testdb;" -C
141137
@@ -151,7 +147,3 @@ jobs:
151147
mssql-host: localhost
152148
mssql-port: 1433
153149
mssql-database: testdb
154-
155-
- name: Stop MSSQL
156-
if: always()
157-
run: docker stop mssql && docker rm mssql

0 commit comments

Comments
 (0)