Skip to content

Commit

Permalink
Merge pull request #9 from ChrisPulman/Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPulman authored Sep 14, 2023
2 parents 8e4051e + 0ef2b1f commit 0f65398
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 57 deletions.
13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ A collection of tools to assist with building .Net applications with Nuke
* InstallDotNetSdk
* GetAsset
* SetGithubCredentials
* UploadReleaseAssetToGithub
* UploadDirectory
* CreateRelease
* Publish
* InstallAspNetCore

PublicNuGetSource - gets the public V3 nuget string

Expand All @@ -36,10 +33,4 @@ GetAsset - gets an asset from a github Release

SetGithubCredentials - sets the github credentials

UploadReleaseAssetToGithub - uploads a Release asset to github

UploadDirectory - uploads a directory to github

CreateRelease - creates a Release on github

Publish - publishes a Release to github
InstallAspNetCore - installs the aspnetcore runtime
9 changes: 5 additions & 4 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ class Build : NukeBuild
{
if (Repository.IsOnMainOrMasterBranch())
{
this.CreateRelease("ChrisPulman", "CP.Nuke.BuildTools", $"Release version {NerdbankVersioning.NuGetPackageVersion}", NerdbankVersioning.NuGetPackageVersion, null, false)
.UploadDirectory(PackagesDirectory)
.Publish("ChrisPulman", "CP.Nuke.BuildTools")
.UploadReleaseAssetToGithub(PackagesDirectory);

//this.CreateRelease(Repository, $"Release version {NerdbankVersioning.NuGetPackageVersion}", NerdbankVersioning.NuGetPackageVersion, null, false)
//.UploadDirectory(PackagesDirectory)
//.Publish(Repository)
//.UploadReleaseAssetToGithub(PackagesDirectory);

DotNetNuGetPush(settings => settings
.SetSkipDuplicate(true)
Expand Down
35 changes: 25 additions & 10 deletions build/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Text.Json.Nodes;
using Nuke.Common;
using Nuke.Common.Git;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
Expand Down Expand Up @@ -114,7 +115,7 @@ public static async Task InstallDotNetSdk(this NukeBuild _, params string[] vers
{
// check if the version is not a preview version and if the major version matches
var releaseVer = x?[latestsdk]?.ToString();
return releaseVer?.Contains("preview") == false && version.Item2[0].Equals(releaseVer.Split('.').Select(int.Parse).ToArray()[0]);
return releaseVer?.Contains("preview") == false && releaseVer?.Contains("rc") == false && version.Item2[0].Equals(releaseVer.Split('.').Select(int.Parse).ToArray()[0]);
}).OrderBy(x => Math.Abs(x![latestsdk]!.ToString().CompareTo(version.v))).First();
var verSplit = (closestVersion?[latestsdk]?.ToString())?.Split('.').Select(int.Parse).ToArray();

Expand Down Expand Up @@ -295,19 +296,24 @@ public static Release UploadDirectory(this Release release, AbsolutePath directo
/// Creates the release.
/// </summary>
/// <param name="_">The .</param>
/// <param name="repoOwner">The repo owner.</param>
/// <param name="repoName">Name of the repo.</param>
/// <param name="repo">The repo.</param>
/// <param name="tagName">Name of the tag.</param>
/// <param name="version">The version.</param>
/// <param name="commitSha">The commit sha.</param>
/// <param name="isPrerelease">if set to <c>true</c> [is prerelease].</param>
/// <returns>
/// A Release.
/// </returns>
/// <exception cref="System.ArgumentNullException">repo.</exception>
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
public static Release CreateRelease(this NukeBuild _, string repoOwner, string repoName, string tagName, string? version, string? commitSha, bool isPrerelease)
public static Release CreateRelease(this NukeBuild _, GitRepository repo, string tagName, string? version, string? commitSha, bool isPrerelease)
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
{
if (repo == null)
{
throw new ArgumentNullException(nameof(repo));
}

Log.Information("Creating release for tag {TagName}", tagName);
var newRelease = new NewRelease(tagName)
{
Expand All @@ -317,25 +323,34 @@ public static Release CreateRelease(this NukeBuild _, string repoOwner, string r
Prerelease = isPrerelease,
Body = string.Empty
};
return GitHubTasks.GitHubClient.Repository.Release.Create(repoOwner, repoName, newRelease).Result;
var repoInfo = repo.Identifier.Split('/');
return GitHubTasks.GitHubClient.Repository.Release.Create(repoInfo[0], repoInfo[1], newRelease).Result;
}

/// <summary>
/// Publishes the specified repo owner.
/// </summary>
/// <param name="release">The release.</param>
/// <param name="repoOwner">The repo owner.</param>
/// <param name="repoName">Name of the repo.</param>
/// <returns>A Release.</returns>
public static Release Publish(this Release release, string repoOwner, string repoName)
/// <param name="repo">The repo.</param>
/// <returns>
/// A Release.
/// </returns>
/// <exception cref="System.ArgumentNullException">release.</exception>
public static Release Publish(this Release release, GitRepository repo)
{
if (release == null)
{
throw new ArgumentNullException(nameof(release));
}

if (repo == null)
{
throw new ArgumentNullException(nameof(repo));
}

var repoInfo = repo.Identifier.Split('/');
return GitHubTasks.GitHubClient.Repository.Release
.Edit(repoOwner, repoName, release.Id, new ReleaseUpdate { Draft = false }).Result;
.Edit(repoInfo[0], repoInfo[1], release.Id, new ReleaseUpdate { Draft = false }).Result;
}

/// <summary>
Expand Down
79 changes: 47 additions & 32 deletions src/CP.Nuke.BuildTools/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text.Json.Nodes;
using Microsoft.AspNetCore.StaticFiles;
using Nuke.Common;
using Nuke.Common.Git;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
Expand Down Expand Up @@ -146,7 +147,7 @@ public static async Task InstallDotNetSdk(this NukeBuild _, params string[] vers
{
// check if the version is not a preview version and if the major version matches
var releaseVer = x?[latestsdk]?.ToString();
return releaseVer?.Contains("preview") == false && version.Item2[0].Equals(releaseVer.Split('.').Select(int.Parse).ToArray()[0]);
return releaseVer?.Contains("preview") == false && releaseVer?.Contains("rc") == false && version.Item2[0].Equals(releaseVer.Split('.').Select(int.Parse).ToArray()[0]);
}).OrderBy(x => Math.Abs(x![latestsdk]!.ToString().CompareTo(version.v))).First();
var verSplit = (closestVersion?[latestsdk]?.ToString())?.Split('.').Select(int.Parse).ToArray();

Expand Down Expand Up @@ -217,6 +218,28 @@ public static async Task InstallDotNetSdk(this NukeBuild _, params string[] vers
await Task.CompletedTask.ConfigureAwait(false);
}

/// <summary>
/// Installs the ASP net core.
/// </summary>
/// <param name="_">The .</param>
/// <param name="version">The version.</param>
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
public static void InstallAspNetCore(this NukeBuild _, string version)
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
{
if (float.Parse(version) < 6)
{
throw new Exception("Version must be greater than or equal to 6");
}

if (!File.Exists("dotnet-install.ps1"))
{
ProcessTasks.StartShell("pwsh -NoProfile -ExecutionPolicy unrestricted -Command Invoke-WebRequest 'https://dot.net/v1/dotnet-install.ps1' -OutFile 'dotnet-install.ps1';").AssertZeroExitCode();
}

ProcessTasks.StartShell($"pwsh -NoProfile -ExecutionPolicy unrestricted -Command ./dotnet-install.ps1 -Channel {version} -Runtime aspnetcore;").AssertZeroExitCode();
}

/// <summary>
/// Gets the asset.
/// </summary>
Expand Down Expand Up @@ -280,7 +303,7 @@ public static void SetGithubCredentials(this NukeBuild _, string authToken) =>
/// </summary>
/// <param name="release">The release.</param>
/// <param name="asset">The asset.</param>
public static void UploadReleaseAssetToGithub(this Release release, AbsolutePath asset)
internal static void UploadReleaseAssetToGithub(this Release release, AbsolutePath asset)
{
if (!asset.Exists())
{
Expand Down Expand Up @@ -309,7 +332,7 @@ public static void UploadReleaseAssetToGithub(this Release release, AbsolutePath
/// <param name="release">The release.</param>
/// <param name="directory">The directory.</param>
/// <returns>A Release.</returns>
public static Release UploadDirectory(this Release release, AbsolutePath directory)
internal static Release UploadDirectory(this Release release, AbsolutePath directory)
{
if (directory.GlobDirectories("*").Count > 0)
{
Expand All @@ -324,19 +347,24 @@ public static Release UploadDirectory(this Release release, AbsolutePath directo
/// Creates the release.
/// </summary>
/// <param name="_">The .</param>
/// <param name="repoOwner">The repo owner.</param>
/// <param name="repoName">Name of the repo.</param>
/// <param name="repo">The repo.</param>
/// <param name="tagName">Name of the tag.</param>
/// <param name="version">The version.</param>
/// <param name="commitSha">The commit sha.</param>
/// <param name="isPrerelease">if set to <c>true</c> [is prerelease].</param>
/// <returns>
/// A Release.
/// </returns>
/// <exception cref="System.ArgumentNullException">repo.</exception>
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
public static Release CreateRelease(this NukeBuild _, string repoOwner, string repoName, string tagName, string? version, string? commitSha, bool isPrerelease)
internal static Release CreateRelease(this NukeBuild _, GitRepository repo, string tagName, string? version, string? commitSha, bool isPrerelease)
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
{
if (repo == null)
{
throw new ArgumentNullException(nameof(repo));
}

Log.Information("Creating release for tag {TagName}", tagName);
var newRelease = new NewRelease(tagName)
{
Expand All @@ -346,47 +374,34 @@ public static Release CreateRelease(this NukeBuild _, string repoOwner, string r
Prerelease = isPrerelease,
Body = string.Empty
};
return GitHubTasks.GitHubClient.Repository.Release.Create(repoOwner, repoName, newRelease).Result;
var repoInfo = repo.Identifier.Split('/');
return GitHubTasks.GitHubClient.Repository.Release.Create(repoInfo[0], repoInfo[1], newRelease).Result;
}

/// <summary>
/// Publishes the specified repo owner.
/// </summary>
/// <param name="release">The release.</param>
/// <param name="repoOwner">The repo owner.</param>
/// <param name="repoName">Name of the repo.</param>
/// <returns>A Release.</returns>
public static Release Publish(this Release release, string repoOwner, string repoName)
/// <param name="repo">The repo.</param>
/// <returns>
/// A Release.
/// </returns>
/// <exception cref="System.ArgumentNullException">release.</exception>
internal static Release Publish(this Release release, GitRepository repo)
{
if (release == null)
{
throw new ArgumentNullException(nameof(release));
}

return GitHubTasks.GitHubClient.Repository.Release
.Edit(repoOwner, repoName, release.Id, new ReleaseUpdate { Draft = false }).Result;
}

/// <summary>
/// Installs the ASP net core.
/// </summary>
/// <param name="_">The .</param>
/// <param name="version">The version.</param>
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
public static void InstallAspNetCore(this NukeBuild _, string version)
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
{
if (float.Parse(version) < 6)
if (repo == null)
{
throw new Exception("Version must be greater than or equal to 6");
throw new ArgumentNullException(nameof(repo));
}

if (!File.Exists("dotnet-install.ps1"))
{
ProcessTasks.StartShell("pwsh -NoProfile -ExecutionPolicy unrestricted -Command Invoke-WebRequest 'https://dot.net/v1/dotnet-install.ps1' -OutFile 'dotnet-install.ps1';").AssertZeroExitCode();
}

ProcessTasks.StartShell($"pwsh -NoProfile -ExecutionPolicy unrestricted -Command ./dotnet-install.ps1 -Channel {version} -Runtime aspnetcore;").AssertZeroExitCode();
var repoInfo = repo.Identifier.Split('/');
return GitHubTasks.GitHubClient.Repository.Release
.Edit(repoInfo[0], repoInfo[1], release.Id, new ReleaseUpdate { Draft = false }).Result;
}
}
}

0 comments on commit 0f65398

Please sign in to comment.