Skip to content

Commit

Permalink
Merge pull request #159 from devlead/feature/pushnuget
Browse files Browse the repository at this point in the history
Push tagged build to NuGet
  • Loading branch information
devlead committed Dec 13, 2021
2 parents 8599fc2 + e6d012c commit c6d29b1
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions build.cake
Expand Up @@ -23,6 +23,7 @@ if (BuildSystem.GitHubActions.IsRunningOnGitHubActions)

Setup(ctx =>
{
var isMainBranch = StringComparer.OrdinalIgnoreCase.Equals("master", AppVeyor.Environment.Repository.Branch);
var isLocalBuild = !AppVeyor.IsRunningOnAppVeyor;
var releaseNotes = ParseReleaseNotes("./ReleaseNotes.md");
var version = releaseNotes.Version.ToString();
Expand All @@ -31,6 +32,11 @@ Setup(ctx =>
? version
: string.Concat(version, "-build-", AppVeyor.Environment.Build.Number.ToString("0000"));
var shouldPublish = ctx.IsRunningOnWindows()
&& AppVeyor.IsRunningOnAppVeyor
&& AppVeyor.Environment.Repository.Tag.IsTag
&& StringComparer.OrdinalIgnoreCase.Equals(version, AppVeyor.Environment.Repository.Tag.Name?.TrimStart('v'));
if (!isLocalBuild)
{
AppVeyor.UpdateBuildVersion(semVersion);
Expand All @@ -53,16 +59,20 @@ Setup(ctx =>
// Executed BEFORE the first task.
Information("Building {0} version {1} of {2} ({3}).",
Information("Building {0} version {1} of {2} ({3}), IsMainBranch: {4}, Publish: {5}.",
configuration,
version,
assemblyInfo.Product,
semVersion);
semVersion,
isMainBranch,
shouldPublish);
var artifactsRoot = MakeAbsolute(Directory("./artifacts/"));
var nugetRoot = MakeAbsolute(Directory("./nuget/"));
return new BuildData(
isMainBranch,
shouldPublish,
isLocalBuild,
configuration,
target,
Expand Down Expand Up @@ -285,6 +295,21 @@ Task("Upload-AppVeyor-Artifacts")
AppVeyor.UploadArtifact(data.BuildPaths.Package);
});

Task("Push-NuGet-Packages")
.IsDependentOn("Create-NuGet-Package")
.IsDependentOn("Test")
.WithCriteria<BuildData>(static data => data.ShouldPushNuGetPackages())
.Does<BuildData>((context, data) =>
{
context.DotNetNuGetPush(
data.BuildPaths.Package,
new DotNetNuGetPushSettings
{
Source = data.NuGetSource,
ApiKey = data.NuGetApiKey
}
);
});

Task("Upload-GitHubActions-Artifacts")
.IsDependentOn("Create-NuGet-Package")
Expand All @@ -310,7 +335,8 @@ Task("Local-Tests")
.IsDependentOn("Test");

Task("AppVeyor")
.IsDependentOn("Upload-AppVeyor-Artifacts");
.IsDependentOn("Upload-AppVeyor-Artifacts")
.IsDependentOn("Push-NuGet-Packages");

Task("GitHubActions")
.IsDependentOn("Upload-GitHubActions-Artifacts");
Expand Down Expand Up @@ -339,14 +365,24 @@ public record BuildPaths(
}

public record BuildData(
bool IsMainBranch,
bool ShouldPublish,
bool IsLocalBuild,
string Configuration,
string Target,
ICollection<string> TargetFrameworks,
DotNetMSBuildSettings MSBuildSettings,
NuGetPackSettings NuGetPackSettings,
AssemblyInfoSettings AssemblyInfoSettings,
BuildPaths BuildPaths);
BuildPaths BuildPaths)
{
public string NuGetSource { get; } = System.Environment.GetEnvironmentVariable("NUGET_SOURCE");
public string NuGetApiKey { get; } = System.Environment.GetEnvironmentVariable("NUGET_APIKEY");
public bool ShouldPushNuGetPackages() => IsMainBranch &&
ShouldPublish &&
!string.IsNullOrWhiteSpace(NuGetSource) &&
!string.IsNullOrWhiteSpace(NuGetApiKey);
}

public record TestCase(
string TargetFramework,
Expand Down

0 comments on commit c6d29b1

Please sign in to comment.