From ab6dd483a8e2e63f466cb193120dd53ccb64125a Mon Sep 17 00:00:00 2001 From: max-ieremenko Date: Tue, 28 Nov 2023 03:42:00 +0100 Subject: [PATCH] test --- .github/workflows/ci.yml | 3 +- Build/build.ps1 | 13 +-- Build/scripts/Get-CurentEnvironment.ps1 | 11 ++ Build/scripts/Import-All.ps1 | 4 + Build/scripts/Start-Container.ps1 | 10 +- Build/scripts/Start-Mysql.ps1 | 28 ----- Build/scripts/Start-Pgsql.ps1 | 28 ----- Build/scripts/Wait-Mysql.ps1 | 5 + Build/scripts/Wait-Pgsql.ps1 | 5 + Build/scripts/github/Start-Mssql.ps1 | 23 ++++ Build/scripts/github/Start-Mysql.ps1 | 31 +++++ Build/scripts/github/Start-Pgsql.ps1 | 32 +++++ Build/scripts/github/mysql.init.sql | 1 + Build/scripts/{ => local}/Start-Mssql.ps1 | 16 +-- Build/scripts/local/Start-Mysql.ps1 | 25 ++++ Build/scripts/local/Start-Pgsql.ps1 | 25 ++++ Build/tasks/build-tasks.it-linux.ps1 | 14 +-- Build/tasks/build-tasks.it-ps-core.ps1 | 10 +- Build/tasks/build-tasks.it-ps-desktop.ps1 | 10 +- Build/tasks/build-tasks.it-tool-linux.ps1 | 8 +- Build/tasks/build-tasks.it-win.ps1 | 10 +- Build/tasks/build-tasks.ps1 | 135 +++++++++++----------- Build/tasks/build-tasks.third-party.ps1 | 14 +-- Build/tasks/build-tasks.unit-test.ps1 | 35 +++--- Build/tasks/create-images-tasks.ps1 | 29 +++-- 25 files changed, 322 insertions(+), 203 deletions(-) create mode 100644 Build/scripts/Get-CurentEnvironment.ps1 create mode 100644 Build/scripts/Import-All.ps1 delete mode 100644 Build/scripts/Start-Mysql.ps1 delete mode 100644 Build/scripts/Start-Pgsql.ps1 create mode 100644 Build/scripts/github/Start-Mssql.ps1 create mode 100644 Build/scripts/github/Start-Mysql.ps1 create mode 100644 Build/scripts/github/Start-Pgsql.ps1 create mode 100644 Build/scripts/github/mysql.init.sql rename Build/scripts/{ => local}/Start-Mssql.ps1 (55%) create mode 100644 Build/scripts/local/Start-Mysql.ps1 create mode 100644 Build/scripts/local/Start-Pgsql.ps1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88405c2e..7ba2404f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,7 @@ on: branches: - master - 'release/**' + - 'feature/**' paths-ignore: - '**.md' pull_request: @@ -32,7 +33,7 @@ jobs: - name: Build shell: pwsh - run: ./Build/build.ps1 -Mode "github" -GithubToken "${{ secrets.GITHUB_TOKEN }}" + run: ./Build/build.ps1 -GithubToken "${{ secrets.GITHUB_TOKEN }}" - name: Artifacts uses: actions/upload-artifact@v3 diff --git a/Build/build.ps1 b/Build/build.ps1 index 7ce53c07..4cc67397 100644 --- a/Build/build.ps1 +++ b/Build/build.ps1 @@ -4,20 +4,13 @@ [CmdletBinding()] param ( - [Parameter()] - [ValidateSet("local", "github")] - [string] - $Mode, - [Parameter()] [string] $GithubToken ) Set-StrictMode -Version Latest -$ErrorActionPreference = "Stop" - -$file = Join-Path $PSScriptRoot "tasks/build-tasks.ps1" -$task = ($Mode -eq "github") ? "GithubBuild" : "LocalBuild" +$ErrorActionPreference = 'Stop' -Invoke-Build -File $file -Task $task -GithubToken $GithubToken \ No newline at end of file +$file = Join-Path $PSScriptRoot 'tasks/build-tasks.ps1' +Invoke-Build -File $file -GithubToken $GithubToken \ No newline at end of file diff --git a/Build/scripts/Get-CurentEnvironment.ps1 b/Build/scripts/Get-CurentEnvironment.ps1 new file mode 100644 index 00000000..a863edd0 --- /dev/null +++ b/Build/scripts/Get-CurentEnvironment.ps1 @@ -0,0 +1,11 @@ +function Get-CurentEnvironment { + param () + + # github actions environment + if ($env:GITHUB_ACTIONS -eq 'true') { + 'github' + } + else { + 'local' + } +} \ No newline at end of file diff --git a/Build/scripts/Import-All.ps1 b/Build/scripts/Import-All.ps1 new file mode 100644 index 00000000..5585b619 --- /dev/null +++ b/Build/scripts/Import-All.ps1 @@ -0,0 +1,4 @@ +Get-ChildItem -Path $PSScriptRoot -Filter *.ps1 | Where-Object { $_.Name -ne 'Import-All.ps1' } | ForEach-Object { . $_.FullName } + +$currentEnv = Get-CurentEnvironment +Get-ChildItem -Path (Join-Path $PSScriptRoot $currentEnv) -Filter *.ps1 | ForEach-Object { . $_.FullName } \ No newline at end of file diff --git a/Build/scripts/Start-Container.ps1 b/Build/scripts/Start-Container.ps1 index f1e39472..dce26383 100644 --- a/Build/scripts/Start-Container.ps1 +++ b/Build/scripts/Start-Container.ps1 @@ -9,26 +9,26 @@ function Start-Container { $ContainerPort ) - $containerId = exec { + [string]$containerId = exec { docker run ` -d ` -p $ContainerPort ` $Image } - $ip = exec { + [string]$ip = exec { docker inspect ` - --format "{{.NetworkSettings.Networks.bridge.IPAddress}}" ` + --format '{{.NetworkSettings.Networks.bridge.IPAddress}}' ` $containerId } - $hostPort = exec { + [int]$hostPort = exec { docker inspect ` --format "{{(index (index .NetworkSettings.Ports \""$ContainerPort/tcp\"") 0).HostPort}}" ` $containerId } - return @{ + @{ containerId = $containerId ip = $ip port = $hostPort diff --git a/Build/scripts/Start-Mysql.ps1 b/Build/scripts/Start-Mysql.ps1 deleted file mode 100644 index 8bc4727b..00000000 --- a/Build/scripts/Start-Mysql.ps1 +++ /dev/null @@ -1,28 +0,0 @@ -function Start-Mysql { - param () - - $sqlConnectordll = Join-Path $env:USERPROFILE "\.nuget\packages\mysqlconnector\1.3.10\lib\netstandard2.0\MySqlConnector.dll" - Add-Type -Path $sqlConnectordll - - $container = Start-Container -Image sqldatabase/mysql:8.0.25 -ContainerPort 3306 - - $builder = New-Object -TypeName MySqlConnector.MySqlConnectionStringBuilder - $builder["Database"] = "sqldatabasetest" - $builder["User ID"] = "root" - $builder["Password"] = "qwerty" - $builder["ConnectionTimeout"] = 5 - - $builder.Server = "localhost" - $builder.Port = $container.port.ToString() - $connectionString = $builder.ToString() - - $builder.Server = $container.ip.ToString() - $builder.Port = 3306 - $remoteConnectionString = $builder.ToString() - - return @{ - containerId = $container.containerId - connectionString = $connectionString - remoteConnectionString = $remoteConnectionString - } -} \ No newline at end of file diff --git a/Build/scripts/Start-Pgsql.ps1 b/Build/scripts/Start-Pgsql.ps1 deleted file mode 100644 index d1a0d01c..00000000 --- a/Build/scripts/Start-Pgsql.ps1 +++ /dev/null @@ -1,28 +0,0 @@ -function Start-Pgsql { - param () - - $npgsqldll = Join-Path $env:USERPROFILE ".nuget\packages\npgsql\4.0.11\lib\netstandard2.0\Npgsql.dll" - Add-Type -Path $npgsqldll - - $container = Start-Container -Image sqldatabase/postgres:13.3 -ContainerPort 5432 - - $builder = New-Object -TypeName Npgsql.NpgsqlConnectionStringBuilder - $builder["Database"] = "sqldatabasetest" - $builder["Username"] = "postgres" - $builder["Password"] = "qwerty" - $builder["Timeout"] = 5 - - $builder.Host = "localhost" - $builder.Port = $container.port.ToString() - $connectionString = $builder.ToString() - - $builder.Host = $container.ip.ToString() - $builder.Port = 5432 - $remoteConnectionString = $builder.ToString() - - return @{ - containerId = $container.containerId - connectionString = $connectionString - remoteConnectionString = $remoteConnectionString - } -} \ No newline at end of file diff --git a/Build/scripts/Wait-Mysql.ps1 b/Build/scripts/Wait-Mysql.ps1 index 0a3ec755..3b11fc84 100644 --- a/Build/scripts/Wait-Mysql.ps1 +++ b/Build/scripts/Wait-Mysql.ps1 @@ -5,5 +5,10 @@ function Wait-Mysql { $ConnectionString ) + if (-not ('MySqlConnector.MySqlConnection' -as [type])) { + $sqlConnectordll = Join-Path $env:USERPROFILE '\.nuget\packages\mysqlconnector\1.3.10\lib\netstandard2.0\MySqlConnector.dll' + Add-Type -Path $sqlConnectordll + } + Wait-Connection -ConnectionName MySqlConnector.MySqlConnection -ConnectionString $ConnectionString } \ No newline at end of file diff --git a/Build/scripts/Wait-Pgsql.ps1 b/Build/scripts/Wait-Pgsql.ps1 index dc2ea406..2a45039e 100644 --- a/Build/scripts/Wait-Pgsql.ps1 +++ b/Build/scripts/Wait-Pgsql.ps1 @@ -5,5 +5,10 @@ function Wait-Pgsql { $ConnectionString ) + if (-not ('Npgsql.NpgsqlConnection' -as [type])) { + $npgsqldll = Join-Path $env:USERPROFILE '.nuget\packages\npgsql\4.0.11\lib\netstandard2.0\Npgsql.dll' + Add-Type -Path $npgsqldll + } + Wait-Connection -ConnectionName Npgsql.NpgsqlConnection -ConnectionString $ConnectionString } \ No newline at end of file diff --git a/Build/scripts/github/Start-Mssql.ps1 b/Build/scripts/github/Start-Mssql.ps1 new file mode 100644 index 00000000..562c6267 --- /dev/null +++ b/Build/scripts/github/Start-Mssql.ps1 @@ -0,0 +1,23 @@ +function Start-Mssql { + param () + + exec { sqllocaldb.exe s MSSQLLocalDB } + + $dataSource = '(localdb)\MSSQLLocalDB' + $database = 'SqlDatabaseTest' + + $databases = exec { sqlcmd.exe -S $dataSource -l 15 -Q 'select Name from sys.databases' } + $databaseExists = $databases | Where-Object { $_.Trim() -eq $database } + if (-not $databaseExists) { + $file = Join-Path $PSScriptRoot '..\..\..\Sources\Docker\mssql.create-database.sql' + $file = [System.IO.Path]::GetFullPath($file) + Set-Content -Path $file -Value (Get-Content -Path $file -Raw) + + exec { sqlcmd.exe -S $dataSource -i $file } + } + + @{ + containerId = '' + connectionString = "Data Source=$dataSource;Initial Catalog=$database;Integrated Security=true;Connect Timeout=5" + } +} \ No newline at end of file diff --git a/Build/scripts/github/Start-Mysql.ps1 b/Build/scripts/github/Start-Mysql.ps1 new file mode 100644 index 00000000..e08d3eb1 --- /dev/null +++ b/Build/scripts/github/Start-Mysql.ps1 @@ -0,0 +1,31 @@ +function Start-Mysql { + param () + + $port = 3306 + + if (-not (Test-Connection -TargetName localhost -TcpPort $port -ErrorAction Continue)) { + exec { mysqld.exe --console --initialize } + + $file = Join-Path $PSScriptRoot mysql.init.sql + exec { mysqld.exe --console --init-file=$file & } + + for ($i = 0; $i -lt 3; $i++) { + if (Test-Connection -TargetName localhost -TcpPort $port -ErrorAction Continue) { + break + } + + Start-Sleep 2 + } + + $file = Join-Path $PSScriptRoot '..\..\..\Sources\Docker\mysql.create-database.sql' + $file = [System.IO.Path]::GetFullPath($file) + Set-Content -Path $file -Value (Get-Content -Path $file -Raw) + + exec { mysql.exe -uroot -proot -e "source $file" } + } + + return @{ + containerId = '' + connectionString = "Server=localhost;Port=$port;Database=sqldatabasetest;User ID=root;Password=root;Connection Timeout=5;" + } +} \ No newline at end of file diff --git a/Build/scripts/github/Start-Pgsql.ps1 b/Build/scripts/github/Start-Pgsql.ps1 new file mode 100644 index 00000000..562faf85 --- /dev/null +++ b/Build/scripts/github/Start-Pgsql.ps1 @@ -0,0 +1,32 @@ +function Start-Pgsql { + param () + + $port = 5432 + + if (-not (Test-Connection -TargetName localhost -TcpPort $port -ErrorAction Continue)) { + Set-Service 'postgresql-x64-14' -StartupType Manual + Start-Service 'postgresql-x64-14' + + for ($i = 0; $i -lt 3; $i++) { + if (Test-Connection -TargetName localhost -TcpPort $port -ErrorAction Continue) { + break + } + + Start-Sleep 2 + } + + $file = Join-Path $PSScriptRoot '..\..\..\Sources\Docker\pgsql.create-database.sql' + $file = [System.IO.Path]::GetFullPath($file) + Set-Content -Path $file -Value (Get-Content -Path $file -Raw) + + $env:PGPASSWORD = 'root' + + $psql = Join-Path $env:PGBIN 'psql.exe' + exec { & $psql -U postgres -a -f $file } + } + + @{ + containerId = '' + connectionString = "Host=localhost;Port=$port;Database=sqldatabasetest;Username=postgres;Password=root;Timeout=5;" + } +} \ No newline at end of file diff --git a/Build/scripts/github/mysql.init.sql b/Build/scripts/github/mysql.init.sql new file mode 100644 index 00000000..ee68dbea --- /dev/null +++ b/Build/scripts/github/mysql.init.sql @@ -0,0 +1 @@ +ALTER USER 'root'@'localhost' IDENTIFIED BY 'root'; \ No newline at end of file diff --git a/Build/scripts/Start-Mssql.ps1 b/Build/scripts/local/Start-Mssql.ps1 similarity index 55% rename from Build/scripts/Start-Mssql.ps1 rename to Build/scripts/local/Start-Mssql.ps1 index e21b0f8c..f470181f 100644 --- a/Build/scripts/Start-Mssql.ps1 +++ b/Build/scripts/local/Start-Mssql.ps1 @@ -4,19 +4,19 @@ function Start-Mssql { $container = Start-Container -Image sqldatabase/mssql:2017 -ContainerPort 1433 $port = $container.port - $builder = New-Object -TypeName System.Data.SqlClient.SqlConnectionStringBuilder - $builder["Initial Catalog"] = "SqlDatabaseTest" - $builder["User Id"] = "sa" - $builder["Password"] = "P@ssw0rd" - $builder["Connect Timeout"] = 5 + $builder = New-Object -TypeName System.Data.Common.DbConnectionStringBuilder + $builder['Data Source'] = ".,$port" + $builder['Initial Catalog'] = 'SqlDatabaseTest' + $builder['User Id'] = 'sa' + $builder['Password'] = 'P@ssw0rd' + $builder['Connect Timeout'] = 5 - $builder["Data Source"] = ".,$port" $connectionString = $builder.ToString() - $builder["Data Source"] = $container.ip + $builder['Data Source'] = $container.ip $remoteConnectionString = $builder.ToString() - return @{ + @{ containerId = $container.containerId connectionString = $connectionString remoteConnectionString = $remoteConnectionString diff --git a/Build/scripts/local/Start-Mysql.ps1 b/Build/scripts/local/Start-Mysql.ps1 new file mode 100644 index 00000000..107fd1c4 --- /dev/null +++ b/Build/scripts/local/Start-Mysql.ps1 @@ -0,0 +1,25 @@ +function Start-Mysql { + param () + + $container = Start-Container -Image sqldatabase/mysql:8.0.25 -ContainerPort 3306 + + $builder = New-Object -TypeName System.Data.Common.DbConnectionStringBuilder + $builder['Database'] = 'sqldatabasetest' + $builder['User ID'] = 'root' + $builder['Password'] = 'qwerty' + $builder['Connection Timeout'] = 5 + + $builder['Server'] = 'localhost' + $builder['Port'] = $container.port + $connectionString = $builder.ToString() + + $builder['Server'] = $container.ip + $builder['Port'] = 3306 + $remoteConnectionString = $builder.ToString() + + @{ + containerId = $container.containerId + connectionString = $connectionString + remoteConnectionString = $remoteConnectionString + } +} \ No newline at end of file diff --git a/Build/scripts/local/Start-Pgsql.ps1 b/Build/scripts/local/Start-Pgsql.ps1 new file mode 100644 index 00000000..7baa85fd --- /dev/null +++ b/Build/scripts/local/Start-Pgsql.ps1 @@ -0,0 +1,25 @@ +function Start-Pgsql { + param () + + $container = Start-Container -Image sqldatabase/postgres:13.3 -ContainerPort 5432 + + $builder = New-Object -TypeName System.Data.Common.DbConnectionStringBuilder + $builder['Database'] = 'sqldatabasetest' + $builder['Username'] = 'postgres' + $builder['Password'] = 'qwerty' + $builder['Timeout'] = 5 + + $builder['Host'] = 'localhost' + $builder['Port'] = $container.port + $connectionString = $builder.ToString() + + $builder['Host'] = $container.ip + $builder['Port'] = 5432 + $remoteConnectionString = $builder.ToString() + + @{ + containerId = $container.containerId + connectionString = $connectionString + remoteConnectionString = $remoteConnectionString + } +} \ No newline at end of file diff --git a/Build/tasks/build-tasks.it-linux.ps1 b/Build/tasks/build-tasks.it-linux.ps1 index 90bbc882..2eae56c3 100644 --- a/Build/tasks/build-tasks.it-linux.ps1 +++ b/Build/tasks/build-tasks.it-linux.ps1 @@ -7,11 +7,11 @@ param( task Default StartDatabase, UnZip, RunTest -Get-ChildItem -Path (Join-Path $PSScriptRoot '../scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName } +. (Join-Path $PSScriptRoot '../scripts/Import-All.ps1') -$containerId = "" -$connectionString = "" -$remoteConnectionString = "" +$containerId = '' +$connectionString = '' +$remoteConnectionString = '' $tempDir = Join-Path $settings.bin ([Guid]::NewGuid().ToString()) Enter-Build { @@ -38,8 +38,8 @@ task StartDatabase { task RunTest { & "Wait-$database" $connectionString - $app = $tempDir + ":/app" - $test = (Join-Path $settings.integrationTests $database) + ":/test" + $app = $tempDir + ':/app' + $test = (Join-Path $settings.integrationTests $database) + ':/test' exec { docker run --rm ` @@ -47,7 +47,7 @@ task RunTest { -v $test ` --env connectionString=$remoteConnectionString ` --env test=/test ` - -w "/app" ` + -w '/app' ` $image ` bash /test/Test.sh } diff --git a/Build/tasks/build-tasks.it-ps-core.ps1 b/Build/tasks/build-tasks.it-ps-core.ps1 index a12bb7d7..67b04811 100644 --- a/Build/tasks/build-tasks.it-ps-core.ps1 +++ b/Build/tasks/build-tasks.it-ps-core.ps1 @@ -6,10 +6,10 @@ param( task Default StartDatabase, RunTest -Get-ChildItem -Path (Join-Path $PSScriptRoot '../scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName } +. (Join-Path $PSScriptRoot '../scripts/Import-All.ps1') -$containerId = "" -$connectionString = "" +$containerId = '' +$connectionString = '' Enter-Build { Write-Output "$database on $image" @@ -26,8 +26,8 @@ task StartDatabase { } task RunTest { - $app = $settings.artifactsPowerShell + ":/root/.local/share/powershell/Modules/SqlDatabase" - $test = (Join-Path $settings.integrationTests $database) + ":/test" + $app = $settings.artifactsPowerShell + ':/root/.local/share/powershell/Modules/SqlDatabase' + $test = (Join-Path $settings.integrationTests $database) + ':/test' exec { docker run --rm ` diff --git a/Build/tasks/build-tasks.it-ps-desktop.ps1 b/Build/tasks/build-tasks.it-ps-desktop.ps1 index 73741b81..2ff495dd 100644 --- a/Build/tasks/build-tasks.it-ps-desktop.ps1 +++ b/Build/tasks/build-tasks.it-ps-desktop.ps1 @@ -5,11 +5,11 @@ param( task Default RunContainers, CopyModule, PublishModule, RunTest -Get-ChildItem -Path (Join-Path $PSScriptRoot '../scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName } +. (Join-Path $PSScriptRoot '../scripts/Import-All.ps1') -$containerId = "" -$connectionString = "" -$testDir = Join-Path ([Environment]::GetFolderPath("MyDocuments")) "WindowsPowerShell\modules\SqlDatabase" +$containerId = '' +$connectionString = '' +$testDir = Join-Path ([Environment]::GetFolderPath('MyDocuments')) 'WindowsPowerShell\modules\SqlDatabase' task CopyModule { if (Test-Path $testDir) { @@ -20,7 +20,7 @@ task CopyModule { } task PublishModule { - $log = Join-Path $settings.artifacts "Publish-Module.whatif.log" + $log = Join-Path $settings.artifacts 'Publish-Module.whatif.log' $command = "Publish-Module -Name SqlDatabase -WhatIf -Verbose -NuGetApiKey 123 *> $log" exec { powershell -NoLogo -Command "$command" } diff --git a/Build/tasks/build-tasks.it-tool-linux.ps1 b/Build/tasks/build-tasks.it-tool-linux.ps1 index 87aac1b2..d99d2e86 100644 --- a/Build/tasks/build-tasks.it-tool-linux.ps1 +++ b/Build/tasks/build-tasks.it-tool-linux.ps1 @@ -6,10 +6,10 @@ param( task Default StartDatabase, RunTest -Get-ChildItem -Path (Join-Path $PSScriptRoot '../scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName } +. (Join-Path $PSScriptRoot '../scripts/Import-All.ps1') -$containerId = "" -$connectionString = "" +$containerId = '' +$connectionString = '' Enter-Build { Write-Output "$database on $image" @@ -29,7 +29,7 @@ task RunTest { $packageVersion = $settings.version $packageName = "SqlDatabase.GlobalTool.$packageVersion.nupkg" $app = (Join-Path $settings.artifacts $packageName) + ":/app/$packageName" - $test = (Join-Path $settings.integrationTests $database) + ":/test" + $test = (Join-Path $settings.integrationTests $database) + ':/test' exec { docker run -it --rm ` diff --git a/Build/tasks/build-tasks.it-win.ps1 b/Build/tasks/build-tasks.it-win.ps1 index 718408cc..a211acce 100644 --- a/Build/tasks/build-tasks.it-win.ps1 +++ b/Build/tasks/build-tasks.it-win.ps1 @@ -6,10 +6,10 @@ param( task Default StartDatabase, UnZip, RunTest -Get-ChildItem -Path (Join-Path $PSScriptRoot '../scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName } +. (Join-Path $PSScriptRoot '../scripts/Import-All.ps1') -$containerId = "" -$connectionString = "" +$containerId = '' +$connectionString = '' $tempDir = Join-Path $settings.bin ([Guid]::NewGuid().ToString()) Enter-Build { @@ -35,9 +35,9 @@ task StartDatabase { task RunTest { & "Wait-$database" $connectionString - $app = Join-Path $tempDir "SqlDatabase.exe" + $app = Join-Path $tempDir 'SqlDatabase.exe' $script = (Join-Path $settings.integrationTests $database) - $script = Join-Path $script "Test.ps1" + $script = Join-Path $script 'Test.ps1' & $script $app $connectionString } diff --git a/Build/tasks/build-tasks.ps1 b/Build/tasks/build-tasks.ps1 index f311e9ee..9a50c698 100644 --- a/Build/tasks/build-tasks.ps1 +++ b/Build/tasks/build-tasks.ps1 @@ -4,34 +4,34 @@ param( $GithubToken ) -task GithubBuild Initialize, Clean, Build, ThirdPartyNotices, Pack -task LocalBuild GithubBuild, UnitTest, IntegrationTest +. (Join-Path $PSScriptRoot '../scripts/Import-All.ps1') + +task Default Initialize, Clean, Build, ThirdPartyNotices, Pack, LocalBuild +task LocalBuild -If { (Get-CurentEnvironment) -ne 'github' } UnitTest, IntegrationTest task Pack PackGlobalTool, PackPoweShellModule, PackNuget472, PackManualDownload task IntegrationTest InitializeIntegrationTest, PsDesktopTest, PsCoreTest, SdkToolTest, NetRuntimeLinuxTest, NetRuntimeWindowsTest -Get-ChildItem -Path (Join-Path $PSScriptRoot '../scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName } - task Initialize { - $root = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot "..\..\")) - $sources = Join-Path $root "Sources" - $bin = Join-Path $root "bin" - $artifacts = Join-Path $bin "artifacts" + $root = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..\..\')) + $sources = Join-Path $root 'Sources' + $bin = Join-Path $root 'bin' + $artifacts = Join-Path $bin 'artifacts' $script:settings = @{ - nugetexe = Join-Path $root "Build\nuget.exe" + nugetexe = Join-Path $root 'Build\nuget.exe' sources = $sources bin = $bin artifacts = $artifacts - artifactsPowerShell = Join-Path $artifacts "PowerShell" - integrationTests = Join-Path $bin "IntegrationTests" + artifactsPowerShell = Join-Path $artifacts 'PowerShell' + integrationTests = Join-Path $bin 'IntegrationTests' version = Get-ReleaseVersion -SourcePath $sources githubToken = $GithubToken repositoryCommitId = git rev-parse HEAD } - $script:frameworks = "net472", "net6.0", "net7.0", "net8.0" - $script:databases = "MsSql", "PgSql", "MySql" + $script:frameworks = 'net472', 'net6.0', 'net7.0', 'net8.0' + $script:databases = 'MsSql', 'PgSql', 'MySql' Write-Output "PackageVersion: $($settings.version)" Write-Output "CommitId: $($settings.repositoryCommitId)" @@ -39,23 +39,23 @@ task Initialize { task Clean { Remove-DirectoryRecurse -Path $settings.bin - Remove-DirectoryRecurse -Path $settings.sources -Filters "bin", "obj" + Remove-DirectoryRecurse -Path $settings.sources -Filters 'bin', 'obj' New-Item -Path $settings.bin -ItemType Directory | Out-Null } task Build { - $solutionFile = Join-Path $settings.sources "SqlDatabase.sln" + $solutionFile = Join-Path $settings.sources 'SqlDatabase.sln' exec { dotnet restore $solutionFile } exec { dotnet build $solutionFile -t:Rebuild -p:Configuration=Release } } task ThirdPartyNotices { - Invoke-Build -File "build-tasks.third-party.ps1" -settings $settings + Invoke-Build -File 'build-tasks.third-party.ps1' -settings $settings } task PackGlobalTool { - $projectFile = Join-Path $settings.sources "SqlDatabase\SqlDatabase.csproj" + $projectFile = Join-Path $settings.sources 'SqlDatabase\SqlDatabase.csproj' exec { dotnet pack ` @@ -70,31 +70,31 @@ task PackGlobalTool { } task PackPoweShellModule { - $source = Join-Path $settings.bin "SqlDatabase.PowerShell\netstandard2.0\" + $source = Join-Path $settings.bin 'SqlDatabase.PowerShell\netstandard2.0\' $dest = $settings.artifactsPowerShell Copy-Item -Path $source -Destination $dest -Recurse # .psd1 set module version - $psdFile = Join-Path $dest "SqlDatabase.psd1" + $psdFile = Join-Path $dest 'SqlDatabase.psd1' ((Get-Content -Path $psdFile -Raw) -replace '1.2.3', $settings.version) | Set-Content -Path $psdFile # copy license - Copy-Item -Path (Join-Path $settings.sources "..\LICENSE.md") -Destination $dest + Copy-Item -Path (Join-Path $settings.sources '..\LICENSE.md') -Destination $dest # copy ThirdPartyNotices - Copy-Item -Path (Join-Path $settings.bin "ThirdPartyNotices.txt") -Destination $dest + Copy-Item -Path (Join-Path $settings.bin 'ThirdPartyNotices.txt') -Destination $dest Get-ChildItem $dest -Include *.pdb -Recurse | Remove-Item } task PackNuget472 PackPoweShellModule, { $bin = $settings.artifactsPowerShell - if (-not $bin.EndsWith("\")) { - $bin += "\" + if (-not $bin.EndsWith('\')) { + $bin += '\' } - $nuspec = Join-Path $settings.sources "SqlDatabase.Package\nuget\package.nuspec" + $nuspec = Join-Path $settings.sources 'SqlDatabase.Package\nuget\package.nuspec' exec { & $($settings.nugetexe) pack ` -NoPackageAnalysis ` @@ -108,16 +108,16 @@ task PackNuget472 PackPoweShellModule, { } task PackManualDownload PackGlobalTool, PackPoweShellModule, { - Get-ChildItem -Path $settings.bin -Recurse -Directory -Filter "publish" | Remove-Item -Force -Recurse - Get-ChildItem -Path $settings.bin -Recurse -Directory -Filter "win-arm64" | Remove-Item -Force -Recurse + Get-ChildItem -Path $settings.bin -Recurse -Directory -Filter 'publish' | Remove-Item -Force -Recurse + Get-ChildItem -Path $settings.bin -Recurse -Directory -Filter 'win-arm64' | Remove-Item -Force -Recurse $out = $settings.artifacts - $lic = Join-Path $settings.sources "..\LICENSE.md" - $thirdParty = Join-Path $settings.bin "ThirdPartyNotices.txt" + $lic = Join-Path $settings.sources '..\LICENSE.md' + $thirdParty = Join-Path $settings.bin 'ThirdPartyNotices.txt' $packageVersion = $settings.version $destination = Join-Path $out "SqlDatabase.$packageVersion-PowerShell.zip" - $source = Join-Path $settings.artifactsPowerShell "*" + $source = Join-Path $settings.artifactsPowerShell '*' Compress-Archive -Path $source -DestinationPath $destination foreach ($target in $frameworks) { @@ -131,13 +131,14 @@ task UnitTest { $builds = @() foreach ($case in $frameworks) { $builds += @{ - File = "build-tasks.unit-test.ps1" + File = 'build-tasks.unit-test.ps1' Sources = $settings.sources Framework = $case } } - Build-Parallel $builds -ShowParameter Framework -MaximumBuilds 4 + $maximumBuilds = ((Get-CurentEnvironment) -eq 'github') ? 1 : 4 + Build-Parallel $builds -ShowParameter Framework -MaximumBuilds $maximumBuilds } task InitializeIntegrationTest { @@ -146,8 +147,8 @@ task InitializeIntegrationTest { Remove-Item -Path $dest -Force -Recurse } - Copy-Item -Path (Join-Path $settings.sources "IntegrationTests") -Destination $dest -Force -Recurse - $assemblyScript = Join-Path $settings.bin "..\Examples\CSharpMirationStep\bin\Release\net472\2.1_2.2.*" + Copy-Item -Path (Join-Path $settings.sources 'IntegrationTests') -Destination $dest -Force -Recurse + $assemblyScript = Join-Path $settings.bin '..\Examples\CSharpMirationStep\bin\Release\net472\2.1_2.2.*' foreach ($database in $databases) { Copy-Item -Path $assemblyScript -Destination (Join-Path $dest "$database\Upgrade") -Force } @@ -158,7 +159,7 @@ task InitializeIntegrationTest { } # fix unix line endings - $test = $dest + ":/test" + $test = $dest + ':/test' exec { docker run --rm ` -v $test ` @@ -171,7 +172,7 @@ task PsDesktopTest { $builds = @() foreach ($database in $databases) { $builds += @{ - File = "build-tasks.it-ps-desktop.ps1" + File = 'build-tasks.it-ps-desktop.ps1' settings = $settings database = $database } @@ -183,28 +184,28 @@ task PsDesktopTest { task PsCoreTest { # show-powershell-images.ps1 $images = $( - "mcr.microsoft.com/powershell:6.1.0-ubuntu-18.04" - , "mcr.microsoft.com/powershell:6.1.1-ubuntu-18.04" - , "mcr.microsoft.com/powershell:6.1.2-ubuntu-18.04" - , "mcr.microsoft.com/powershell:6.1.3-ubuntu-18.04" - , "mcr.microsoft.com/powershell:6.2.0-ubuntu-18.04" - , "mcr.microsoft.com/powershell:6.2.1-ubuntu-18.04" - , "mcr.microsoft.com/powershell:6.2.2-ubuntu-18.04" - , "mcr.microsoft.com/powershell:6.2.3-ubuntu-18.04" - , "mcr.microsoft.com/powershell:6.2.4-ubuntu-18.04" - , "mcr.microsoft.com/powershell:7.0.0-ubuntu-18.04" - , "mcr.microsoft.com/powershell:7.0.1-ubuntu-18.04" - , "mcr.microsoft.com/powershell:7.0.2-ubuntu-18.04" - , "mcr.microsoft.com/powershell:7.0.3-ubuntu-18.04" - , "mcr.microsoft.com/powershell:7.1.0-ubuntu-18.04" - , "mcr.microsoft.com/powershell:7.1.1-ubuntu-20.04" - , "mcr.microsoft.com/powershell:7.1.2-ubuntu-20.04" - , "mcr.microsoft.com/powershell:7.1.3-ubuntu-20.04" - , "mcr.microsoft.com/powershell:7.1.4-ubuntu-20.04" - , "mcr.microsoft.com/powershell:7.2.0-ubuntu-20.04" - , "mcr.microsoft.com/powershell:7.2.1-ubuntu-20.04" - , "mcr.microsoft.com/powershell:7.2.2-ubuntu-20.04" - , "mcr.microsoft.com/powershell:7.3-ubuntu-20.04") + 'mcr.microsoft.com/powershell:6.1.0-ubuntu-18.04' + , 'mcr.microsoft.com/powershell:6.1.1-ubuntu-18.04' + , 'mcr.microsoft.com/powershell:6.1.2-ubuntu-18.04' + , 'mcr.microsoft.com/powershell:6.1.3-ubuntu-18.04' + , 'mcr.microsoft.com/powershell:6.2.0-ubuntu-18.04' + , 'mcr.microsoft.com/powershell:6.2.1-ubuntu-18.04' + , 'mcr.microsoft.com/powershell:6.2.2-ubuntu-18.04' + , 'mcr.microsoft.com/powershell:6.2.3-ubuntu-18.04' + , 'mcr.microsoft.com/powershell:6.2.4-ubuntu-18.04' + , 'mcr.microsoft.com/powershell:7.0.0-ubuntu-18.04' + , 'mcr.microsoft.com/powershell:7.0.1-ubuntu-18.04' + , 'mcr.microsoft.com/powershell:7.0.2-ubuntu-18.04' + , 'mcr.microsoft.com/powershell:7.0.3-ubuntu-18.04' + , 'mcr.microsoft.com/powershell:7.1.0-ubuntu-18.04' + , 'mcr.microsoft.com/powershell:7.1.1-ubuntu-20.04' + , 'mcr.microsoft.com/powershell:7.1.2-ubuntu-20.04' + , 'mcr.microsoft.com/powershell:7.1.3-ubuntu-20.04' + , 'mcr.microsoft.com/powershell:7.1.4-ubuntu-20.04' + , 'mcr.microsoft.com/powershell:7.2.0-ubuntu-20.04' + , 'mcr.microsoft.com/powershell:7.2.1-ubuntu-20.04' + , 'mcr.microsoft.com/powershell:7.2.2-ubuntu-20.04' + , 'mcr.microsoft.com/powershell:7.3-ubuntu-20.04') foreach ($image in $images) { exec { docker pull $image } @@ -214,7 +215,7 @@ task PsCoreTest { foreach ($image in $images) { foreach ($database in $databases) { $builds += @{ - File = "build-tasks.it-ps-core.ps1" + File = 'build-tasks.it-ps-core.ps1' settings = $settings database = $database image = $image @@ -227,15 +228,15 @@ task PsCoreTest { task SdkToolTest { $images = $( - "sqldatabase/dotnet_pwsh:6.0-sdk" - , "sqldatabase/dotnet_pwsh:7.0-sdk" - , "sqldatabase/dotnet_pwsh:8.0-sdk") + 'sqldatabase/dotnet_pwsh:6.0-sdk' + , 'sqldatabase/dotnet_pwsh:7.0-sdk' + , 'sqldatabase/dotnet_pwsh:8.0-sdk') $builds = @() foreach ($image in $images) { foreach ($database in $databases) { $builds += @{ - File = "build-tasks.it-tool-linux.ps1" + File = 'build-tasks.it-tool-linux.ps1' settings = $settings database = $database image = $image @@ -248,16 +249,16 @@ task SdkToolTest { task NetRuntimeLinuxTest { $testCases = $( - @{ targetFramework = "net6.0"; image = "sqldatabase/dotnet_pwsh:6.0-runtime" } - , @{ targetFramework = "net7.0"; image = "sqldatabase/dotnet_pwsh:7.0-runtime" } - , @{ targetFramework = "net8.0"; image = "sqldatabase/dotnet_pwsh:8.0-runtime" } + @{ targetFramework = 'net6.0'; image = 'sqldatabase/dotnet_pwsh:6.0-runtime' } + , @{ targetFramework = 'net7.0'; image = 'sqldatabase/dotnet_pwsh:7.0-runtime' } + , @{ targetFramework = 'net8.0'; image = 'sqldatabase/dotnet_pwsh:8.0-runtime' } ) $builds = @() foreach ($case in $testCases) { foreach ($database in $databases) { $builds += @{ - File = "build-tasks.it-linux.ps1" + File = 'build-tasks.it-linux.ps1' settings = $settings targetFramework = $case.targetFramework database = $database @@ -274,7 +275,7 @@ task NetRuntimeWindowsTest { foreach ($case in $frameworks) { foreach ($database in $databases) { $builds += @{ - File = "build-tasks.it-win.ps1" + File = 'build-tasks.it-win.ps1' settings = $settings targetFramework = $case database = $database diff --git a/Build/tasks/build-tasks.third-party.ps1 b/Build/tasks/build-tasks.third-party.ps1 index 52b3d09f..70d42321 100644 --- a/Build/tasks/build-tasks.third-party.ps1 +++ b/Build/tasks/build-tasks.third-party.ps1 @@ -5,23 +5,23 @@ param( task Default Update, Test, Publish Enter-Build { - $repository = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot "../third-party-libraries")) + $repository = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot '../third-party-libraries')) $sources = $settings.sources } task Update { - Update-ThirdPartyLibrariesRepository -AppName "SqlDatabase" -Source $sources -Repository $repository -GithubPersonalAccessToken $settings.githubToken + Update-ThirdPartyLibrariesRepository -AppName 'SqlDatabase' -Source $sources -Repository $repository -GithubPersonalAccessToken $settings.githubToken } task Test { - Test-ThirdPartyLibrariesRepository -AppName "SqlDatabase" -Source $sources -Repository $repository + Test-ThirdPartyLibrariesRepository -AppName 'SqlDatabase' -Source $sources -Repository $repository } task Publish { - $outTemp = Join-Path $settings.bin "Temp" - $title = "SqlDatabase " + $settings.version - Publish-ThirdPartyNotices -AppName "SqlDatabase" -Repository $repository -Title $title -To $outTemp + $outTemp = Join-Path $settings.bin 'Temp' + $title = 'SqlDatabase ' + $settings.version + Publish-ThirdPartyNotices -AppName 'SqlDatabase' -Repository $repository -Title $title -To $outTemp - Move-Item (Join-Path $outTemp "ThirdPartyNotices.txt") $settings.bin -Force + Move-Item (Join-Path $outTemp 'ThirdPartyNotices.txt') $settings.bin -Force Remove-Item -Path $outTemp -Recurse -Force } \ No newline at end of file diff --git a/Build/tasks/build-tasks.unit-test.ps1 b/Build/tasks/build-tasks.unit-test.ps1 index 05c1b871..dd78a023 100644 --- a/Build/tasks/build-tasks.unit-test.ps1 +++ b/Build/tasks/build-tasks.unit-test.ps1 @@ -5,19 +5,19 @@ param( $Sources, [Parameter(Mandatory)] - [ValidateSet("net472", "net6.0", "net7.0", "net8.0")] + [ValidateSet('net472', 'net6.0', 'net7.0', 'net8.0')] [string] $Framework ) -task Default RunContainers, UpdateConfig, RunTests +. (Join-Path $PSScriptRoot '../scripts/Import-All.ps1') -Get-ChildItem -Path (Join-Path $PSScriptRoot '../scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName } +task Default RunContainers, UpdateConfig, RunTests $containerIds = @() -$mssqlConnectionString = "" -$pgsqlConnectionString = "" -$mysqlConnectionString = "" +$mssqlConnectionString = '' +$pgsqlConnectionString = '' +$mysqlConnectionString = '' Enter-Build { $testList = Get-ChildItem -Path $Sources -Recurse -Filter *.Test.dll ` @@ -27,7 +27,7 @@ Enter-Build { | ForEach-Object { $_.FullName } if (-not $testList) { - throw "Test list is empty." + throw 'Test list is empty.' } $testList @@ -41,17 +41,26 @@ Exit-Build { task RunContainers { $info = Start-Mssql - $script:containerIds += $info.containerId + if ($info.containerId) { + $script:containerIds += $info.containerId + } + $script:mssqlConnectionString = $info.connectionString Write-Output $mssqlConnectionString $info = Start-Pgsql - $script:containerIds += $info.containerId + if ($info.containerId) { + $script:containerIds += $info.containerId + } + $script:pgsqlConnectionString = $info.connectionString Write-Output $pgsqlConnectionString $info = Start-Mysql - $script:containerIds += $info.containerId + if ($info.containerId) { + $script:containerIds += $info.containerId + } + $script:mysqlConnectionString = $info.connectionString Write-Output $mysqlConnectionString @@ -67,19 +76,19 @@ task UpdateConfig { $node = $config.SelectSingleNode("configuration/connectionStrings/add[@name = 'mssql']") if ($node) { - $node.Attributes["connectionString"].InnerText = $mssqlConnectionString + $node.Attributes['connectionString'].InnerText = $mssqlConnectionString $config.Save($configFile) } $node = $config.SelectSingleNode("configuration/connectionStrings/add[@name = 'pgsql']") if ($node) { - $node.Attributes["connectionString"].InnerText = $pgsqlConnectionString + $node.Attributes['connectionString'].InnerText = $pgsqlConnectionString $config.Save($configFile) } $node = $config.SelectSingleNode("configuration/connectionStrings/add[@name = 'mysql']") if ($node) { - $node.Attributes["connectionString"].InnerText = $mysqlConnectionString + $node.Attributes['connectionString'].InnerText = $mysqlConnectionString $config.Save($configFile) } } diff --git a/Build/tasks/create-images-tasks.ps1 b/Build/tasks/create-images-tasks.ps1 index bc718538..eb9a2f54 100644 --- a/Build/tasks/create-images-tasks.ps1 +++ b/Build/tasks/create-images-tasks.ps1 @@ -10,13 +10,14 @@ task Default ` , BuildMySqlDatabase Enter-Build { - $context = Join-Path $PSScriptRoot "..\..\Sources\Docker" + $context = Join-Path $PSScriptRoot '..\..\Sources\Docker' } task BuildMsSqlDatabase { - $dockerfile = Join-Path $context "image-mssql-2017.dockerfile" + $dockerfile = Join-Path $context 'image-mssql-2017.dockerfile' exec { docker build ` + --pull ` -f $dockerfile ` -t sqldatabase/mssql:2017 ` $context @@ -24,9 +25,10 @@ task BuildMsSqlDatabase { } task BuildPgSqlDatabase { - $dockerfile = Join-Path $context "image-postgres-133.dockerfile" + $dockerfile = Join-Path $context 'image-postgres-133.dockerfile' exec { docker build ` + --pull ` -f $dockerfile ` -t sqldatabase/postgres:13.3 ` $context @@ -34,9 +36,10 @@ task BuildPgSqlDatabase { } task BuildMySqlDatabase { - $dockerfile = Join-Path $context "image-mysql-8025.dockerfile" + $dockerfile = Join-Path $context 'image-mysql-8025.dockerfile' exec { docker build ` + --pull ` -f $dockerfile ` -t sqldatabase/mysql:8.0.25 ` $context @@ -44,9 +47,10 @@ task BuildMySqlDatabase { } task BuildDotnetSdk60 { - $dockerfile = Join-Path $context "image-dotnet-sdk-6.0.dockerfile" + $dockerfile = Join-Path $context 'image-dotnet-sdk-6.0.dockerfile' exec { docker build ` + --pull ` -f $dockerfile ` -t sqldatabase/dotnet_pwsh:6.0-sdk ` . @@ -54,9 +58,10 @@ task BuildDotnetSdk60 { } task BuildDotnetRuntime60 { - $dockerfile = Join-Path $context "image-dotnet-runtime-6.0.dockerfile" + $dockerfile = Join-Path $context 'image-dotnet-runtime-6.0.dockerfile' exec { docker build ` + --pull ` -f $dockerfile ` -t sqldatabase/dotnet_pwsh:6.0-runtime ` . @@ -64,9 +69,10 @@ task BuildDotnetRuntime60 { } task BuildDotnetSdk70 { - $dockerfile = Join-Path $context "image-dotnet-sdk-7.0.dockerfile" + $dockerfile = Join-Path $context 'image-dotnet-sdk-7.0.dockerfile' exec { docker build ` + --pull ` -f $dockerfile ` -t sqldatabase/dotnet_pwsh:7.0-sdk ` . @@ -74,9 +80,10 @@ task BuildDotnetSdk70 { } task BuildDotnetRuntime70 { - $dockerfile = Join-Path $context "image-dotnet-runtime-7.0.dockerfile" + $dockerfile = Join-Path $context 'image-dotnet-runtime-7.0.dockerfile' exec { docker build ` + --pull ` -f $dockerfile ` -t sqldatabase/dotnet_pwsh:7.0-runtime ` . @@ -84,9 +91,10 @@ task BuildDotnetRuntime70 { } task BuildDotnetSdk80 { - $dockerfile = Join-Path $context "image-dotnet-sdk-8.0.dockerfile" + $dockerfile = Join-Path $context 'image-dotnet-sdk-8.0.dockerfile' exec { docker build ` + --pull ` -f $dockerfile ` -t sqldatabase/dotnet_pwsh:8.0-sdk ` . @@ -94,9 +102,10 @@ task BuildDotnetSdk80 { } task BuildDotnetRuntime80 { - $dockerfile = Join-Path $context "image-dotnet-runtime-8.0.dockerfile" + $dockerfile = Join-Path $context 'image-dotnet-runtime-8.0.dockerfile' exec { docker build ` + --pull ` -f $dockerfile ` -t sqldatabase/dotnet_pwsh:8.0-runtime ` .