Skip to content

Commit

Permalink
Chore: Make it still build on .net6.0 and 7.0
Browse files Browse the repository at this point in the history
* Made dotnet pack to work
* Removed <TargetFramework> altogether - only use <TargetFrameworks>
* Install more .net versions in build pipelines, to be able to run all tests on all frameworks
* Fixed .NET 6 test errors (used some Polyfills)
  • Loading branch information
erikbra committed Jan 19, 2025
1 parent 9549a12 commit 5e7e345
Show file tree
Hide file tree
Showing 44 changed files with 208 additions and 60 deletions.
22 changes: 16 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,14 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup .NET 9
- name: Setup .NET 9 and earlier
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
dotnet-version: |
6.0.x
7.0.x
8.0.x
9.0.x
- name: Restore dependencies
run: dotnet restore
Expand Down Expand Up @@ -121,9 +125,10 @@ jobs:
dotnet-version: 9.0.x

- name: Publish self-contained ${{ matrix.arch }}
run: dotnet publish ./src/grate/grate.csproj -f net9.0 -r ${{ matrix.arch }} -c release --self-contained -p:SelfContained=true -o ./publish/${{ matrix.arch }}/self-contained
run: dotnet publish ./src/grate/grate.csproj -r ${{ matrix.arch }} -c release --self-contained -p:SelfContained=true -o ./publish/${{ matrix.arch }}/self-contained
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
TargetFramework: net9.0


- name: Upload self-contained ${{ matrix.arch }}
Expand Down Expand Up @@ -157,9 +162,10 @@ jobs:
dotnet-version: 9.0.x

- name: Publish self-contained ${{ matrix.arch }}
run: dotnet publish ./src/grate/grate.csproj -f net9.0 -r ${{ matrix.arch }} -c release --self-contained -p:SelfContained=true -o ./publish/${{ matrix.arch }}/self-contained
run: dotnet publish ./src/grate/grate.csproj -r ${{ matrix.arch }} -c release --self-contained -p:SelfContained=true -o ./publish/${{ matrix.arch }}/self-contained
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
TargetFramework: net9.0

- name: Upload self-contained ${{ matrix.arch }}
#if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
Expand Down Expand Up @@ -294,10 +300,14 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Setup .NET 9
- name: Setup .NET 9 and earlier
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
dotnet-version: |
6.0.x
7.0.x
8.0.x
9.0.x
- name: Test
run: >
dotnet test
Expand Down
18 changes: 13 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET 9
- name: Setup .NET 9 and earlier
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
dotnet-version: |
6.0.x
7.0.x
8.0.x
9.0.x
- name: Restore dependencies
run: |
dotnet restore -r linux-x64 grate.sln
- name: Build
run: dotnet build -f net9.0 --no-restore --no-self-contained -r linux-x64 src/grate/grate.csproj -c release
run: dotnet build --no-restore --no-self-contained -r linux-x64 src/grate/grate.csproj -c release


analyze:
Expand All @@ -44,7 +48,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup .NET 9
- name: Setup .NET 9 and earlier
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
Expand Down Expand Up @@ -79,7 +83,11 @@ jobs:
- name: Setup .NET 9
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
dotnet-version: |
6.0.x
7.0.x
8.0.x
9.0.x
- name: Test
run: |
dotnet test \
Expand Down
22 changes: 15 additions & 7 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ jobs:
dotnet-version: 9.0.x

- name: Publish self-contained ${{ matrix.arch }}
run: dotnet publish ./src/grate/grate.csproj -f net9.0 -r ${{ matrix.arch }} -c release --self-contained -p:SelfContained=true -o ./publish/${{ matrix.arch }}/self-contained
run: dotnet publish ./src/grate/grate.csproj -r ${{ matrix.arch }} -c release --self-contained -p:SelfContained=true -o ./publish/${{ matrix.arch }}/self-contained
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
TargetFramework: net9.0

- name: Upload self-contained ${{ matrix.arch }}
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -104,9 +105,10 @@ jobs:
dotnet-version: 9.0.x

- name: Publish self-contained ${{ matrix.arch }}
run: dotnet publish ./src/grate/grate.csproj -f net9.0 -r ${{ matrix.arch }} -c release --self-contained -p:SelfContained=true -o ./publish/${{ matrix.arch }}/self-contained
run: dotnet publish ./src/grate/grate.csproj -r ${{ matrix.arch }} -c release --self-contained -p:SelfContained=true -o ./publish/${{ matrix.arch }}/self-contained
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
TargetFramework: net9.0

- name: Upload self-contained ${{ matrix.arch }}
uses: actions/upload-artifact@v4
Expand All @@ -130,12 +132,16 @@ jobs:
- name: Setup .NET 9
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
dotnet-version: |
6.0.x
7.0.x
8.0.x
9.0.x
- name: Build Test DLLs ${{ matrix.arch }}
run: |
dotnet restore -r ${{ matrix.arch }} unittests/UnitTests.slnf
dotnet publish -f net9.0 -r ${{ matrix.arch }} -c release --no-restore ./unittests/UnitTests.slnf -o ./integration-tests/${{ matrix.arch }}
dotnet publish -r ${{ matrix.arch }} -c release --no-restore ./unittests/UnitTests.slnf -o ./integration-tests/${{ matrix.arch }}
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
Expand All @@ -158,15 +164,17 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Setup .NET 9
- name: Setup .NET 8 & 9
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
dotnet-version: |
8.0.x
9.0.x
- name: Build Test DLLs ${{ matrix.arch }}
run: |
dotnet restore -r ${{ matrix.arch }} unittests/UnitTests.slnf
dotnet publish -f net9.0 -r ${{ matrix.arch }} -c release --no-restore ./unittests/UnitTests.slnf -o ./integration-tests/${{ matrix.arch }}
dotnet publish -r ${{ matrix.arch }} -c release --no-restore ./unittests/UnitTests.slnf -o ./integration-tests/${{ matrix.arch }}
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
Expand Down
10 changes: 6 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@


<PropertyGroup>
<TargetFramework Condition=" '$(TargetFramework)' == '' ">net9.0</TargetFramework>
<NetTargetFrameworks Condition=" '$(NetTargetFrameworks)' == '' ">
net6.0;net7.0;net8.0;net9.0
</NetTargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0'">
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<NoWarn>$(NoWarn);NETSDK1138</NoWarn>
</PropertyGroup>

<PropertyGroup>
Expand Down
6 changes: 6 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
</PropertyGroup>

<ItemGroup>
<!--
.net sdk
Expand All @@ -14,6 +19,7 @@
<PackageVersion Include="Dapper" Version="2.1.35" />
<PackageVersion Include="MySqlConnector" Version="2.4.0" />
<PackageVersion Include="Oracle.ManagedDataAccess.Core" Version="3.21.170" />
<PackageVersion Include="System.Private.Uri" Version="4.3.2" />
<!--
Note: the following references are exclusively used in the test projects:
-->
Expand Down
1 change: 0 additions & 1 deletion src/grate.core/grate.core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(NetTargetFrameworks)</TargetFrameworks>
<Nullable>enable</Nullable>
<RootNamespace>grate</RootNamespace>
<SourceRevisionId>build$([System.DateTime]::UtcNow.ToString("O"))</SourceRevisionId>
Expand Down
1 change: 0 additions & 1 deletion src/grate.mariadb/grate.mariadb.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(NetTargetFrameworks)</TargetFrameworks>
<Nullable>enable</Nullable>
<IsPublishable>false</IsPublishable>
</PropertyGroup>
Expand Down
1 change: 0 additions & 1 deletion src/grate.oracle/grate.oracle.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(NetTargetFrameworks)</TargetFrameworks>
<Nullable>enable</Nullable>
<IsPublishable>false</IsPublishable>
</PropertyGroup>
Expand Down
1 change: 0 additions & 1 deletion src/grate.postgresql/grate.postgresql.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(NetTargetFrameworks)</TargetFrameworks>
<Nullable>enable</Nullable>
<IsPublishable>false</IsPublishable>
</PropertyGroup>
Expand Down
1 change: 0 additions & 1 deletion src/grate.sqlite/grate.sqlite.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(NetTargetFrameworks)</TargetFrameworks>
<Nullable>enable</Nullable>
<IsPublishable>false</IsPublishable>
</PropertyGroup>
Expand Down
1 change: 0 additions & 1 deletion src/grate.sqlserver/grate.sqlserver.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(NetTargetFrameworks)</TargetFrameworks>
<Nullable>enable</Nullable>
<IsPublishable>false</IsPublishable>
</PropertyGroup>
Expand Down
1 change: 0 additions & 1 deletion src/grate/grate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>$(TargetFramework)</TargetFramework>
<DebugType>Embedded</DebugType>
<Nullable>enable</Nullable>

Expand Down
1 change: 0 additions & 1 deletion unittests/Basic_tests/Basic_tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(TargetFramework)</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
using grate.Exceptions;
using grate.Infrastructure;

#if NET6_0
using Dir = TestCommon.TestInfrastructure.Net6PolyFills.Directory;
#else
using Dir = System.IO.Directory;
#endif

namespace Basic_tests.CommandLineParsing;

// ReSharper disable once InconsistentNaming
Expand Down Expand Up @@ -71,7 +77,7 @@ public async Task AdminConnectionString(string argName)
[InlineData("--sqlfilesdirectory=")]
public async Task SqlFilesDirectory(string argName)
{
var folder = Directory.CreateTempSubdirectory();
var folder = Dir.CreateTempSubdirectory();
var commandline = argName + folder;
var cfg = await ParseGrateConfiguration(commandline);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
using grate.Migration;
using NSubstitute;

#if NET6_0
using Dir = TestCommon.TestInfrastructure.Net6PolyFills.Directory;
#else
using Dir = System.IO.Directory;
#endif

namespace Basic_tests.GrateMigrator_MigrationStatus;

// ReSharper disable once InconsistentNaming
public class IsUpToDate_: IDisposable
{
private static readonly DirectoryInfo SqlFilesDirectory = Directory.CreateTempSubdirectory();
private static readonly DirectoryInfo SqlFilesDirectory = Dir.CreateTempSubdirectory();

[Theory]
[InlineData(true)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
using grate.Migration;
using NSubstitute;

#if NET6_0
using Dir = TestCommon.TestInfrastructure.Net6PolyFills.Directory;
#else
using Dir = System.IO.Directory;
#endif

namespace Basic_tests.GrateMigrator_MigrationStatus;

// ReSharper disable once InconsistentNaming
public class MigrationStatus_: IDisposable
{
private static readonly DirectoryInfo SqlFilesDirectory = Directory.CreateTempSubdirectory();
private static readonly DirectoryInfo SqlFilesDirectory = Dir.CreateTempSubdirectory();

[Fact]
public async Task Includes_list_of_ScriptsRun()
Expand Down
66 changes: 66 additions & 0 deletions unittests/Basic_tests/Infrastructure/MockDatabase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Data.Common;
using grate.Configuration;
using grate.Migration;
using Microsoft.Extensions.Logging;

namespace Basic_tests.Infrastructure;

public record MockDatabase : IDatabase
{
public ValueTask DisposeAsync() => ValueTask.CompletedTask;

object ICloneable.Clone() => this with { };

public string? ServerName { get; set; }
public string? DatabaseName { get; set; }
public string DatabaseType { get; } = "Mock";
public string MasterDatabaseName { get; } = "Mock";
public bool SupportsDdlTransactions { get; set; }
public bool SplitBatchStatements { get; set; }
public string ScriptsRunTable { get; } = "ScriptsRun";
public string ScriptsRunErrorsTable { get; } = "ScriptsRunErrors";
public string VersionTable { get; } = "Version";
public DbConnection ActiveConnection { get; set; } = null!;
public bool SupportsSchemas { get; set; }
public Task InitializeConnections(GrateConfiguration configuration) => Task.CompletedTask;

public Task OpenConnection() => Task.CompletedTask;
public Task CloseConnection() => Task.CompletedTask;
public Task OpenAdminConnection() => Task.CompletedTask;
public Task CloseAdminConnection() => Task.CompletedTask;
public Task CreateDatabase() => Task.CompletedTask;
public Task RestoreDatabase(string backupPath) => Task.CompletedTask;
public void SetLogger(ILogger logger) { }
public Task DropDatabase() => Task.CompletedTask;
public Task<bool> DatabaseExists() => Task.FromResult(false);
public Task<string> GetCurrentVersion() => Task.FromResult(string.Empty);
public Task<long> VersionTheDatabase(string newVersion) => Task.FromResult(0L);
public void Rollback() { }

public Task RunSql(string sql, ConnectionType connectionType, TransactionHandling transactionHandling) => Task.CompletedTask;
public Task<string?> GetCurrentHash(string scriptName) => Task.FromResult(string.Empty)!;
public Task<bool> HasRun(string scriptName, TransactionHandling transactionHandling) => Task.FromResult(false);
public Task InsertScriptRun(string scriptName, string? sql, string hash, bool runOnce, long versionId,
TransactionHandling transactionHandling) => Task.CompletedTask;

public Task InsertScriptRunError(string scriptName, string? sql, string errorSql, string errorMessage, long versionId) => Task.CompletedTask;

public Task<bool> VersionTableExists() => Task.FromResult(false);

public Task<bool> GrateInternalTablesAreProperlyLogged() => Task.FromResult(false);

public Task ChangeVersionStatus(string status, long versionId) => Task.CompletedTask;

public Task DeleteVersionRecord(long versionId) => Task.CompletedTask;

public void SetDefaultConnectionActive() { }

public Task<IDisposable> OpenNewActiveConnection() => Task.FromResult<IDisposable>(new HttpClient());

public Task OpenActiveConnection() => Task.CompletedTask;
public Task<string?> ExistingTable(string schemaName, string tableName) => Task.FromResult(string.Empty)!;

public IEnumerable<string> GetStatements(string sql) => new List<string>();
public void ThrowScriptFailed(MigrationsFolder folder, string file, string? scriptText, Exception exception) { }

}
Loading

0 comments on commit 5e7e345

Please sign in to comment.