Skip to content

Commit

Permalink
Merge pull request #666 from SteveDunn/enable-nullable-if-required
Browse files Browse the repository at this point in the history
Generate nullability attributes if nullability is enabled
  • Loading branch information
SteveDunn authored Sep 9, 2024
2 parents 2d58ab2 + ded2dba commit 280d936
Show file tree
Hide file tree
Showing 30,623 changed files with 1,152,453 additions and 223,206 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
48 changes: 33 additions & 15 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
param($verbosity = "minimal") #quite|q, minimal|m, normal|n, detailed|d
param($verbosity = "minimal", [switch] $quick = $false) #quite|q, minimal|m, normal|n, detailed|d

$artifacts = ".\artifacts"
$localPackages = ".\local-global-packages"
Expand Down Expand Up @@ -34,7 +34,7 @@ function Exec
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
[Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd)
[Parameter(Position=1,Mandatory=0)][string]$errorMessage = "Error executing command $cmd"
)
& $cmd
if ($lastexitcode -ne 0) {
Expand Down Expand Up @@ -89,7 +89,7 @@ exec { & dotnet restore Vogen.sln --packages $localPackages --no-cache --verbosi
exec { & dotnet build Vogen.sln -c Debug --no-restore --verbosity $verbosity}
exec { & dotnet pack ./src/Vogen.Pack.csproj -c Debug -o:$localPackages /p:ForceVersion=$version --include-symbols --version-suffix:dev --no-restore --verbosity $verbosity }

WriteStage("Cleaning and building consumers (tests and samples)")
WriteStage("Cleaning and building consumers (tests and samples) - verbosity of $verbosity")

exec { & dotnet restore Consumers.sln --no-cache --verbosity $verbosity }
exec { & dotnet clean Consumers.sln -c Release --verbosity $verbosity}
Expand All @@ -98,28 +98,46 @@ exec { & dotnet clean Consumers.sln -c Release --verbosity $verbosity}
# Restore the project using the custom config file, restoring packages to a local folder
exec { & dotnet restore Consumers.sln -p UseLocallyBuiltPackage=true --force --no-cache --packages $localPackages --configfile ./nuget.private.config --verbosity $verbosity }

exec { & dotnet build Consumers.sln -c Debug --no-restore --verbosity $verbosity }
exec { & dotnet build Consumers.sln -c Release --no-restore --verbosity $verbosity }
# Run both build tasks asynchronously

WriteStage("Running consumer tests in debug with the local version of the NuGet package:" +$version)
exec { & dotnet test ./tests/ConsumerTests -c Debug --no-build --no-restore --verbosity $verbosity }
$debugTask = Start-Process "dotnet" "build Consumers.sln --configuration Debug --no-restore --verbosity $verbosity" -NoNewWindow -PassThru
$releaseTask = Start-Process "dotnet" "build Consumers.sln --configuration Release --no-restore --verbosity $verbosity" -NoNewWindow -PassThru

WriteStage("Re-running tests in release with the local version of the NuGet package:" +$version)
exec { & dotnet test ./tests/ConsumerTests -c Release --no-build --no-restore --verbosity $verbosity }
# Wait for both tasks to complete
$debugTask.WaitForExit()
$releaseTask.WaitForExit()

WriteStage("Re-running tests in release with no validation with the local version of the NuGet package:" +$version)
exec { & dotnet build Consumers.sln -c Release -p:DefineConstants="VOGEN_NO_VALIDATION" --no-restore --verbosity $verbosity }
exec { & dotnet test ./tests/ConsumerTests -c Release --no-build --no-restore --verbosity $verbosity }
if ($debugTask.ExitCode -ne $null -and $debugTask.ExitCode -ne 0) {
Write-Host "debug build returned " + $debugTask.ExitCode
exit -1
}
if ($releaseTask.ExitCode -ne $null -and $releaseTask.ExitCode -ne 0) {
Write-Host "release build returned " + $releaseTask.ExitCode
exit -1
}

WriteStage("Building samples using the local version of the NuGet package...")

#exec { & dotnet build Consumers.sln -c Debug --no-restore --verbosity $verbosity }
#exec { & dotnet build Consumers.sln -c Release --no-restore --verbosity $verbosity }

exec { & dotnet run --project samples/Vogen.Examples/Vogen.Examples.csproj -c Debug --no-build --no-restore }
WriteStage("Running consumer tests in debug with the local version of the NuGet package:" +$version)
exec { & dotnet test ./tests/ConsumerTests -c Debug --no-build --no-restore --verbosity $verbosity }

if(-not $quick)
{
WriteStage("Re-running tests in release with the local version of the NuGet package:" + $version)
exec { & dotnet test ./tests/ConsumerTests -c Release --no-build --no-restore --verbosity $verbosity }

WriteStage("Finally, packing the release version into " + $artifacts)
WriteStage("Re-running tests in release with no validation with the local version of the NuGet package:" +$version)
exec { & dotnet build Consumers.sln -c Release -p:DefineConstants="VOGEN_NO_VALIDATION" --no-restore --verbosity $verbosity }
exec { & dotnet test ./tests/ConsumerTests -c Release --no-build --no-restore --verbosity $verbosity }

WriteStage("Building and running samples using the local version of the NuGet package...")
exec { & dotnet run --project samples/Vogen.Examples/Vogen.Examples.csproj -c Debug --no-build --no-restore }
exec { & dotnet run --project samples/Vogen.Examples/Vogen.Examples.csproj -c Release --no-build --no-restore }
}

WriteStage("Finally, packing the release version into " + $artifacts)
exec { & dotnet pack src/Vogen.Pack.csproj -c Release -o $artifacts --no-build --verbosity $verbosity }

WriteStage("Done! Package generated at " + $artifacts)
Expand Down
26 changes: 17 additions & 9 deletions samples/Vogen.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,26 @@ class Program
// ReSharper disable once UnusedParameter.Local
static async Task Main(string[] args)
{
var scenarioTypes = typeof(Program).Assembly.GetTypes()
.Where(t => typeof(IScenario).IsAssignableFrom(t) && t != typeof(IScenario)).ToList();
try
{
var scenarioTypes = typeof(Program).Assembly.GetTypes()
.Where(t => typeof(IScenario).IsAssignableFrom(t) && t != typeof(IScenario)).ToList();

foreach (var eachScenarioType in scenarioTypes)
{
var instance = (IScenario)Activator.CreateInstance(eachScenarioType)!;
WriteBanner(instance);

await instance.Run();
}

foreach (var eachScenarioType in scenarioTypes)
Console.WriteLine("Finished");
}
catch (Exception e)
{
var instance = (IScenario)Activator.CreateInstance(eachScenarioType)!;
WriteBanner(instance);

await instance.Run();
Console.Error.WriteLine(e);
Environment.Exit(-1);
}

Console.WriteLine("Finished");
}

private static void WriteBanner(IScenario scenario)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#if NULLABLE_DISABLED_BUILD
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
#endif

using System;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -36,7 +40,7 @@ public async Task Run()

try
{
string runnerOs = Environment.GetEnvironmentVariable("RUNNER_OS");
string? runnerOs = Environment.GetEnvironmentVariable("RUNNER_OS");

bool isLocalOrLinuxOnGitHub = string.IsNullOrEmpty(runnerOs) || runnerOs == "Linux";

Expand Down
20 changes: 10 additions & 10 deletions samples/Vogen.Examples/Types/DateTimeOffsetVo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@
namespace Vogen.Examples.Types
{
[ValueObject(conversions: Conversions.None, underlyingType: typeof(DateTimeOffset))]
public partial struct DateTimeOffsetVo { }
public partial struct DateTimeOffsetVo;

[ValueObject(conversions: Conversions.None, underlyingType: typeof(DateTimeOffset))]
public partial struct NoConverterDateTimeOffsetVo { }
public partial struct NoConverterDateTimeOffsetVo;

[ValueObject(conversions: Conversions.TypeConverter, underlyingType: typeof(DateTimeOffset))]
public partial struct NoJsonDateTimeOffsetVo { }
public partial struct NoJsonDateTimeOffsetVo;

[ValueObject(conversions: Conversions.NewtonsoftJson, underlyingType: typeof(DateTimeOffset))]
public partial struct NewtonsoftJsonDateTimeOffsetVo { }
public partial struct NewtonsoftJsonDateTimeOffsetVo;

[ValueObject(conversions: Conversions.ServiceStackDotText, underlyingType: typeof(DateTimeOffset))]
public partial struct SsdtDateTimeOffsetVo { }
public partial struct SsdtDateTimeOffsetVo;

[ValueObject(conversions: Conversions.SystemTextJson, underlyingType: typeof(DateTimeOffset))]
public partial struct SystemTextJsonDateTimeOffsetVo { }
public partial struct SystemTextJsonDateTimeOffsetVo;

[ValueObject(conversions: Conversions.NewtonsoftJson | Conversions.SystemTextJson, underlyingType: typeof(DateTimeOffset))]
public partial struct BothJsonDateTimeOffsetVo { }
public partial struct BothJsonDateTimeOffsetVo;

[ValueObject(conversions: Conversions.EfCoreValueConverter, underlyingType: typeof(DateTimeOffset))]
public partial struct EfCoreDateTimeOffsetVo { }
public partial struct EfCoreDateTimeOffsetVo;

[ValueObject(conversions: Conversions.DapperTypeHandler, underlyingType: typeof(DateTimeOffset))]
public partial struct DapperDateTimeOffsetVo { }
public partial struct DapperDateTimeOffsetVo;

[ValueObject(conversions: Conversions.LinqToDbValueConverter, underlyingType: typeof(DateTimeOffset))]
public partial struct LinqToDbDateTimeOffsetVo { }
public partial struct LinqToDbDateTimeOffsetVo;
}
Loading

0 comments on commit 280d936

Please sign in to comment.