Skip to content

Commit

Permalink
Enable IAssetRelease to release assets before GitRelease and `Git…
Browse files Browse the repository at this point in the history
…PreRelease`
  • Loading branch information
ricaun committed Dec 18, 2024
1 parent 087ceeb commit 43c3f10
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 7 deletions.
16 changes: 16 additions & 0 deletions Build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,24 @@
using ricaun.Nuke;
using ricaun.Nuke.Components;

class AssetRelease : IAssetRelease
{
public void ReleaseAsset(ReleaseAssets releaseAssets)
{
Serilog.Log.Information($"Project: {releaseAssets.Project.Name}");
Serilog.Log.Information($"Version: {releaseAssets.Version}");
Serilog.Log.Information($"Notes: {releaseAssets.Notes}");
Serilog.Log.Information($"Prerelease: {releaseAssets.Prerelease}");
foreach (var file in releaseAssets.Files)
{
Serilog.Log.Information($"File: {file}");
}
}
}

class Build : NukeBuild, IPublishPack, ICompileExample, ITest, IShowGitVersion, IAzureSignTool, IPrePack
{
IAssetRelease IHazAssetRelease.AssetRelease => null;
//bool IPack.UnlistNuget => true;
bool ITest.TestBuildStopWhenFailed => false;
public static int Main() => Execute<Build>(x => x.From<IPublishPack>().Build);
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [1.9.0] / 2024-12-06
### Features
- Enable sign files using `Azure Key Vault`.
- Enable `IAssetRelease` to release assets before `GitRelease` and `GitPreRelease`.
### Build
- Add `IAzureSignTool` to check if `AzureSignToolUtils` is installed.
### Updates
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>1.9.0-beta.6</Version>
<Version>1.9.0-beta.7</Version>
</PropertyGroup>
</Project>
75 changes: 75 additions & 0 deletions ricaun.Nuke/Components/IAssetRelease.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using ricaun.Nuke.IO;
using System.Collections.Generic;

namespace ricaun.Nuke.Components
{
/// <summary>
/// Represents the assets to be released.
/// </summary>
public class ReleaseAssets
{
/// <summary>
/// Gets the project associated with the release.
/// </summary>
public Project Project { get; init; }

/// <summary>
/// Gets the version of the release.
/// </summary>
public string Version { get; init; }

/// <summary>
/// Gets the release notes.
/// </summary>
public string Notes { get; init; }

/// <summary>
/// Gets the collection of zip files to be released.
/// </summary>
public IReadOnlyCollection<AbsolutePath> Files { get; init; }

/// <summary>
/// Gets a value indicating whether the release is a prerelease.
/// </summary>
public bool Prerelease { get; init; } = false;
}
/// <summary>
/// Defines a component that has asset release capabilities
/// </summary>
/// <remarks><see cref="IHazAssetRelease.AssetRelease"/> executes inside <see cref="IGitPreRelease"/> and <see cref="IGitRelease"/> before release.</remarks>
public interface IHazAssetRelease
{
/// <summary>
/// Gets the asset release instance.
/// </summary>
IAssetRelease AssetRelease => null;

/// <summary>
/// Releases the specified assets.
/// </summary>
/// <param name="releaseAssets">The assets to be released.</param>
public void ReleaseAsset(ReleaseAssets releaseAssets)
{
if (AssetRelease is IAssetRelease assetRelease)
{
Serilog.Log.Information($"Asset Release {assetRelease}");
assetRelease.ReleaseAsset(releaseAssets);
}
}
}

/// <summary>
/// Defines the interface for releasing assets.
/// </summary>
public interface IAssetRelease
{
/// <summary>
/// Releases the specified assets.
/// </summary>
/// <param name="releaseAssets">The assets to be released.</param>
/// <remarks>Use <see cref="HttpAuthTasks"/> to post/put the release files in a private server.</remarks>
public void ReleaseAsset(ReleaseAssets releaseAssets);
}
}
2 changes: 1 addition & 1 deletion ricaun.Nuke/Components/IGitPreRelease.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public bool HasPreReleaseFilter(string version)
return;
}
ReportSummary(_ => _.AddPair("Prerelease", version));
ReleaseGithubProject(MainProject, true);
ReleaseGitHubProject(MainProject, true);
});
}
}
22 changes: 17 additions & 5 deletions ricaun.Nuke/Components/IGitRelease.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace ricaun.Nuke.Components
/// <summary>
/// IGitRelease
/// </summary>
public interface IGitRelease : IRelease, IHazGitRepository, IHazGitVersion, IHazChangelog, INukeBuild
public interface IGitRelease : IRelease, IHazGitRepository, IHazGitVersion, IHazChangelog, IHazAssetRelease, INukeBuild
{
/// <summary>
/// Target GitRelease
Expand All @@ -37,15 +37,15 @@ public interface IGitRelease : IRelease, IHazGitRepository, IHazGitVersion, IHaz
throw new Exception(errorMessage);
}

ReleaseGithubProject(project);
ReleaseGitHubProject(project);
});

/// <summary>
/// Release Github project with release notes
/// Release GitHub project with release notes
/// </summary>
/// <param name="project"></param>
/// <param name="releaseAsPrerelease"></param>
void ReleaseGithubProject(Project project, bool releaseAsPrerelease = false)
void ReleaseGitHubProject(Project project, bool releaseAsPrerelease = false)
{
if (Directory.Exists(ReleaseDirectory) == false)
{
Expand Down Expand Up @@ -74,10 +74,22 @@ void ReleaseGithubProject(Project project, bool releaseAsPrerelease = false)
return;
}

var releaseNotes = GetReleaseNotes();
var releaseAssets = new ReleaseAssets
{
Project = project,
Version = version,
Notes = releaseNotes,
Files = releaseFiles,
Prerelease = releaseAsPrerelease
};

ReleaseAsset(releaseAssets);

var newRelease = new Octokit.NewRelease(version)
{
Name = version,
Body = GetReleaseNotes(),
Body = releaseNotes,
Draft = true,
TargetCommitish = GitVersion.Sha
};
Expand Down

0 comments on commit 43c3f10

Please sign in to comment.