Here's the solution that fixed my Actions workflow. We remove the health checks and add an Actions step that repeatedly attempts to connect to SQL Server and run a simple query until it succeeds, ensuring the server is fully operational before proceeding with database initialization.
services:
mssql:
image: mcr.microsoft.com/mssql/server:2022-latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: ComplexPass123!
MSSQL_PID: Express
ports:
- 1433:1433
steps:
- uses: actions/checkout@v4
- name: Wait for SQL Server to be ready
run: |
echo "Waiting for SQL Server to be fully operational..."
until /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P ComplexPass123! -Q "SELECT @@VERSION" > /dev/null 2>&1
do
echo "SQL Server is still initializing. Waiting..."
sleep 5
done
echo "SQL Server is now operational."
- name: Initialize SQL Server
run: |
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P ComplexPass123! -i ./scripts/init-db.sql