Skip to content

Commit 241c5e1

Browse files
committed
chore(workflows): enhance SQL Server debugging and readiness checks
Improve the workflow for .NET tests by adding more robust SQL Server service checks and debugging steps. This ensures better reliability and visibility during the CI process. - Added SQL Server service state debugging step. - Implemented waiting mechanism for SQL login readiness. - Moved database creation step to ensure it runs after SQL Server is ready. - Enhanced logging for SQL Server container failures.
1 parent 1ab9f2d commit 241c5e1

File tree

1 file changed

+50
-14
lines changed

1 file changed

+50
-14
lines changed

.github/workflows/dotnet-test.yml

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
SA_PASSWORD: "${{ secrets.SQLHELPER_SQL_PASSWORD }}"
5151
ports:
5252
- 1433:1433
53+
options: --pull always
5354

5455
strategy:
5556
matrix:
@@ -80,14 +81,59 @@ jobs:
8081
echo "SQL Server did not become reachable in time."
8182
exit 1
8283
83-
- name: Debug SA password presence
84+
- name: Debug SQL Server service state
85+
shell: bash
8486
run: |
85-
if [ -z "${{ secrets.SQLHELPER_SQL_PASSWORD }}" ]; then
86-
echo "Password is EMPTY"
87+
echo "Service container id: ${{ job.services.sqlserver.id }}"
88+
docker ps -a
89+
docker inspect "${{ job.services.sqlserver.id }}" --format 'Status={{.State.Status}} Health={{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}} StartedAt={{.State.StartedAt}}'
90+
if [ -n "$SQLHELPER_SQL_PASSWORD" ]; then
91+
echo "SQLHELPER_SQL_PASSWORD is set (value masked)."
92+
echo "Password length: ${#SQLHELPER_SQL_PASSWORD}"
8793
else
88-
echo "Password is PRESENT (value hidden)"
94+
echo "SQLHELPER_SQL_PASSWORD is empty."
8995
fi
9096
97+
- name: Wait for SQL login readiness
98+
shell: bash
99+
run: |
100+
for i in {1..45}; do
101+
if docker exec "${{ job.services.sqlserver.id }}" /opt/mssql-tools18/bin/sqlcmd \
102+
-S localhost \
103+
-U sa \
104+
-P "$SQLHELPER_SQL_PASSWORD" \
105+
-C \
106+
-Q "SELECT 1" >/dev/null 2>&1; then
107+
echo "SQL Server accepted sa login."
108+
exit 0
109+
fi
110+
echo "Waiting for SQL login readiness... attempt $i"
111+
if [ "$i" -eq 1 ] || [ $((i % 10)) -eq 0 ]; then
112+
docker logs --tail 80 "${{ job.services.sqlserver.id }}" || true
113+
fi
114+
sleep 2
115+
done
116+
echo "SQL Server never accepted sa login. Dumping container logs."
117+
docker logs "${{ job.services.sqlserver.id }}" || true
118+
exit 1
119+
120+
- name: Create test databases
121+
shell: bash
122+
run: |
123+
docker exec "${{ job.services.sqlserver.id }}" /opt/mssql-tools18/bin/sqlcmd \
124+
-S localhost \
125+
-U sa \
126+
-P "$SQLHELPER_SQL_PASSWORD" \
127+
-C \
128+
-Q "IF DB_ID(N'TestDatabase') IS NULL CREATE DATABASE [TestDatabase]; IF DB_ID(N'TestDatabase2') IS NULL CREATE DATABASE [TestDatabase2]; IF DB_ID(N'MockDatabase') IS NULL CREATE DATABASE [MockDatabase]; IF DB_ID(N'MockDatabaseForMockMapping') IS NULL CREATE DATABASE [MockDatabaseForMockMapping];"
129+
130+
- name: Debug SQL logs on failure
131+
if: ${{ failure() }}
132+
shell: bash
133+
run: |
134+
echo "Dumping SQL Server container logs due to earlier failure."
135+
docker logs "${{ job.services.sqlserver.id }}" || true
136+
91137
- name: Cache NuGet packages
92138
uses: actions/cache@v5
93139
with:
@@ -102,16 +148,6 @@ jobs:
102148
- name: Build
103149
run: dotnet build "$SOLUTION_FILE" --no-restore --configuration $BUILD_CONFIG
104150

105-
- name: Create test databases
106-
shell: bash
107-
run: |
108-
docker exec "${{ job.services.sqlserver.id }}" /opt/mssql-tools18/bin/sqlcmd \
109-
-S localhost \
110-
-U sa \
111-
-P "$SQLHELPER_SQL_PASSWORD" \
112-
-C \
113-
-Q "IF DB_ID(N'TestDatabase') IS NULL CREATE DATABASE [TestDatabase]; IF DB_ID(N'TestDatabase2') IS NULL CREATE DATABASE [TestDatabase2]; IF DB_ID(N'MockDatabase') IS NULL CREATE DATABASE [MockDatabase]; IF DB_ID(N'MockDatabaseForMockMapping') IS NULL CREATE DATABASE [MockDatabaseForMockMapping];"
114-
115151
- name: Test
116152
run: dotnet test "$SOLUTION_FILE" /p:Configuration=$BUILD_CONFIG --no-build --verbosity normal --logger trx --results-directory "TestResults-${{ matrix.dotnet-version }}" $TEST_FILTER
117153

0 commit comments

Comments
 (0)