-
Notifications
You must be signed in to change notification settings - Fork 27
171 lines (157 loc) · 6.74 KB
/
ci.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
name: CI
on:
push:
branches:
- master
- release-*
pull_request:
workflow_dispatch:
env:
DOTNET_NOLOGO: true
jobs:
build:
name: ${{ matrix.os-name }}-${{ matrix.engine }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-2022, ubuntu-22.04]
engine: [SqlServer, MySql, PostgreSql, Oracle]
include:
# Add os-name alias for job name
- os: windows-2022
os-name: Windows
- os: ubuntu-22.04
os-name: Linux
fail-fast: false
steps:
- name: Check for secrets
env:
SECRETS_AVAILABLE: ${{ secrets.SECRETS_AVAILABLE }}
shell: pwsh
run: exit $(If ($env:SECRETS_AVAILABLE -eq 'true') { 0 } Else { 1 })
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Setup .NET SDK
uses: actions/[email protected]
with:
dotnet-version: 8.0.x
- name: Build
run: dotnet build src --configuration Release
- name: Upload packages
uses: actions/[email protected]
with:
name: NuGet packages
path: nugets/
retention-days: 7
- name: Azure login
uses: azure/[email protected]
if: matrix.engine == 'PostgreSQL' || (matrix.engine == 'Oracle' && matrix.os-name == 'Windows')
with:
creds: ${{ secrets.AZURE_ACI_CREDENTIALS }}
- name: Setup SQL Server
if: matrix.engine == 'SqlServer'
uses: Particular/[email protected]
with:
connection-string-env-var: SQLServerConnectionString
catalog: nservicebus
extra-params: "Encrypt=False;"
- name: Setup PostgreSql 15.x
id: setup-postgresql
if: matrix.engine == 'PostgreSql'
shell: pwsh
run: |
echo "Getting the Azure region in which this workflow is running..."
$hostInfo = curl -H Metadata:true --noproxy "*" "http://169.254.169.254/metadata/instance?api-version=2021-02-01" | ConvertFrom-Json
$region = $hostInfo.compute.location
echo "Actions agent running in Azure region: $region"
$name = "postgres-$(Get-Random)"
$packageTag = "Package=SqlPersistence"
$runnerOsTag = "RunnerOS=$($Env:RUNNER_OS)"
$dateTag = "Created=$(Get-Date -Format "yyyy-MM-dd")"
$password = [guid]::NewGuid().ToString("n")
echo "::add-mask::$password"
echo "Creating PostgreSQL container $name (This can take a while)"
$details = az container create --image postgres:15 --name $name --location $region --dns-name-label $name --resource-group GitHubActions-RG --cpu 2 --memory 8 --ports 5432 --ip-address public --environment-variables POSTGRES_PASSWORD="$password" | ConvertFrom-Json
echo "name=$name" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf-8 -Append
echo "Tagging container"
$ignore = az tag create --resource-id $details.id --tags $packageTag $runnerOsTag $dateTag
$fqdn = $details.ipAddress.fqdn
echo "::add-mask::$fqdn"
$connectionString = "User ID=postgres;Password=$password;Host=$fqdn;Port=5432;Database=postgres;"
echo "PostgreSqlConnectionString=$connectionString" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
$env:PGPASSWORD = $password
# psql not in PATH on Windows
if ($Env:RUNNER_OS -eq 'Windows') {
$Env:PATH = $Env:PATH + ';' + $Env:PGBIN
}
for ($i = 0; $i -lt 24; $i++) { ## 2 minute timeout
echo "Checking for PostgreSQL connectivity $($i+1)/30..."
$ignore = psql --host $fqdn --username=postgres --list
if ($?) {
echo "Connection successful"
break;
}
sleep 5
}
- name: Setup MySQL
id: setup-mysql
if: matrix.engine == 'MySql'
shell: pwsh
run: |
echo '[client]
user=root
host=localhost' >> mysql-login
if ($Env:RUNNER_OS -eq 'Windows') {
echo "Installing MySQL from Chocolatey"
choco install mysql --limitoutput
echo 'password=' >> mysql-login
} else {
echo "Starting MySQL service preinstalled on Linux agent"
sudo systemctl start mysql.service
echo 'password=root' >> mysql-login
}
for ($i = 0; $i -lt 30; $i++) { ## 2.5 minute timeout
echo "Checking for MySQL connectivity $($i+1)/30..."
$ignore = mysql --defaults-extra-file=mysql-login -e "show databases;"
if ($?) {
echo "Connection successful"
break;
}
sleep 5
}
echo "Creating nservicebus database"
mysql --defaults-extra-file=mysql-login -D mysql -e "create database if not exists nservicebus ;"
echo "Creating user particular"
mysql --defaults-extra-file=mysql-login -D mysql -e "create user particular identified by 'Welcome1' ;"
echo "Giving user particular access to schema nservicebus"
mysql --defaults-extra-file=mysql-login -D mysql -e "grant all on *.* to particular@'%' ;"
$connectionString = "Data Source=localhost;Initial Catalog=nservicebus;User ID=particular;Password=Welcome1;AllowUserVariables=True;AutoEnlist=false;Connect Timeout=60"
echo "MySQLConnectionString=$connectionString" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
- name: Setup Oracle
id: setup-oracle
if: matrix.engine == 'Oracle'
uses: Particular/[email protected]
with:
connection-string-name: OracleConnectionString
init-script: ./.github/workflows/scripts/setup-oracle-database-users-and-permissions.sql
tag: SqlPersistence
- name: Prepare Connection Strings for Oracle
if: matrix.engine == 'Oracle'
shell: pwsh
run: |
$connectionString = $Env:OracleConnectionString
"OracleConnectionString=$($connectionString.Replace('system', 'particular'))" >> $Env:GITHUB_ENV
"OracleConnectionString_Particular2=$($connectionString.Replace('system', 'particular2'))" >> $Env:GITHUB_ENV
- name: Run tests
uses: Particular/[email protected]
- name: Teardown infrastructure
if: ${{ always() }}
shell: pwsh
run: |
if ('${{ matrix.engine }}' -eq 'PostgreSql') {
echo "Removing container ${{ steps.setup-postgresql.outputs.name }}"
$ignore = az container delete --resource-group GitHubActions-RG --name ${{ steps.setup-postgresql.outputs.name }} --yes
echo "Removal complete"
}