Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,6 @@ TestResult.xml

# macOS Finder metadata
.DS_Store

# Test output
TestResults/
141 changes: 75 additions & 66 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Build Schema",
"$ref": "#/definitions/build",
"definitions": {
"build": {
"type": "object",
"Host": {
"type": "string",
"enum": [
"AppVeyor",
"AzurePipelines",
"Bamboo",
"Bitbucket",
"Bitrise",
"GitHubActions",
"GitLab",
"Jenkins",
"Rider",
"SpaceAutomation",
"TeamCity",
"Terminal",
"TravisCI",
"VisualStudio",
"VSCode"
]
},
"ExecutableTarget": {
"type": "string",
"enum": [
"Clean",
"Compile",
"CopyToLocalPackages",
"Pack",
"Restore",
"Test"
]
},
"Verbosity": {
"type": "string",
"description": "",
"enum": [
"Verbose",
"Normal",
"Minimal",
"Quiet"
]
},
"NukeBuild": {
"properties": {
"AutoDetectBranch": {
"type": "boolean",
"description": "Whether to auto-detect the branch name - this is okay for a local build, but should not be used under CI"
},
"Configuration": {
"type": "string",
"description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)",
"enum": [
"Debug",
"Release"
]
},
"Continue": {
"type": "boolean",
"description": "Indicates to continue a previously failed build attempt"
Expand All @@ -27,33 +53,13 @@
"description": "Shows the help text for this build assembly"
},
"Host": {
"type": "string",
"description": "Host for execution. Default is 'automatic'",
"enum": [
"AppVeyor",
"AzurePipelines",
"Bamboo",
"Bitrise",
"GitHubActions",
"GitLab",
"Jenkins",
"Rider",
"SpaceAutomation",
"TeamCity",
"Terminal",
"TravisCI",
"VisualStudio",
"VSCode"
]
"$ref": "#/definitions/Host"
},
"NoLogo": {
"type": "boolean",
"description": "Disables displaying the NUKE logo"
},
"OCTOVERSION_CurrentBranch": {
"type": "string",
"description": "Branch name for OctoVersion to use to calculate the version number. Can be set via the environment variable OCTOVERSION_CurrentBranch"
},
"Partition": {
"type": "string",
"description": "Partition to use on CI"
Expand All @@ -77,47 +83,50 @@
"type": "array",
"description": "List of targets to be skipped. Empty list skips all dependencies",
"items": {
"type": "string",
"enum": [
"Clean",
"Compile",
"CopyToLocalPackages",
"Pack",
"Restore",
"Test"
]
"$ref": "#/definitions/ExecutableTarget"
}
},
"Solution": {
"type": "string",
"description": "Path to a solution file that is automatically loaded"
},
"Target": {
"type": "array",
"description": "List of targets to be invoked. Default is '{default_target}'",
"items": {
"type": "string",
"enum": [
"Clean",
"Compile",
"CopyToLocalPackages",
"Pack",
"Restore",
"Test"
]
"$ref": "#/definitions/ExecutableTarget"
}
},
"Verbosity": {
"type": "string",
"description": "Logging verbosity during build execution. Default is 'Normal'",
"$ref": "#/definitions/Verbosity"
}
}
}
},
"allOf": [
{
"properties": {
"AutoDetectBranch": {
"type": "boolean",
"description": "Whether to auto-detect the branch name - this is okay for a local build, but should not be used under CI"
},
"Configuration": {
"type": "string",
"description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)",
"enum": [
"Minimal",
"Normal",
"Quiet",
"Verbose"
"Debug",
"Release"
]
},
"OCTOVERSION_CurrentBranch": {
"type": "string",
"description": "Branch name for OctoVersion to use to calculate the version number. Can be set via the environment variable OCTOVERSION_CurrentBranch"
},
"Solution": {
"type": "string",
"description": "Path to a solution file that is automatically loaded"
}
}
},
{
"$ref": "#/definitions/NukeBuild"
}
}
}
]
}
72 changes: 34 additions & 38 deletions build/Build.cs
Original file line number Diff line number Diff line change
@@ -1,70 +1,66 @@
// ReSharper disable RedundantUsingDirective

using System;
using System.Linq;
using Nuke.Common;
using Nuke.Common.CI;
using Nuke.Common.CI.TeamCity;
using Nuke.Common.Execution;
using Nuke.Common.Git;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.OctoVersion;
using Nuke.Common.Utilities.Collections;
using static Nuke.Common.EnvironmentInfo;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.IO.PathConstruction;
using static Nuke.Common.Tools.DotNet.DotNetTasks;

[CheckBuildProjectConfigurations]
[ShutdownDotNetAfterServerBuild]
[UnsetVisualStudioEnvironmentVariables]
class Build : NukeBuild
{
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
public Configuration Configuration => IsLocalBuild ? Configuration.Debug : Configuration.Release;
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;

[Solution] readonly Solution Solution;

[Parameter("Branch name for OctoVersion to use to calculate the version number. Can be set via the environment variable OCTOVERSION_CurrentBranch.", Name = "OCTOVERSION_CurrentBranch")]
[Parameter("Branch name for OctoVersion to use to calculate the version number. Can be set via the environment variable OCTOVERSION_CurrentBranch.",
Name = "OCTOVERSION_CurrentBranch")]
readonly string BranchName;

[Parameter("Whether to auto-detect the branch name - this is okay for a local build, but should not be used under CI.")]
readonly bool AutoDetectBranch = IsLocalBuild;
[OctoVersion(UpdateBuildNumber = true, BranchParameter = nameof(BranchName), AutoDetectBranchParameter = nameof(AutoDetectBranch), Framework = "net8.0")]
readonly OctoVersionInfo OctoVersionInfo;

[Solution] readonly Solution Solution;
[OctoVersion(UpdateBuildNumber = true, BranchMember = nameof(BranchName),
AutoDetectBranchMember = nameof(AutoDetectBranch), Framework = "net10.0")]
readonly OctoVersionInfo OctoVersionInfo;

AbsolutePath SourceDirectory => RootDirectory / "source";
AbsolutePath TestsDirectory => RootDirectory / "tests";
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
AbsolutePath PublishDirectory => RootDirectory / "publish";
AbsolutePath LocalPackagesDirectory => RootDirectory / ".." / "LocalPackages";

Target Clean => _ => _
.Before(Restore)
.Executes(() =>
{
SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(DeleteDirectory);
TestsDirectory.GlobDirectories("**/bin", "**/obj", "**/TestResults").ForEach(DeleteDirectory);
EnsureCleanDirectory(ArtifactsDirectory);
EnsureCleanDirectory(PublishDirectory);
SourceDirectory.GlobDirectories("**/bin", "**/obj", "**/TestResults").ForEach(d => d.DeleteDirectory());
ArtifactsDirectory.CreateOrCleanDirectory();
});

Target Restore => _ => _
.DependsOn(Clean)
.Executes(() =>
{
DotNetRestore(s => s
DotNetRestore(_ => _
.SetProjectFile(Solution));
});

Target Compile => _ => _
.DependsOn(Clean)
.DependsOn(Restore)
.Executes(() =>
{
DotNetBuild(s => s
Serilog.Log.Information("Building Octopus.CoreParsers.Hcl v{Version}", OctoVersionInfo.FullSemVer);

DotNetBuild(_ => _
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.SetVersion(OctoVersionInfo.FullSemVer)
.SetInformationalVersion(OctoVersionInfo.InformationalVersion)
.EnableNoRestore());
});

Target Test => _ => _
.DependsOn(Compile)
.Executes(() =>
Expand All @@ -73,11 +69,13 @@ class Build : NukeBuild
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.SetLoggers("trx")
.SetVerbosity(DotNetVerbosity.Normal)
.SetVerbosity(DotNetVerbosity.normal)
.EnableNoBuild()
.EnableNoRestore());
GlobFiles(SourceDirectory, "**/*.trx")
.ForEach(x => CopyFileToDirectory(x, ArtifactsDirectory, FileExistsPolicy.Overwrite));

// TeamCity reads test results from the published artifacts.
SourceDirectory.GlobFiles("**/*.trx")
.ForEach(f => f.CopyToDirectory(ArtifactsDirectory, ExistsPolicy.FileOverwrite));
});

Target Pack => _ => _
Expand All @@ -90,22 +88,20 @@ class Build : NukeBuild
.SetConfiguration(Configuration)
.SetOutputDirectory(ArtifactsDirectory)
.EnableNoBuild()
.AddProperty("Version", OctoVersionInfo.FullSemVer)
);
.AddProperty("Version", OctoVersionInfo.FullSemVer));

TeamCity.Instance?.PublishArtifacts(ArtifactsDirectory / $"Octopus.CoreParsers.Hcl.{OctoVersionInfo.FullSemVer}.nupkg");
});

Target CopyToLocalPackages => _ => _
.OnlyWhenStatic(() => IsLocalBuild)
.DependsOn(Pack)
.TriggeredBy(Pack)
.Executes(() =>
{
GlobFiles(ArtifactsDirectory, $"*.{OctoVersionInfo.FullSemVer}.nupkg")
.ForEach(x => CopyFileToDirectory(x, LocalPackagesDirectory, FileExistsPolicy.Overwrite));
LocalPackagesDirectory.CreateDirectory();
(ArtifactsDirectory / $"Octopus.CoreParsers.Hcl.{OctoVersionInfo.FullSemVer}.nupkg")
.CopyToDirectory(LocalPackagesDirectory, ExistsPolicy.FileOverwrite);
});

public static int Main() => Execute<Build>(
x => x.Pack,
x => x.CopyToLocalPackages);
}
public static int Main() => Execute<Build>(x => x.Pack);
}
7 changes: 3 additions & 4 deletions build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<RootNamespace></RootNamespace>
<NoWarn>CS0649;CS0169</NoWarn>
<NoWarn>CS0649;CS0169;CS8618</NoWarn>
<NukeRootDirectory>..</NukeRootDirectory>
<NukeScriptDirectory>..</NukeScriptDirectory>
<NukeTelemetryVersion>1</NukeTelemetryVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageDownload Include="OctoVersion.Tool" Version="[0.2.963]" />
<PackageDownload Include="JetBrains.ReSharper.GlobalTools" Version="[2021.2.0]" />
<PackageReference Include="Nuke.Common" Version="6.0.1" />
<PackageReference Include="Nuke.Common" Version="10.1.0" />
<PackageReference Include="Octopus.OctoVersion.Tool" Version="1.1.74" ExcludeAssets="all" />
</ItemGroup>

</Project>