diff --git a/Build/Build.cs b/Build/Build.cs index b18beb7..416e3d3 100644 --- a/Build/Build.cs +++ b/Build/Build.cs @@ -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(x => x.From().Build); diff --git a/CHANGELOG.md b/CHANGELOG.md index 79305f2..90a4fbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Directory.Build.props b/Directory.Build.props index 7f50035..9479514 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 1.9.0-beta.6 + 1.9.0-beta.7 \ No newline at end of file diff --git a/ricaun.Nuke/Components/IAssetRelease.cs b/ricaun.Nuke/Components/IAssetRelease.cs new file mode 100644 index 0000000..f2a248e --- /dev/null +++ b/ricaun.Nuke/Components/IAssetRelease.cs @@ -0,0 +1,75 @@ +using Nuke.Common.IO; +using Nuke.Common.ProjectModel; +using ricaun.Nuke.IO; +using System.Collections.Generic; + +namespace ricaun.Nuke.Components +{ + /// + /// Represents the assets to be released. + /// + public class ReleaseAssets + { + /// + /// Gets the project associated with the release. + /// + public Project Project { get; init; } + + /// + /// Gets the version of the release. + /// + public string Version { get; init; } + + /// + /// Gets the release notes. + /// + public string Notes { get; init; } + + /// + /// Gets the collection of zip files to be released. + /// + public IReadOnlyCollection Files { get; init; } + + /// + /// Gets a value indicating whether the release is a prerelease. + /// + public bool Prerelease { get; init; } = false; + } + /// + /// Defines a component that has asset release capabilities + /// + /// executes inside and before release. + public interface IHazAssetRelease + { + /// + /// Gets the asset release instance. + /// + IAssetRelease AssetRelease => null; + + /// + /// Releases the specified assets. + /// + /// The assets to be released. + public void ReleaseAsset(ReleaseAssets releaseAssets) + { + if (AssetRelease is IAssetRelease assetRelease) + { + Serilog.Log.Information($"Asset Release {assetRelease}"); + assetRelease.ReleaseAsset(releaseAssets); + } + } + } + + /// + /// Defines the interface for releasing assets. + /// + public interface IAssetRelease + { + /// + /// Releases the specified assets. + /// + /// The assets to be released. + /// Use to post/put the release files in a private server. + public void ReleaseAsset(ReleaseAssets releaseAssets); + } +} diff --git a/ricaun.Nuke/Components/IGitPreRelease.cs b/ricaun.Nuke/Components/IGitPreRelease.cs index f62db90..6d8d69a 100644 --- a/ricaun.Nuke/Components/IGitPreRelease.cs +++ b/ricaun.Nuke/Components/IGitPreRelease.cs @@ -54,7 +54,7 @@ public bool HasPreReleaseFilter(string version) return; } ReportSummary(_ => _.AddPair("Prerelease", version)); - ReleaseGithubProject(MainProject, true); + ReleaseGitHubProject(MainProject, true); }); } } diff --git a/ricaun.Nuke/Components/IGitRelease.cs b/ricaun.Nuke/Components/IGitRelease.cs index b6911a3..7106e80 100644 --- a/ricaun.Nuke/Components/IGitRelease.cs +++ b/ricaun.Nuke/Components/IGitRelease.cs @@ -13,7 +13,7 @@ namespace ricaun.Nuke.Components /// /// IGitRelease /// - public interface IGitRelease : IRelease, IHazGitRepository, IHazGitVersion, IHazChangelog, INukeBuild + public interface IGitRelease : IRelease, IHazGitRepository, IHazGitVersion, IHazChangelog, IHazAssetRelease, INukeBuild { /// /// Target GitRelease @@ -37,15 +37,15 @@ public interface IGitRelease : IRelease, IHazGitRepository, IHazGitVersion, IHaz throw new Exception(errorMessage); } - ReleaseGithubProject(project); + ReleaseGitHubProject(project); }); /// - /// Release Github project with release notes + /// Release GitHub project with release notes /// /// /// - void ReleaseGithubProject(Project project, bool releaseAsPrerelease = false) + void ReleaseGitHubProject(Project project, bool releaseAsPrerelease = false) { if (Directory.Exists(ReleaseDirectory) == false) { @@ -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 };