Unverified Commit 663588f9 authored by Nick Craver's avatar Nick Craver Committed by GitHub

AppVeyor: Build tweaks & misc fixes (#1450)

Simplifying and improve build speed.

- Decreases builds from 8-13 minutes down to ~2 minutes (while running more tests)
- Moves to SQL Server 2019 on AppVeyor
- Moves the 2 longest running tests with params to `[FactLongRunning]`
- Bumps tests up to `netcoreapp3.1`
- Also fixes .Contrib tests
- Moves to `Build.csproj`
- Simplifies `build.ps1`
- Removed defunct `build.sh`
- Nukes `IsAppveyor` (moves to environmental variable overloads)
- Builds now work in Linux/macOS
parent 5c87dc97
<Project Sdk="Microsoft.Build.Traversal/2.0.24">
<ItemGroup>
<ProjectReference Include="*\*.csproj" />
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -7,7 +7,7 @@
using System.Threading;
using System.Threading.Tasks;
using Dapper.ProviderTools.Internal;
#nullable enable
namespace Dapper.ProviderTools
{
/// <summary>
......
......@@ -8,7 +8,6 @@
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<Nullable>enable</Nullable>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
......
......@@ -3,7 +3,7 @@
using System.Data.Common;
using System.Linq.Expressions;
using System.Reflection;
#nullable enable
namespace Dapper.ProviderTools
{
/// <summary>
......
......@@ -3,7 +3,7 @@
using System.Data.Common;
using System.Linq.Expressions;
using System.Reflection;
#nullable enable
namespace Dapper.ProviderTools
{
/// <summary>
......
......@@ -3,11 +3,11 @@
<AssemblyName>Dapper.Tests.Contrib</AssemblyName>
<Description>Dapper Contrib Test Suite</Description>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TargetFrameworks>netcoreapp2.1;net462</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net462</TargetFrameworks>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Dapper.Tests\Helpers\XunitSkippable.cs;..\Dapper\TypeExtensions.cs" />
<Compile Include="..\Dapper.Tests\Helpers\XunitSkippable.cs" Link="Helpers\XunitSkippable.cs" />
<None Remove="Test.DB.sdf" />
</ItemGroup>
<ItemGroup>
......@@ -25,5 +25,4 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<!-- note: define SQLCE if SQL CE is available -->
</Project>
using System;
using Xunit.Sdk;
namespace Dapper.Tests
{
/// <summary>
/// <para>Override for <see cref="Xunit.FactAttribute"/> that truncates our DisplayName down.</para>
/// <para>
/// Attribute that is applied to a method to indicate that it is a fact that should
/// be run by the test runner. It can also be extended to support a customized definition
/// of a test method.
/// </para>
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
[XunitTestCaseDiscoverer("Dapper.Tests.FactDiscoverer", "Dapper.Tests.Contrib")]
public class FactAttribute : Xunit.FactAttribute
{
}
/// <summary>
/// <para>Override for <see cref="Xunit.TheoryAttribute"/> that truncates our DisplayName down.</para>
/// <para>
/// Marks a test method as being a data theory. Data theories are tests which are
/// fed various bits of data from a data source, mapping to parameters on the test
/// method. If the data source contains multiple rows, then the test method is executed
/// multiple times (once with each data row). Data is provided by attributes which
/// derive from Xunit.Sdk.DataAttribute (notably, Xunit.InlineDataAttribute and Xunit.MemberDataAttribute).
/// </para>
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
[XunitTestCaseDiscoverer("Dapper.Tests.TheoryDiscoverer", "Dapper.Tests.Contrib")]
public class TheoryAttribute : Xunit.TheoryAttribute { }
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class FactLongRunningAttribute : FactAttribute
{
public FactLongRunningAttribute()
{
#if !LONG_RUNNING
Skip = "Long running";
#endif
}
public string Url { get; private set; }
}
}
......@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Transactions;
using Dapper.Contrib.Extensions;
using Xunit;
......@@ -104,10 +103,11 @@ public class GenericType<T>
public abstract partial class TestSuite
{
protected static readonly bool IsAppVeyor = Environment.GetEnvironmentVariable("Appveyor")?.ToUpperInvariant() == "TRUE";
public abstract IDbConnection GetConnection();
protected static string GetConnectionString(string name, string defaultConnectionString) =>
Environment.GetEnvironmentVariable(name) ?? defaultConnectionString;
private IDbConnection GetOpenConnection()
{
var connection = GetConnection();
......
......@@ -23,9 +23,8 @@ public class SqlServerTestSuite : TestSuite
{
private const string DbName = "tempdb";
public static string ConnectionString =>
IsAppVeyor
? @"Server=(local)\SQL2016;Database=tempdb;User ID=sa;Password=Password12!"
: $"Data Source=.;Initial Catalog={DbName};Integrated Security=True";
GetConnectionString("SqlServerConnectionString", $"Data Source=.;Initial Catalog={DbName};Integrated Security=True");
public override IDbConnection GetConnection() => new SqlConnection(ConnectionString);
static SqlServerTestSuite()
......@@ -62,9 +61,7 @@ static SqlServerTestSuite()
public class MySqlServerTestSuite : TestSuite
{
public static string ConnectionString { get; } =
IsAppVeyor
? "Server=localhost;Database=test;Uid=root;Pwd=Password12!;UseAffectedRows=false;"
: "Server=localhost;Database=tests;Uid=test;Pwd=pass;UseAffectedRows=false;";
GetConnectionString("MySqlConnectionString", "Server=localhost;Database=tests;Uid=test;Pwd=pass;UseAffectedRows=false;");
public override IDbConnection GetConnection()
{
......
......@@ -5,7 +5,8 @@
<Description>Dapper Core Performance Suite</Description>
<OutputType>Exe</OutputType>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TargetFrameworks>net462;netcoreapp3.0</TargetFrameworks>
<TargetFrameworks>net462;netcoreapp3.1</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
......
......@@ -3,7 +3,7 @@
<AssemblyName>Dapper.Tests</AssemblyName>
<Description>Dapper Core Test Suite</Description>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TargetFrameworks>netcoreapp2.1;net462;net472</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net462;net472</TargetFrameworks>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<DefineConstants>$(DefineConstants);MSSQLCLIENT</DefineConstants>
</PropertyGroup>
......@@ -13,10 +13,10 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Dapper.SqlBuilder\Dapper.SqlBuilder.csproj" />
<ProjectReference Include="..\Dapper\Dapper.csproj" />
<ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" />
<ProjectReference Include="..\Dapper.ProviderTools\Dapper.ProviderTools.csproj" />
<ProjectReference Include="..\Dapper.SqlBuilder\Dapper.SqlBuilder.csproj" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="7.0.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="1.1.1" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.6" />
......
......@@ -1442,10 +1442,10 @@ public void Issue601_InternationalParameterNamesWork()
Assert.Equal(42, result);
}
[Fact]
[FactLongRunning]
public void TestListExpansionPadding_Enabled() => TestListExpansionPadding(true);
[Fact]
[FactLongRunning]
public void TestListExpansionPadding_Disabled() => TestListExpansionPadding(false);
private void TestListExpansionPadding(bool enabled)
......
......@@ -10,9 +10,8 @@ namespace Dapper.Tests
public sealed class MySqlProvider : DatabaseProvider
{
public override DbProviderFactory Factory => MySql.Data.MySqlClient.MySqlClientFactory.Instance;
public override string GetConnectionString() => IsAppVeyor
? "Server=localhost;Database=test;Uid=root;Pwd=Password12!;"
: "Server=localhost;Database=tests;Uid=test;Pwd=pass;";
public override string GetConnectionString() =>
GetConnectionString("MySqlConnectionString", "Server=localhost;Database=tests;Uid=test;Pwd=pass;");
public DbConnection GetMySqlConnection(bool open = true,
bool convertZeroDatetime = false, bool allowZeroDatetime = false)
......
......@@ -11,9 +11,7 @@ public class OLEDBProvider : DatabaseProvider
{
public override DbProviderFactory Factory => OleDbFactory.Instance;
public override string GetConnectionString() =>
IsAppVeyor
? @"Provider=SQLOLEDB;Data Source=(local)\SQL2016;Initial Catalog=tempdb;User Id=sa;Password=Password12!"
: "Provider=SQLOLEDB;Data Source=.;Initial Catalog=tempdb;Integrated Security=SSPI";
GetConnectionString("OLEDBConnectionString", "Provider=SQLOLEDB;Data Source=.;Initial Catalog=tempdb;Integrated Security=SSPI");
}
public class OLDEBTests : TestBase<OLEDBProvider>
......
......@@ -9,9 +9,8 @@ namespace Dapper.Tests
public class PostgresProvider : DatabaseProvider
{
public override DbProviderFactory Factory => Npgsql.NpgsqlFactory.Instance;
public override string GetConnectionString() => IsAppVeyor
? "Server=localhost;Port=5432;User Id=postgres;Password=Password12!;Database=test"
: "Server=localhost;Port=5432;User Id=dappertest;Password=dapperpass;Database=dappertest"; // ;Encoding = UNICODE
public override string GetConnectionString() =>
GetConnectionString("PostgesConnectionString", "Server=localhost;Port=5432;User Id=dappertest;Password=dapperpass;Database=dappertest");
}
public class PostgresqlTests : TestBase<PostgresProvider>
{
......
......@@ -15,10 +15,12 @@ public abstract class DatabaseProvider
{
public abstract DbProviderFactory Factory { get; }
public static bool IsAppVeyor { get; } = Environment.GetEnvironmentVariable("Appveyor")?.ToUpperInvariant() == "TRUE";
public virtual void Dispose() { }
public abstract string GetConnectionString();
protected string GetConnectionString(string name, string defaultConnectionString) =>
Environment.GetEnvironmentVariable(name) ?? defaultConnectionString;
public DbConnection GetOpenConnection()
{
var conn = Factory.CreateConnection();
......@@ -47,10 +49,8 @@ public DbParameter CreateRawParameter(string name, object value)
public abstract class SqlServerDatabaseProvider : DatabaseProvider
{
public override string GetConnectionString() =>
IsAppVeyor
? @"Server=(local)\SQL2016;Database=tempdb;User ID=sa;Password=Password12!"
: "Data Source=.;Initial Catalog=tempdb;Integrated Security=True";
public override string GetConnectionString() =>
GetConnectionString("SqlServerConnectionString", "Data Source=.;Initial Catalog=tempdb;Integrated Security=True");
public DbConnection GetOpenConnection(bool mars)
{
......
......@@ -20,6 +20,8 @@
<IncludeSymbols>false</IncludeSymbols>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
......@@ -32,7 +34,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.1.74" PrivateAssets="all" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" IncludeAssets="runtime; build; native; contentfiles; analyzers" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.1.74" PrivateAssets="all" />
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -114,9 +114,9 @@ Performance
A key feature of Dapper is performance. The following metrics show how long it takes to execute a `SELECT` statement against a DB (in various config, each labeled) and map the data returned to objects.
The benchmarks can be found in [Dapper.Tests.Performance](https://github.com/StackExchange/Dapper/tree/master/Dapper.Tests.Performance) (contributions welcome!) and can be run once compiled via:
```
Dapper.Tests.Performance.exe -f * --join
The benchmarks can be found in [Dapper.Tests.Performance](https://github.com/StackExchange/Dapper/tree/master/Dapper.Tests.Performance) (contributions welcome!) and can be run via:
```bash
dotnet run -p .\Dapper.Tests.Performance\ -c Release -f netcoreapp3.1 -- -f * --join
```
Output from the latest run is:
``` ini
......
image: Visual Studio 2017
image: Visual Studio 2019
skip_branch_with_pr: true
skip_tags: true
......@@ -6,9 +6,6 @@ skip_commits:
files:
- '**/*.md'
install:
- choco install dotnetcore-sdk --version 3.0.100
environment:
Appveyor: true
# Postgres
......@@ -24,14 +21,20 @@ environment:
MYSQL_ENV_MYSQL_USER: root
MYSQL_ENV_MYSQL_PASSWORD: Password12!
MYSQL_ENV_MYSQL_DATABASE: test
# Connection strings for tests:
MySqlConnectionString: Server=localhost;Database=test;Uid=root;Pwd=Password12!
OLEDBConnectionString: Provider=SQLOLEDB;Data Source=(local)\SQL2019;Initial Catalog=tempdb;User Id=sa;Password=Password12!
PostgesConnectionString: Server=localhost;Port=5432;User Id=postgres;Password=Password12!;Database=test
SqlServerConnectionString: Server=(local)\SQL2019;Database=tempdb;User ID=sa;Password=Password12!
services:
- mssql2016
- mysql
- postgresql
init:
- git config --global core.autocrlf input
- SET PATH=%POSTGRES_PATH%\bin;%MYSQL_PATH%\bin;%PATH%
- net start MSSQL$SQL2019
nuget:
disable_publish_on_pr: true
......
......@@ -11,61 +11,33 @@ Write-Host " RunTests: $RunTests"
Write-Host " dotnet --version:" (dotnet --version)
$packageOutputFolder = "$PSScriptRoot\.nupkgs"
$projectsToBuild =
'Dapper',
'Dapper.StrongName',
'Dapper.Contrib',
'Dapper.EntityFramework',
'Dapper.EntityFramework.StrongName',
'Dapper.Rainbow',
'Dapper.SqlBuilder'
$testsToRun =
'Dapper.Tests',
'Dapper.Tests.Contrib'
if ($PullRequestNumber) {
Write-Host "Building for a pull request (#$PullRequestNumber), skipping packaging." -ForegroundColor Yellow
$CreatePackages = $false
}
Write-Host "Restoring all projects..." -ForegroundColor "Magenta"
dotnet restore
Write-Host "Done restoring." -ForegroundColor "Green"
Write-Host "Building all projects..." -ForegroundColor "Magenta"
dotnet build -c Release --no-restore /p:CI=true
Write-Host "Building all projects (Build.csproj traversal)..." -ForegroundColor "Magenta"
dotnet build ".\Build.csproj" -c Release /p:CI=true
Write-Host "Done building." -ForegroundColor "Green"
if ($RunTests) {
foreach ($project in $testsToRun) {
Write-Host "Running tests: $project (all frameworks)" -ForegroundColor "Magenta"
Push-Location ".\$project"
dotnet test -c Release
if ($LastExitCode -ne 0) {
Write-Host "Error with tests, aborting build." -Foreground "Red"
Pop-Location
Exit 1
}
Write-Host "Tests passed!" -ForegroundColor "Green"
Pop-Location
Write-Host "Running tests: Build.csproj traversal (all frameworks)" -ForegroundColor "Magenta"
dotnet test ".\Build.csproj" -c Release --no-build
if ($LastExitCode -ne 0) {
Write-Host "Error with tests, aborting build." -Foreground "Red"
Exit 1
}
Write-Host "Tests passed!" -ForegroundColor "Green"
}
if ($CreatePackages) {
mkdir -Force $packageOutputFolder | Out-Null
New-Item -ItemType Directory -Path $packageOutputFolder -Force | Out-Null
Write-Host "Clearing existing $packageOutputFolder..." -NoNewline
Get-ChildItem $packageOutputFolder | Remove-Item
Write-Host "done." -ForegroundColor "Green"
Write-Host "Building all packages" -ForegroundColor "Green"
foreach ($project in $projectsToBuild) {
Write-Host "Packing $project (dotnet pack)..." -ForegroundColor "Magenta"
dotnet pack ".\$project\$project.csproj" --no-build -c Release /p:PackageOutputPath=$packageOutputFolder /p:NoPackageAnalysis=true /p:CI=true
Write-Host ""
}
dotnet pack ".\Build.csproj" --no-build -c Release /p:PackageOutputPath=$packageOutputFolder /p:CI=true
}
Write-Host "Build Complete." -ForegroundColor "Green"
#!/bin/bash
echo ""
echo "Installing dotnet cli..."
echo ""
export DOTNET_INSTALL_DIR="./.dotnet/"
tools/install.sh
origPath=$PATH
export PATH="./dotnet/bin/:$PATH"
if [ $? -ne 0 ]; then
echo >&2 ".NET Execution Environment installation has failed."
exit 1
fi
export DOTNET_HOME="$DOTNET_INSTALL_DIR/cli"
export PATH="$DOTNET_HOME/bin:$PATH"
export autoGeneratedVersion=false
# Generate version number if not set
if [[ -z "$BuildSemanticVersion" ]]; then
autoVersion="$((($(date +%s) - 1451606400)/60))-$(date +%S)"
export BuildSemanticVersion="rc2-$autoVersion"
autoGeneratedVersion=true
echo "Set version to $BuildSemanticVersion"
fi
sed -i '' "s/99.99.99-rc2/1.0.0-$BuildSemanticVersion/g" */*/project.json
# Restore packages and build product
dotnet restore -v Minimal # Restore all packages
# Build all
# Note the exclude: https://github.com/dotnet/cli/issues/1342
for d in Dapper*/; do
if [ "$d" != "*.EntityFramework.StrongName" ]; then
echo "Building $d"
pushd "$d"
dotnet build -f netstandard1.3
popd
fi
done
# Run tests
for d in *.Tests*/; do
echo "Testing $d"
pushd "$d"
dotnet test -f netcoreapp1.0
popd
done
sed -i '' "s/1.0.0-$BuildSemanticVersion/99.99.99-rc2/g" */*/project.json
if [ $autoGeneratedVersion ]; then
unset BuildSemanticVersion
fi
export PATH=$origPath
\ No newline at end of file
It's <insert new hire>'s fault!
\ No newline at end of file
{
"sdk": {
"version": "3.0.100",
"version": "3.1.100",
"rollForward": "latestMajor",
"allowPrerelease": false
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment