Skip to content

Commit e422eb7

Browse files
theodorejbclaude
andcommitted
Use install-sql-server-action for SQL Server in CI
The action starts SQL Server in a container, waits for it to accept connections, creates the database, and sets the SQLCMD* environment variables with a random password. This replaces the service container, hardcoded password, and database creation step. On Linux, the action now forwards sqlcmd to the container, so it no longer depends on sqlcmd being installed on the runner. The collation is set to SQL Server's usual case-insensitive default, since the action defaults to a case-sensitive collation. Refs #13 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 93a6e91 commit e422eb7

1 file changed

Lines changed: 9 additions & 32 deletions

File tree

‎.github/workflows/php.yml‎

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,20 @@ jobs:
2929
ports:
3030
# map port 5432 on service container to the host
3131
- 5432:5432
32-
mssql:
33-
image: mcr.microsoft.com/mssql/server:2022-latest
34-
env:
35-
ACCEPT_EULA: Y
36-
MSSQL_SA_PASSWORD: PeachySQL-Test1
37-
ports:
38-
# map port 1433 on service container to the host
39-
- 1433:1433
40-
41-
env:
42-
# used by the SQL Server tests
43-
SQLCMDSERVER: localhost
44-
SQLCMDUSER: sa
45-
SQLCMDPASSWORD: PeachySQL-Test1
4632

4733
steps:
4834
- name: Checkout
4935
uses: actions/checkout@v6
5036

37+
# Starts SQL Server in a container, creates the database, and sets the SQLCMD* environment
38+
# variables used by the tests. Docs: https://github.com/Particular/install-sql-server-action
39+
- name: Install SQL Server
40+
uses: Particular/install-sql-server-action@v3.0.0
41+
with:
42+
connection-string-env-var: MSSQL_CONNECTION_STRING
43+
catalog: PeachySQL
44+
collation: SQL_Latin1_General_CP1_CI_AS
45+
5146
# The runner image includes Microsoft's package repository, but not the ODBC driver
5247
- name: Install Microsoft ODBC Driver for SQL Server
5348
run: |
@@ -70,24 +65,6 @@ jobs:
7065
- name: Install Composer dependencies
7166
uses: "ramsey/composer-install@v4"
7267

73-
# SQL Server can take a while to start, so retry connecting for up to two minutes
74-
- name: Create SQL Server database
75-
run: |
76-
php -r '
77-
for ($i = 0; ; $i++) {
78-
try {
79-
$pdo = new PDO("sqlsrv:Server=localhost;TrustServerCertificate=1", getenv("SQLCMDUSER"), getenv("SQLCMDPASSWORD"));
80-
break;
81-
} catch (PDOException $e) {
82-
if ($i === 60) {
83-
throw $e;
84-
}
85-
sleep(2);
86-
}
87-
}
88-
$pdo->exec("CREATE DATABASE PeachySQL");
89-
'
90-
9168
- name: Run PHPUnit
9269
run: composer test
9370
env:

0 commit comments

Comments
 (0)