Skip to content

Commit

Permalink
Merge pull request #6 from DavidRogersDev/release/1.1.0
Browse files Browse the repository at this point in the history
Release/1.1.0
  • Loading branch information
DavidRogersDev authored Nov 19, 2023
2 parents 9aa4463 + 347b795 commit e759c63
Show file tree
Hide file tree
Showing 17 changed files with 176 additions and 135 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ on:
- release/**
- develop/**
paths-ignore:
- 'readme.md'
- '**/*.md'
- 'LICENCE'
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: ['7.0.x']
dotnet-version: ['8.0.x']
steps:
- name: Setup .NET ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v3
Expand All @@ -28,10 +28,10 @@ jobs:
- name: Run nuke
shell: bash
env:
NugetApiKey: ${{ secrets.NUGET_API_KEY }}
NugetApiUrl: ${{ vars.PACKAGES_NUGET_URL }}
NugetOrgApiKey: ${{ secrets.NUGETORG_API_KEY }}
NugetOrgApiUrl: ${{ vars.NUGETORG_NUGET_URL }}
PackagesNugetApiKey: ${{ secrets.NUGET_API_KEY }}
PackagesNugetApiUrl: ${{ vars.PACKAGES_NUGET_URL }}
NugetOrgNugetApiKey: ${{ secrets.NUGETORG_API_KEY }}
NugetOrgNugetApiUrl: ${{ vars.NUGETORG_NUGET_URL }}
ReleaseNotes: ${{ vars.RELEASE_NOTES }}
run: |
./build.sh
12 changes: 6 additions & 6 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Build Schema",
"$ref": "#/definitions/build",
"title": "Build Schema",
"definitions": {
"build": {
"type": "object",
Expand Down Expand Up @@ -50,18 +50,18 @@
"type": "boolean",
"description": "Disables displaying the NUKE logo"
},
"NugetApiKey": {
"NugetOrgNugetApiKey": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"NugetApiUrl": {
"NugetOrgNugetApiUrl": {
"type": "string"
},
"NugetOrgApiKey": {
"PackagesNugetApiKey": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"NugetOrgApiUrl": {
"PackagesNugetApiUrl": {
"type": "string"
},
"Partition": {
Expand Down Expand Up @@ -135,4 +135,4 @@
}
}
}
}
}
141 changes: 68 additions & 73 deletions build/Build.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
using Invariants;
using Nuke.Common;
using Nuke.Common.CI.AzurePipelines;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.GitVersion;
using Nuke.Common.Tools.Octopus;
using Nuke.Common.Utilities.Collections;
using Serilog;
using System;
using System.Linq;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.IO.PathConstruction;
using static Nuke.Common.Tools.DotNet.DotNetTasks;

class Build : NukeBuild
Expand All @@ -23,14 +21,11 @@ class Build : NukeBuild
/// - Microsoft VisualStudio https://nuke.build/visualstudio
/// - Microsoft VSCode https://nuke.build/vscode

public static int Main() => Execute<Build>(x => x.Push);

const string BinPattern = "**/bin";
const string ObjPattern = "**/obj";

public static int Main() => Execute<Build>(b => b.Push);

[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
static bool IsPublishableBranch = false;


[Solution(GenerateProjects = true)]
Expand All @@ -46,49 +41,50 @@ class Build : NukeBuild
readonly GitVersion GitVersion;

[Parameter]
readonly string NugetApiUrl;
readonly string PackagesNugetApiUrl;

[Parameter]
[Secret]
readonly string NugetApiKey;
readonly string PackagesNugetApiKey;

[Parameter]
readonly string NugetOrgApiUrl;
readonly string NugetOrgNugetApiUrl;

[Parameter]
[Secret]
readonly string NugetOrgApiKey;

static AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
static AbsolutePath SourceDirectory => RootDirectory / "src" / ProjectValues.BusinessValidationProject;
static AbsolutePath MainLibraryDirectory => SourceDirectory / ProjectValues.BusinessValidationProject;
static AbsolutePath TestsDirectory => SourceDirectory / "BusinessValidation.Tests";
readonly string NugetOrgNugetApiKey;

static AbsolutePath ArtifactsDirectory => RootDirectory / FileSystem.ArtifactsDirectory;

Target Print => _ => _
.Description(Descriptions.Print)
.DependentFor(Clean)
.Description(Description.Print)
.Executes(() =>
{
Log.Information("Release Notes = {Value}", ReleaseNotes);
Log.Information("Root Directory = {Value}", RootDirectory);
Log.Information("Major Minor Patch = {Value}", GitVersion.MajorMinorPatch);
Log.Information("NuGet Version = {Value}", GitVersion.NuGetVersion);
Log.Information("PreReleaseLabel = {Value}", GitVersion?.PreReleaseLabel ?? "????");
Log.Information(LogMessage.ReleaseNotes, ReleaseNotes ?? ProjectValue.NoValue);
Log.Information(LogMessage.RootDirectory, RootDirectory.Name);
Log.Information(LogMessage.MajorMinorPatch, GitVersion.MajorMinorPatch);
Log.Information(LogMessage.NugetVersion, GitVersion.NuGetVersion);
Log.Information(LogMessage.PreReleaseLabel, GitVersion?.PreReleaseLabel ?? ProjectValue.NoValue);
Log.Information(LogMessage.Configuration, Configuration?.ToString() ?? ProjectValue.NoValue);

IsPublishableBranch = GitVersion.BranchName.StartsWith(Branch.Release, StringComparison.OrdinalIgnoreCase);
});

Target Clean => _ => _
.Unlisted()
.Description(Descriptions.Clean)
.Description(Description.Clean)
.DependsOn(Print)
.Executes(() =>
{
MainLibraryDirectory.GlobDirectories(BinPattern, ObjPattern).ForEach(DeleteDirectory);
TestsDirectory.GlobDirectories(BinPattern, ObjPattern).ForEach(DeleteDirectory);
EnsureCleanDirectory(ArtifactsDirectory);
Log.Information(LogMessage.CleaningBinaryDirectories);

Solution.BusinessValidation.Directory.GlobDirectories(FileSystem.GlobPattern.BinPattern, FileSystem.GlobPattern.ObjPattern).DeleteDirectories();
Solution.BusinessValidation_Tests.Directory.GlobDirectories(FileSystem.GlobPattern.BinPattern, FileSystem.GlobPattern.ObjPattern).DeleteDirectories();

ArtifactsDirectory.CreateOrCleanDirectory();
});

Target Restore => _ => _
.Description(Descriptions.Restore)
.Description(Description.Restore)
.DependsOn(Clean)
.Executes(() =>
{
Expand All @@ -100,7 +96,7 @@ class Build : NukeBuild
});

Target Compile => _ => _
.Description(Descriptions.Compile)
.Description(Description.Compile)
.DependsOn(Restore)
.Executes(() =>
{
Expand All @@ -113,19 +109,20 @@ from framework in project.GetTargetFrameworks()
_.SetProject(Solution)
.EnableNoRestore()
.SetConfiguration(Configuration)
.SetCopyright(PackageValues.Copyright)
.SetCopyright(PackageValue.Copyright)
.SetAssemblyVersion(GitVersion.AssemblySemFileVer)
.SetFileVersion(GitVersion.MajorMinorPatch)
.SetVersion(GitVersion.NuGetVersion)
.SetInformationalVersion(GitVersion.InformationalVersion)
.AddNoWarns(NoWarn.Codes)
.CombineWith(publishConfiguration, (_, v) =>
_.SetProject(v.project)
.SetFramework(v.framework))
);
});

Target Test => _ => _
.Description(Descriptions.Test)
.Description(Description.Test)
.DependsOn(Compile)
.Executes(() =>
{
Expand All @@ -138,78 +135,76 @@ from framework in project.GetTargetFrameworks()
});

Target Pack => _ => _
.Description(Descriptions.Pack)
.Description(Description.Pack)
.DependsOn(Test)
.Executes(() => DotNetPack(s => s
.SetProject(Solution.BusinessValidation)
.SetConfiguration(Configuration)
.EnableNoBuild()
.EnableNoRestore()
.SetNoDependencies(true)
.SetPackageId(ProjectValues.BusinessValidationProject)
.SetTitle(ProjectValues.BusinessValidationProject)
.SetPackageId(Solution.BusinessValidation.Name)
.SetTitle(Solution.BusinessValidation.Name)
.SetVersion(GitVersion.NuGetVersion)
.SetRepositoryType(AzurePipelinesRepositoryType.Git.ToString().ToLowerInvariant())
.SetPackageReleaseNotes(ReleaseNotes)
.SetPackageProjectUrl(PackageValues.ProjectUrl)
.SetAuthors(PackageValues.Author)
.SetProperty(PackageProperties.PackageLicenseExpression, PackageValues.MITLicence)
.SetPackageTags(PackageValues.Tags)
.SetPackageProjectUrl(PackageValue.ProjectUrl)
.SetAuthors(PackageValue.Author)
.SetProperty(PackageProperty.PackageLicenseExpression, PackageValue.MITLicence)
.SetPackageTags(PackageValue.Tags)
.SetPackageRequireLicenseAcceptance(false)
.SetDescription(PackageValues.Description)
.SetRepositoryUrl(PackageValues.RepositoryUrl)
.SetProperty(PackageProperties.RepositoryBranch, GitVersion.BranchName)
.SetProperty(PackageProperties.RepositoryCommit, GitVersion.Sha)
.SetProperty(PackageProperties.Copyright, PackageValues.Copyright)
.SetProperty(PackageProperties.PackageReadmeFile, PackageValues.Readme)
.SetProperty(PackageProperties.PackageIcon, PackageValues.Icon)
.SetDescription(PackageValue.Description)
.SetRepositoryUrl(PackageValue.RepositoryUrl)
.SetProperty(PackageProperty.RepositoryBranch, GitVersion.BranchName)
.SetProperty(PackageProperty.RepositoryCommit, GitVersion.Sha)
.SetProperty(PackageProperty.Copyright, PackageValue.Copyright)
.SetProperty(PackageProperty.PackageReadmeFile, PackageValue.Readme)
.SetProperty(PackageProperty.PackageIcon, PackageValue.Icon)
.SetOutputDirectory(ArtifactsDirectory)
));

Target Push => _ => _
.Description(Descriptions.Push)
.Description(Description.Push)
.OnlyWhenStatic(() => IsServerBuild) // checked before the build steps run.
.Requires(() => NugetApiKey)
.Requires(() => NugetApiUrl)
.Requires(() => Configuration.Equals(Configuration.Release))
.OnlyWhenDynamic(() => IsPublishableBranch) // checked during run. This variable is set in the Print task.
.Requires(() => NugetOrgNugetApiKey)
.Requires(() => NugetOrgNugetApiUrl)
.Requires(() => PackagesNugetApiKey)
.Requires(() => PackagesNugetApiUrl)
.DependsOn(Pack)
.Executes(() =>
{
var nugetFiles = GlobFiles(ArtifactsDirectory, "*.nupkg");

Assert.NotEmpty(nugetFiles, "There are no Nuget files");
var nugetFiles = ArtifactsDirectory.GlobFiles(FileSystem.Nuget.Packages);

var branchName = GitVersion.BranchName;
Assert.NotEmpty(nugetFiles, LogMessage.NoNugetFiles);

// if we are on the main branch and it is not a pre-release, publish to Nuget.org
if (branchName.StartsWith("release", StringComparison.OrdinalIgnoreCase))
{
// if it is not a pre-release, publish to Nuget.org
if (string.IsNullOrWhiteSpace(GitVersion.PreReleaseLabel))
{
// this publishes to the nuget.org package manager
nugetFiles.Where(x => !x.EndsWith("symbols.nupkg"))
nugetFiles.Where(filePath => !filePath.Name.EndsWith(FileSystem.Nuget.SymbolsPackages, StringComparison.OrdinalIgnoreCase))
.ForEach(x =>
{
DotNetNuGetPush(s => s
.SetTargetPath(x)
.SetSource(NugetOrgApiUrl)
.SetApiKey(NugetOrgApiKey)
.SetSource(NugetOrgNugetApiUrl)
.SetApiKey(NugetOrgNugetApiKey)
);
});
}
else if (GitVersion.PreReleaseLabel.Equals("rc"))
{
// this publishes to the github packages package manager
nugetFiles.Where(x => !x.EndsWith("symbols.nupkg"))
else if (GitVersion.PreReleaseLabel.Equals(BuildType.Ci, StringComparison.OrdinalIgnoreCase) ||
GitVersion.PreReleaseLabel.Equals(BuildType.Rc, StringComparison.OrdinalIgnoreCase))
{
// this publishes to the github packages package manager
nugetFiles.Where(filePath => !filePath.Name.EndsWith(FileSystem.Nuget.SymbolsPackages))
.ForEach(x =>
{
DotNetNuGetPush(s => s
.SetTargetPath(x)
.SetSource(NugetApiUrl)
.SetApiKey(NugetApiKey)
);
});
}
{
DotNetNuGetPush(s => s
.SetTargetPath(x)
.SetSource(PackagesNugetApiUrl)
.SetApiKey(PackagesNugetApiKey)
);
});
}
});
}
8 changes: 8 additions & 0 deletions build/Invariants/Branch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Invariants
{
public sealed class Branch
{
public const string Main = "main";
public const string Release = "release";
}
}
8 changes: 8 additions & 0 deletions build/Invariants/BuildType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Invariants
{
public sealed class BuildType
{
public const string Ci = "ci";
public const string Rc = "rc";
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Invariants
namespace Invariants
{
public sealed class Descriptions
public sealed class Description
{
public const string Clean = "Cleans the project.";
public const string Compile = "Compiles the project.";
Expand Down
20 changes: 20 additions & 0 deletions build/Invariants/FileSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Invariants
{
public sealed class FileSystem
{
public sealed class GlobPattern
{
public const string BinPattern = "**/bin";
public const string ObjPattern = "**/obj";
}

public sealed class Nuget
{
public const string Packages = "*.nupkg";
public const string SymbolsPackages = "symbols.nupkg";
}


public const string ArtifactsDirectory = "artifacts";
}
}
14 changes: 14 additions & 0 deletions build/Invariants/LogMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Invariants
{
public sealed class LogMessage
{
public const string CleaningBinaryDirectories = "Cleaning binary directories";
public const string Configuration = "Configuration = {Value}";
public const string MajorMinorPatch = "Major Minor Patch = {Value}";
public const string NoNugetFiles = "There are no Nuget files";
public const string NugetVersion = "NuGet Version = {Value}";
public const string PreReleaseLabel = "PreReleaseLabel = {Value}";
public const string ReleaseNotes = "Release Notes = {Value}";
public const string RootDirectory= "Root Directory = {Value}";
}
}
Loading

0 comments on commit e759c63

Please sign in to comment.