Skip to content

Commit 5e677e7

Browse files
Configure SQL Server service in CI workflow
Added SQL Server service container and updated installation steps for sqlcmd tools.
1 parent 7603674 commit 5e677e7

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,28 @@ env:
2020
DB_MSSQL_USER: sa
2121
DB_MSSQL_PASSWORD: secret
2222
DB_MSSQL_DATABASE: test_sqlkata
23+
24+
2325
jobs:
2426
build:
2527
runs-on: ubuntu-latest
28+
29+
# Define a service container for SQL Server
30+
services:
31+
mssql:
32+
image: mcr.microsoft.com/mssql/server:2022-latest
33+
env:
34+
SA_PASSWORD: ${{ env.DB_MSSQL_PASSWORD }} # Use a GitHub secret for the password
35+
ACCEPT_EULA: 'Y'
36+
ports:
37+
- 1433:1433 # Map the port
38+
# Wait for the service to be ready before running steps
39+
options: >-
40+
--health-cmd "sqlcmd -S localhost -U sa -P $SA_PASSWORD -Q 'SELECT 1'"
41+
--health-interval 10s
42+
--health-timeout 5s
43+
--health-retries 10
44+
2645
timeout-minutes: 15
2746
steps:
2847
- uses: actions/checkout@v4
@@ -42,18 +61,19 @@ jobs:
4261
mysql -e 'CREATE TABLE cars(id int primary key auto_increment);' -u${{ env.DB_MYSQL_USER }} ${{ env.DB_MYSQL_DATABASE }}
4362
mysql -e 'SHOW TABLES;' -u${{ env.DB_MYSQL_USER }} ${{ env.DB_MYSQL_DATABASE }}
4463
45-
- name: Install SQL Server
64+
- name: Install sqlcmd tools
4665
run: |
47-
sudo su
48-
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
49-
add-apt-repository "$(curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/mssql-server-2022.list)"
50-
apt-get update
51-
ACCEPT_EULA=Y apt-get install -y mssql-server mssql-tools unixodbc-dev
52-
/opt/mssql/bin/mssql-conf setup accept-eula --edition Developer --sapassword "${{ env.DB_MSSQL_PASSWORD }}"
66+
sudo apt-get update
67+
sudo apt-get install -y curl apt-transport-https gnupg
68+
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
69+
echo "deb [arch=amd64,arm64,armhf] https://packages.microsoft.com/ubuntu/$(lsb_release -rs)/prod $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/microsoft.list
70+
sudo apt-get update
71+
sudo apt-get install -y mssql-tools unixodbc-dev
72+
echo '/opt/mssql-tools/bin' | sudo tee -a $GITHUB_PATH
5373
5474
- name: Run SQL commands (example)
55-
run: |
56-
sqlcmd -S localhost -U SA -P "${{ env.DB_MSSQL_PASSWORD }}" -Q "SELECT @@VERSION"
75+
run: |
76+
sqlcmd -S localhost,1433 -U SA -P "${{ env.DB_MSSQL_PASSWORD }}" -Q "SELECT @@VERSION"
5777
5878
- name: Run Test
5979
run: dotnet test --no-build --verbosity normal

0 commit comments

Comments
 (0)