run postgress install in parallel #57
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: .Net Framework Tests (Legacy) | |
defaults: | |
run: | |
shell: bash | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "*" ] | |
paths: | |
- "**" | |
- "!**.md" | |
jobs: | |
# As this can run only on Windows machines, these tests should run only in CI | |
end2end-tests: | |
name: End-to-End Tests | |
runs-on: windows-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Load .env file | |
uses: xom9ikk/dotenv@v2.3.0 | |
with: | |
load-mode: strict | |
- name: Setup Visual Studio for .NET Framework | |
uses: microsoft/setup-msbuild@v1 | |
with: | |
vs-version: 'latest' | |
- name: Setup NuGet | |
uses: NuGet/setup-nuget@v2.0.1 | |
- name: Install Chocolatey | |
shell: powershell | |
run: | | |
Set-ExecutionPolicy Bypass -Scope Process -Force | |
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 | |
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) | |
# - uses: ikalnytskyi/action-setup-postgres@v7 | |
# with: | |
# username: ${{ env.POSTGRES_USER }} | |
# password: ${{ env.POSTGRES_PASSWORD }} | |
# database: ${{ env.TESTS_DB }} | |
# postgres-version: "16" | |
# id: postgres | |
# - name: Init PostgresSQL Schema | |
# shell: powershell | |
# run: psql -U $Env:POSTGRES_USER -f 'examples/config/postgresql/schema.sql' | |
# env: | |
# PGSERVICE: ${{ steps.postgres.outputs.service-name }} | |
# PGPASSWORD: ${{ env.POSTGRES_PASSWORD }} | |
- name: Install MySQL and restore test projects in parallel | |
shell: pwsh | |
run: | | |
$mysqlJob = Start-Job -ScriptBlock { | |
choco install mysql --no-progress --version=8.0.31 -y --params "/serviceName:MySQL" | |
return $LASTEXITCODE | |
} | |
$PostgresJob = Start-Job -ScriptBlock { | |
choco install postgresql16 -y --no-progress --version 16.0.0 ` | |
--install-arguments "--enable-components server,commandlinetools --extract-only 1" ` | |
--package-parameters "/Password:pass" ` | |
--params-global | |
$PG_BINDIR = & "$env:PROGRAMFILES/PostgreSQL/16/bin/pg_config.exe" --bindir | |
$PG_LIBDIR = & "$env:PROGRAMFILES/PostgreSQL/16/bin/pg_config.exe" --libdir | |
Add-Content -Path $env:GITHUB_PATH -Value $PG_BINDIR | |
Set-Content -Path $env:GITHUB_ENV -Value "PQ_LIB_DIR=${PG_LIBDIR}" | |
$PGDATA = "$env:RUNNER_TEMP/pgdata" | |
$PWFILE = "$env:RUNNER_TEMP/pwfile" | |
$DEFAULT_ENCODING = "UTF-8" | |
$DEFAULT_LOCALE = $env:DEFAULT_LOCALE -replace "\.", "" -replace "_", "-" | |
Set-Content -Path $PWFILE -Value $env:POSTGRES_PASSWORD | |
& initdb ` | |
--pgdata="$PGDATA" ` | |
--username="$env:POSTGRES_USER" ` | |
--pwfile="$PWFILE" ` | |
--auth="scram-sha-256" ` | |
--encoding="$DEFAULT_ENCODING" ` | |
--locale="$DEFAULT_LOCALE" ` | |
--no-instructions | |
Add-Content -Path "$PGDATA/postgresql.conf" -Value "unix_socket_directories = ''" | |
Add-Content -Path "$PGDATA/postgresql.conf" -Value "port = 5432" | |
& pg_ctl start --pgdata="$PGDATA" | |
$pgServiceConf = @" | |
[${env:POSTGRES_USER}] | |
host=localhost | |
port=5432 | |
user=${env:POSTGRES_USER} | |
password=${env:POSTGRES_PASSWORD} | |
dbname=${env:TESTS_DB} | |
"@ | |
Set-Content -Path "$PGDATA/pg_service.conf" -Value $pgServiceConf | |
& createdb -O "$env:POSTGRES_USER" "$env:TESTS_DB" | |
return $LASTEXITCODE | |
} | |
$restoreJob = Start-Job -ScriptBlock { | |
Get-ChildItem -Path examples -Recurse -Filter *.csproj | | |
Where-Object { $_.FullName -like '*Legacy*' } | | |
ForEach-Object { nuget restore $_.FullName } | |
nuget restore ./EndToEndCommon/EndToEndCommon.csproj | |
nuget restore ./LegacyEndToEndTests/LegacyEndToEndTests.csproj | |
msbuild.exe ./LegacyEndToEndTests/LegacyEndToEndTests.csproj -p:Configuration=Release -p:FrameworkVersion=v4.7.2 | |
return $LASTEXITCODE | |
} | |
$mysqlOutput = Receive-Job -Job $mysqlJob -Wait | |
$mysqlExitCode = @($mysqlOutput)[-1] | |
if ($mysqlExitCode -ne 0) { | |
Write-Error "MySQL install failed with exit code: $mysqlExitCode" | |
return $mysqlExitCode | |
} | |
$postgresOutput = Receive-Job -Job $PostgresJob -Wait | |
$postgressExitCode = @($postgresOutput)[-1] | |
if ($postgressExitCode -ne 0) { | |
Write-Error "Postgres install failed with exit code: $postgressExitCode" | |
return $postgressExitCode | |
} | |
$restoreOutput = Receive-Job -Job $restoreJob -Wait | |
$restoreExitCode = @($restoreOutput)[-1] | |
if ($restoreExitCode -ne 0) { | |
Write-Error "Restore/build failed with exit code: $restoreExitCode" | |
return $restoreExitCode | |
} | |
- name: Init MySQL Schema | |
shell: powershell | |
run: | | |
$env:Path += ";C:\Program Files\MySQL\MySQL Server 8.0\bin" | |
[Environment]::SetEnvironmentVariable("Path", $env:Path, "Machine") | |
mysql -u root -e "CREATE DATABASE $Env:TESTS_DB;" | |
mysql -u root $Env:TESTS_DB --execute="source examples/config/mysql/schema.sql" | |
- name: Run Tests | |
shell: powershell | |
run: | | |
$path = vswhere -latest -products * -requires Microsoft.VisualStudio.Workload.ManagedDesktop Microsoft.VisualStudio.Workload.Web -requiresAny -property installationPath | |
$path = join-path $path 'Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe' | |
& $path ./LegacyEndToEndTests/bin/Release/net472/LegacyEndToEndTests.dll |