diff --git a/build.cake b/build.cake deleted file mode 100644 index e3340d4..0000000 --- a/build.cake +++ /dev/null @@ -1,236 +0,0 @@ -#tool dotnet:?package=GitVersion.Tool&version=6.5.1 -#load "build/records.cake" -#load "build/helpers.cake" - -/***************************** - * Setup - *****************************/ -Setup( - static context => { - var assertedVersions = context.GitVersion(new GitVersionSettings - { - OutputType = GitVersionOutput.Json - }); - - var branchName = assertedVersions.BranchName; - var isMainBranch = StringComparer.OrdinalIgnoreCase.Equals("main", branchName); - - var gh = context.GitHubActions(); - var buildDate = DateTime.UtcNow; - var runNumber = gh.IsRunningOnGitHubActions - ? gh.Environment.Workflow.RunNumber - : 0; - - var suffix = runNumber == 0 - ? $"-{(short)((buildDate - buildDate.Date).TotalSeconds/3)}" - : string.Empty; - - var version = FormattableString - .Invariant($"{buildDate:yyyy.M.d}.{runNumber}{suffix}"); - - context.Information("Building version {0} (Branch: {1}, IsMain: {2})", - version, - branchName, - isMainBranch); - - var artifactsPath = context - .MakeAbsolute(context.Directory("./artifacts")); - - var projectRoot = context - .MakeAbsolute(context.Directory("./src")); - - var projectPath = projectRoot.CombineWithFilePath("Devlead.Testing.MockHttp/Devlead.Testing.MockHttp.csproj"); - - return new BuildData( - version, - isMainBranch, - !context.IsRunningOnWindows(), - context.BuildSystem().IsLocalBuild, - projectRoot, - projectPath, - new DotNetMSBuildSettings() - .SetConfiguration("Release") - .SetVersion(version) - .WithProperty("Copyright", $"Mattias Karlsson © {DateTime.UtcNow.Year}") - .WithProperty("Authors", "devlead") - .WithProperty("Company", "devlead") - .WithProperty("PackageLicenseExpression", "MIT") - .WithProperty("PackageTags", "testing;http") - .WithProperty("PackageDescription", ".NET Library for mocking HTTP client requests") - .WithProperty("RepositoryUrl", "https://github.com/devlead/Devlead.Testing.MockHttp.git") - .WithProperty("ContinuousIntegrationBuild", gh.IsRunningOnGitHubActions ? "true" : "false") - .WithProperty("EmbedUntrackedSources", "true"), - artifactsPath, - artifactsPath.Combine(version) - ); - } -); - -/***************************** - * Tasks - *****************************/ -Task("Clean") - .Does( - static (context, data) => context.CleanDirectories(data.DirectoryPathsToClean) - ) -.Then("Restore") - .Does( - static (context, data) => context.DotNetRestore( - data.ProjectRoot.FullPath, - new DotNetRestoreSettings { - MSBuildSettings = data.MSBuildSettings - } - ) - ) -.Then("DPI") - .Does( - static (context, data) => context.DotNetTool( - "tool", - new DotNetToolSettings { - ArgumentCustomization = args => args - .Append("run") - .Append("dpi") - .Append("nuget") - .Append("--silent") - .AppendSwitchQuoted("--output", "table") - .Append( - ( - !string.IsNullOrWhiteSpace(context.EnvironmentVariable("NuGetReportSettings_SharedKey")) - && - !string.IsNullOrWhiteSpace(context.EnvironmentVariable("NuGetReportSettings_WorkspaceId")) - ) - ? "report" - : "analyze" - ) - .AppendSwitchQuoted("--buildversion", data.Version) - } - ) - ) -.Then("Build") - .Does( - static (context, data) => context.DotNetBuild( - data.ProjectRoot.FullPath, - new DotNetBuildSettings { - NoRestore = true, - MSBuildSettings = data.MSBuildSettings - } - ) - ) -.Then("Test") - .Does( - static (context, data) => context.DotNetTest( - data.ProjectRoot.FullPath, - new DotNetTestSettings { - NoBuild = true, - NoRestore = true, - MSBuildSettings = data.MSBuildSettings - } - ) - ) -.Then("Pack") - .Does( - static (context, data) => context.DotNetPack( - data.ProjectPath.FullPath, - new DotNetPackSettings { - NoBuild = true, - NoRestore = true, - OutputDirectory = data.NuGetOutputPath, - MSBuildSettings = data.MSBuildSettings - } - ) - ) -.Then("Upload-Artifacts") - .WithCriteria(BuildSystem.IsRunningOnGitHubActions, nameof(BuildSystem.IsRunningOnGitHubActions)) - .Does( - static (context, data) => context - .GitHubActions() is var gh && gh != null - ? gh.Commands - .UploadArtifact(data.ArtifactsPath, $"Artifact_{gh.Environment.Runner.ImageOS ?? gh.Environment.Runner.OS}_{context.Environment.Runtime.BuiltFramework.Identifier}_{context.Environment.Runtime.BuiltFramework.Version}") - : throw new Exception("GitHubActions not available") - ) -.Then("Prepare-Integration-Test") - .Does( - static (context, data) => { - context.CopyDirectory(data.ProjectRoot.Combine("Devlead.Testing.MockHttp.Tests"), data.IntegrationTestPath); - context.CopyFile(data.ProjectRoot.CombineWithFilePath("Directory.Packages.props"), data.IntegrationTestPath.CombineWithFilePath("Directory.Packages.props")); - context.CopyFile("nuget.config", data.IntegrationTestPath.CombineWithFilePath("nuget.config")); - context.DotNetAddPackage( - "Devlead.Testing.MockHttp", - new DotNetPackageAddSettings { - EnvironmentVariables = { { "Configuration", "IntegrationTest" } }, - WorkingDirectory = data.IntegrationTestPath, - Version = data.Version, - Source = data.NuGetOutputPath.FullPath - } - ); - } - ) -.Then("Integration-Test") - .Does( - static (context, data) => { - context.DotNetTest( - data.IntegrationTestPath.FullPath, - new DotNetTestSettings { - Configuration = "IntegrationTest" - } - ); - } - ) - .Default() -.Then("Push-GitHub-Packages") - .WithCriteria( (context, data) => data.ShouldPushGitHubPackages()) - .DoesForEach( - static (data, context) - => context.GetFiles(data.NuGetOutputPath.FullPath + "/*.nupkg"), - static (data, item, context) - => context.DotNetNuGetPush( - item.FullPath, - new DotNetNuGetPushSettings - { - Source = data.GitHubNuGetSource, - ApiKey = data.GitHubNuGetApiKey - } - ) - ) -.Then("Push-NuGet-Packages") - .WithCriteria( (context, data) => data.ShouldPushNuGetPackages()) - .DoesForEach( - static (data, context) - => context.GetFiles(data.NuGetOutputPath.FullPath + "/*.nupkg"), - static (data, item, context) - => context.DotNetNuGetPush( - item.FullPath, - new DotNetNuGetPushSettings - { - Source = data.NuGetSource, - ApiKey = data.NuGetApiKey - } - ) - ) -.Then("Create-GitHub-Release") - .WithCriteria( (context, data) => data.ShouldPushNuGetPackages()) - .Does( - static (context, data) => context - .Command( - new CommandSettings { - ToolName = "GitHub CLI", - ToolExecutableNames = new []{ "gh.exe", "gh" }, - EnvironmentVariables = { { "GH_TOKEN", data.GitHubNuGetApiKey } } - }, - new ProcessArgumentBuilder() - .Append("release") - .Append("create") - .Append(data.Version) - .AppendSwitchQuoted("--title", data.Version) - .Append("--generate-notes") - .Append(string.Join( - ' ', - context - .GetFiles(data.NuGetOutputPath.FullPath + "/*.nupkg") - .Select(path => path.FullPath.Quote()) - )) - - ) - ) -.Then("GitHub-Actions") -.Run();