/
action.yml
69 lines (60 loc) · 3.02 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
name: Run SQL Server
description: Runs SQL Server using a method appropriate for the target platform
inputs:
connection-string-env-var:
description: Name of the output environment variable that will receive the connection string
required: true
catalog:
description: Name of the initial database name (catalog) to create
required: false
default: nservicebus
extra-params:
description: Extra parameters to add to the connection string
required: false
runs:
using: "composite"
steps:
- name: Install SQL Server (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
# Windows SQL install via Chocolatey
echo "Installing SQL Server Express with Chocolatey..."
choco install sql-server-express --no-progress
echo "Setting environment variables for sqlcmd..."
echo "SQLCMDSERVER=.\SQLEXPRESS" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
echo "Setting environment variable ${{ inputs.connection-string-env-var }} to SQL connection string..."
echo "${{ inputs.connection-string-env-var }}=Data Source=.\SQLEXPRESS;Initial Catalog=${{ inputs.catalog }};Integrated Security=True;Encrypt=false;${{ inputs.extra-params }}" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
- name: Start SQL Server (Linux)
if: runner.os == 'Linux'
shell: bash
run: |
# Linux SQL install via Docker
# If the password generator needs to be changed, make sure the resulting password meets SQL Server password requirements
sa_pw=$(uuidgen)
echo "::add-mask::$sa_pw"
echo "Starting SQL Server in a Docker container..."
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=$sa_pw" -e "MSSQL_PID=Developer" -e "MSSQL_COLLATION=SQL_Latin1_General_CP1_CS_AS" -p 1433:1433 --name sqlserver -d mcr.microsoft.com/mssql/server:2022-latest
echo "Setting environment variables for sqlcmd..."
echo "SQLCMDPASSWORD=$sa_pw" >> $GITHUB_ENV
echo "SQLCMDUSER=sa" >> $GITHUB_ENV
echo "SQLCMDSERVER=localhost,1433" >> $GITHUB_ENV
echo "Setting environment variable ${{ inputs.connection-string-env-var }} to SQL connection string..."
echo "${{ inputs.connection-string-env-var }}=Server=localhost;Database=${{ inputs.catalog }};User Id=sa;Password=$sa_pw;Encrypt=false;${{ inputs.extra-params }}" >> $GITHUB_ENV
- name: Setup server
shell: pwsh
run: |
# Wait for availability then create initial catalog
for ($i = 1; $i -le 30; $i++) {
echo "Attempt $i/30 to connect to SQL Server..."
sqlcmd -b -Q "SELECT @@SERVERNAME as ServerName" 2>&1>$null
if ($?) {
echo " - SQL Server is now ready"
break
} else {
echo " - Not ready, sleeping for 5s"
Start-Sleep -seconds 5
}
}
echo "Creating initial catalog '${{ inputs.catalog }}'"
sqlcmd -Q "CREATE DATABASE [${{ inputs.catalog }}]"