Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support execution tests, new syntax and aoc2023 day4 #3

Merged
merged 9 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
name: pull-request

on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
Expand All @@ -28,8 +32,6 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
Expand All @@ -49,8 +51,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
Expand All @@ -70,8 +70,6 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
Expand Down
13 changes: 7 additions & 6 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"build": {
"type": "object",
"properties": {
"CleanPackagesDirectory": {
"type": "boolean"
},
"Configuration": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -78,17 +81,16 @@
"CheckCsharpier",
"CheckFantomas",
"Compile",
"Format",
"FormatCsharpier",
"FormatFantomas",
"InstallCsharpier",
"InstallFantomas",
"InstallLinters",
"Lint",
"Pack",
"Restore",
"RestoreTools",
"Test",
"ValidateFormat"
"Test"
]
}
},
Expand All @@ -105,17 +107,16 @@
"CheckCsharpier",
"CheckFantomas",
"Compile",
"Format",
"FormatCsharpier",
"FormatFantomas",
"InstallCsharpier",
"InstallFantomas",
"InstallLinters",
"Lint",
"Pack",
"Restore",
"RestoreTools",
"Test",
"ValidateFormat"
"Test"
]
}
},
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

<PropertyGroup>
<UseReproducibleBuild Condition="'$(UseReproducibleBuild)'==''">false</UseReproducibleBuild>
<PackableProjects>Visp.Runtime.Library</PackableProjects>
<PackableProjects>Visp.Runtime.Library;Visp.Common</PackableProjects>
</PropertyGroup>

<Choose>
Expand Down
4 changes: 4 additions & 0 deletions aoc2023.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

[CmdletBinding()]
param (
[switch] $Release,
[switch] $Full,
[switch] $NoBuild,
[ValidateSet("day1", "day2", "day3", "day4", "day5", "day6", "day7", "day8", "day9")]
Expand All @@ -20,6 +21,9 @@ $cliArgs = @(
if ($Full) {
$cliArgs += "full"
}
if ($Release) {
$cliArgs += "--release"
}

ExecSafe {
& $cliScript -NoBuild:$NoBuild @cliArgs
Expand Down
171 changes: 157 additions & 14 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
// https://github.com/vipentti/visp-fs/blob/main/LICENSE.md

using System.Collections.Generic;
using System.Linq;
using Nuke.Common;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.Execution;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Utilities.Collections;
using Nuke.Components;
Expand All @@ -20,21 +22,26 @@
GitHubActionsImage.WindowsLatest,
GitHubActionsImage.UbuntuLatest,
GitHubActionsImage.MacOsLatest,
OnPullRequestBranches = new[] { MainBranch, DevelopBranch },
PublishArtifacts = false,
FetchDepth = 0 // fetch full history
, SetupDotnetVersions = new[]
{
"8.x",
}
, InvokedTargets = new[]
{
OnPullRequestBranches = [ MainBranch, DevelopBranch ],
OnPushBranches = [ MainBranch, DevelopBranch ],
PublishArtifacts = false
// FetchDepth = 0 // fetch full history
, SetupDotnetVersions = [ "8.x", ]
, InvokedTargets = [
nameof(ITest.Test),
nameof(IUseLinters.InstallLinters),
nameof(IUseLinters.Lint),
})]
])]
[DisableDefaultOutputForHost<Terminal>(DefaultOutput.Logo)]
class Build : NukeBuild, IUseDotNetFormat, IUseCsharpier, IUseFantomas, IUseLinters, IHazSolution, ITest, ICompile
class Build :
NukeBuild,
IUseCsharpier,
IUseFantomas,
IUseCustomLinters,
IHazSolution,
ITest,
ICompile,
IPackSpecificPackagesWithoutTesting
{
public T From<T>()
where T : INukeBuild => (T)(object)this;
Expand All @@ -54,19 +61,155 @@ public T From<T>()
RootDirectory / "tests",
};

IEnumerable<IProvideLinter> IUseLinters.Linters => new IProvideLinter[]
IEnumerable<IProvideLinter> IUseCustomLinters.Linters => new IProvideLinter[]
{
// From<IUseDotNetFormat>().Linter,
From<IUseCsharpier>().Linter,
From<IUseFantomas>().Linter,
};

// csharpier-ignore
public Target RestoreTools => _ => _
.Before<IRestore>(it => it.Restore)
.DependentFor<IUseLinters>(it => it.InstallLinters)
.DependentFor<IUseCustomLinters>(it => it.InstallLinters)
.Executes(() => DotNetToolRestore())
;

public SolutionFolder SrcFolder => CurrentSolution.GetSolutionFolder("src");

IEnumerable<Project> ProjectsToPack => [
SrcFolder.GetProject("Visp.Common"),
SrcFolder.GetProject("Visp.Runtime.Library"),
];

IEnumerable<string> TargetFrameworks => ["net8.0"];

IEnumerable<(Project Project, string Framework)> ICompile.PublishConfigurations =>
from project in ProjectsToPack
from framework in TargetFrameworks
select (project, framework);

IEnumerable<Project> IPackSpecificPackagesWithoutTesting.ProjectsToPack => ProjectsToPack;

public AbsolutePath PackagePath => From<IPack>().PackagesDirectory;

Configure<DotNetTestSettings> ITest.TestSettings => _ => _
.SetProcessEnvironmentVariable("VISP_FS_RUNTIME_PACKAGE_PATH", PackagePath)
.SetProcessEnvironmentVariable("VISP_FS_COMMON_PACKAGE_PATH", PackagePath)
.SetProcessEnvironmentVariable("VISP_FS_PACKAGE_PATH", PackagePath)
.SetProcessEnvironmentVariable("VISP_FS_PACKAGE_FEED_PATH", PackagePath / "feed")
.SetProcessEnvironmentVariable("VISP_FS_LIB_PATH", RootDirectory / "visp" / "lib")
;

Target ITest.Test => _ => _
.DependsOn<IPackSpecificPackagesWithoutTesting>(x => x.Pack)
.Executes(() => From<ITest>().TestResultDirectory.CreateOrCleanDirectory())
.Inherit<ITest>()
;

Configure<DotNetTestSettings, Project> ITest.TestProjectSettings =>
(_, v) =>
_.RemoveLoggers($"trx;LogFileName={v.Name}.trx")
.AddLoggers($"trx;LogFilePrefix={v.Name}");

// specifying TargetsForTfmSpecificContentInPackage because of
// https://github.com/dotnet/fsharp/issues/12320#issuecomment-1059791494

// csharpier-ignore
Configure<DotNetPublishSettings> ICompile.PublishSettings => _ => _
.AddProperty("TargetsForTfmSpecificContentInPackage", "");

// csharpier-ignore
Configure<DotNetPackSettings> IPack.PackSettings => _ => _
.AddProperty("TargetsForTfmSpecificContentInPackage", "");
}

public interface IUseCustomLinters : INukeBuild
{
IEnumerable<IProvideLinter> Linters { get; }

// csharpier-ignore
Target InstallLinters => _ => _
.Before(Lint)
.Executes(() =>
{
var lintSuccess = true;
foreach (var item in Linters)
{
try
{
item.InstallLinter();
}
catch
{
lintSuccess = false;
}
}

Assert.True(lintSuccess);
});

// csharpier-ignore
Target Lint => _ => _
.AssuredAfterFailure()
.TryAfter<ICompile>(x => x.Compile)
.Executes(() =>
{
var lintSuccess = true;
foreach (var item in Linters)
{
try
{
item.ExecuteLinter();
}
catch
{
lintSuccess = false;
}
}

Assert.True(lintSuccess);
});
}

public interface IPackSpecificPackagesWithoutTesting : IPack
{
IEnumerable<Project> ProjectsToPack { get; }

[Parameter]
bool CleanPackagesDirectory => true;

IEnumerable<string> TargetFrameworks => ["net8.0"];

IEnumerable<(Project Project, string Framework)> ICompile.PublishConfigurations =>
from project in ProjectsToPack
from framework in TargetFrameworks
select (project, framework);

// csharpier-ignore
Target IPack.Pack => _ => _
.DependsOn<ICompile>(x => x.Compile)
.Produces(PackagesDirectory / "*.nupkg")
.Executes(() =>
{
if (CleanPackagesDirectory)
{
PackagesDirectory.CreateOrCleanDirectory();
}

DotNetPack(
_ =>
_.Apply(PackSettingsBase)
.Apply(PackSettings)
.CombineWith(ProjectsToPack, (_, v) => _.SetProject(v))
);

ReportSummary(_ => _.AddPair("Packages", PackagesDirectory.GlobFiles("*.nupkg").Count.ToString()));

Nuke.Common.Tools.NuGet.NuGetTasks.NuGet(
$"init {PackagesDirectory} {PackagesDirectory / "feed"} -Expand"
, logInvocation: true
);
});
}

public interface IUseFantomas : INukeBuild
Expand Down
6 changes: 5 additions & 1 deletion build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace></RootNamespace>
<LangVersion>11.0</LangVersion>
<LangVersion>12.0</LangVersion>
<NoWarn>CS0649;CS0169;CA1050;CA1822;CA2211;IDE1006</NoWarn>
<NukeRootDirectory>..</NukeRootDirectory>
<NukeScriptDirectory>..</NukeScriptDirectory>
Expand All @@ -18,4 +18,8 @@
<PackageReference Include="Vipentti.Nuke.Components" Version="0.4.0" />
</ItemGroup>

<ItemGroup>
<PackageDownload Include="NuGet.CommandLine" Version="[6.8.0]" />
</ItemGroup>

</Project>
24 changes: 21 additions & 3 deletions src/Visp.Cli/CliMain.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,36 @@ let main args =

let mutable files = [ VispFile.Main filePath ]

if not (Array.exists (fun it -> it = "--no-lib") args) then
let knownArguments = [ "--no-lib"; "--release"; "--package" ] |> Set.ofList

if not (Array.contains "--no-lib" args) then
files <- VispFile.CoreLib "core.visp" :: files

let release =
if Array.contains "--release" args then
[| "--configuration"; "Release" |]
else
[||]

let pkg =
if Array.contains "--package" args then
RuntimeLibraryReference.Package
else
RuntimeLibraryReference.Project

let cmdArguments =
args[1..] |> Array.filter (fun it -> not (Set.contains it knownArguments))

let generator = new FsharpGenerator(fs, projectPath)

generator.WriteVispFiles files
generator.WriteVispFiles pkg files None

let dotnet =
Cli
.Wrap("dotnet")
.WithArguments(
Array.concat [| [| "run"; "--project"; projectPath; "--" |]; args[1..] |]
Array.concat
[| [| "run"; "--project"; projectPath |]; release; [| "--" |]; cmdArguments |]
)
.WithWorkingDirectory(cwd)
.WithStandardOutputPipe(PipeTarget.ToDelegate(fun x -> printfn "%s" x))
Expand Down
2 changes: 2 additions & 0 deletions src/Visp.Common/Visp.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
<IsPublishable>true</IsPublishable>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading