From 4a5ada41d95027a242daaa41fcb8324e05d635b1 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Fri, 6 Dec 2024 12:06:20 -0300 Subject: [PATCH 01/44] Add `AzureSignToolUtils` and `build` with `.props` and `.targets` --- Build/.nuke/build.schema.json | 1 + Build/Build.cs | 2 +- Build/Build.csproj | 3 + Build/IAzureSignTool.cs | 13 + CHANGELOG.md | 15 +- ricaun.Nuke/Tools/AzureSignToolUtils.cs | 147 ++++ .../NuGetKeyVaultSignTool.Generated.cs | 661 ++++++++++++++++++ .../NuGetKeyVaultSignTool.json | 113 +++ ricaun.Nuke/build/ricaun.Nuke.targets | 15 + ricaun.Nuke/ricaun.Nuke.csproj | 8 +- 10 files changed, 975 insertions(+), 3 deletions(-) create mode 100644 Build/IAzureSignTool.cs create mode 100644 ricaun.Nuke/Tools/AzureSignToolUtils.cs create mode 100644 ricaun.Nuke/Tools/NuGetKeyVaultSignTool/NuGetKeyVaultSignTool.Generated.cs create mode 100644 ricaun.Nuke/Tools/NuGetKeyVaultSignTool/NuGetKeyVaultSignTool.json create mode 100644 ricaun.Nuke/build/ricaun.Nuke.targets diff --git a/Build/.nuke/build.schema.json b/Build/.nuke/build.schema.json index a9c9453..8eb15af 100644 --- a/Build/.nuke/build.schema.json +++ b/Build/.nuke/build.schema.json @@ -24,6 +24,7 @@ "ExecutableTarget": { "type": "string", "enum": [ + "AzureSignTool", "Build", "Clean", "Compile", diff --git a/Build/Build.cs b/Build/Build.cs index 45a473b..b18beb7 100644 --- a/Build/Build.cs +++ b/Build/Build.cs @@ -3,7 +3,7 @@ using ricaun.Nuke; using ricaun.Nuke.Components; -class Build : NukeBuild, IPublishPack, ICompileExample, ITest, IShowGitVersion, IPrePack +class Build : NukeBuild, IPublishPack, ICompileExample, ITest, IShowGitVersion, IAzureSignTool, IPrePack { //bool IPack.UnlistNuget => true; bool ITest.TestBuildStopWhenFailed => false; diff --git a/Build/Build.csproj b/Build/Build.csproj index 36e6397..fd86e57 100644 --- a/Build/Build.csproj +++ b/Build/Build.csproj @@ -18,4 +18,7 @@ + + + diff --git a/Build/IAzureSignTool.cs b/Build/IAzureSignTool.cs new file mode 100644 index 0000000..31688b5 --- /dev/null +++ b/Build/IAzureSignTool.cs @@ -0,0 +1,13 @@ +using Nuke.Common; +using ricaun.Nuke.Components; + +public interface IAzureSignTool : IClean, ICompile +{ + Target AzureSignTool => _ => _ + .TriggeredBy(Clean) + .Before(Compile) + .Executes(() => + { + ricaun.Nuke.Tools.AzureSignToolUtils.EnsureAzureToolIsInstalled(); + }); +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 5048731..db04867 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,20 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.9.0] / 2024-12-06 +### Features +- Enable sign files using `Azure Key Vault`. +### Build +- Add `IAzureSignTool` to check if `AzureSignToolUtils` is installed. +- Add import `build` with `.targets` +### Updates +- Add `AzureSignToolUtils` to sign files using `AzureSignToolTasks` or `NuGetKeyVaultSignToolTasks`. +- Add `NuGetKeyVaultSignTool` for nuke version `8.*`. +- Add `AzureKeyVaultConfig` with json file with `Azure Key Vault` without secrets. +- Add `build` with `.targets` to install packages `AzureSignTool` and `NuGetKeyVaultSignTool`. + ## [1.8.2] / 2024-11-20 -### Update +### Updates - Update `Nuke.Common` to `8.1.4`. - Update `FileSystemTasks.CopyFileToDirectory` to `AbsolutePathExtensions.CopyToDirectory`. - Update `FileSystemTasks.CopyDirectoryRecursively` to `AbsolutePathExtensions.Copy`. @@ -358,6 +370,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - First Release [vNext]: ../../compare/1.0.0...HEAD +[1.9.0]: ../../compare/1.8.2...1.9.0 [1.8.2]: ../../compare/1.8.1...1.8.2 [1.8.1]: ../../compare/1.8.0...1.8.1 [1.8.0]: ../../compare/1.7.4...1.8.0 diff --git a/ricaun.Nuke/Tools/AzureSignToolUtils.cs b/ricaun.Nuke/Tools/AzureSignToolUtils.cs new file mode 100644 index 0000000..bdcf46c --- /dev/null +++ b/ricaun.Nuke/Tools/AzureSignToolUtils.cs @@ -0,0 +1,147 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Nuke.Common.Tools.NuGetKeyVaultSignTool; +using Nuke.Common.Tools.AzureSignTool; +using System.IO; + +namespace ricaun.Nuke.Tools +{ + /// + /// Utility class for working with Azure Sign Tool. + /// + public class AzureSignToolUtils + { + private const string TimestampUrlDefault = "http://timestamp.digicert.com"; + private const string TimestampDigestDefault = "sha256"; + private const string NugetPackageExtension = ".nupkg"; + + /// + /// Ensures that Azure Sign Tool and NuGet Key Vault Sign Tool are installed. + /// + /// Thrown when the required packages are missing. + public static void EnsureAzureToolIsInstalled() + { + try + { + _ = AzureSignToolTasks.AzureSignToolPath; + _ = NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPath; + } + catch (Exception ex) + { + var packagesToInstall = """ + + + + + """; + throw new Exception($"Missing package reference/download, install the packages in the project: \n{packagesToInstall}", ex); + } + } + + /// + /// Signs the specified file using Azure Sign Tool or NuGet Key Vault Sign Tool. + /// + /// The name of the file to sign. + /// The Azure Key Vault configuration. + /// The Azure Key Vault client secret. + /// The default timestamp URL. + /// The default timestamp digest. + public static void Sign(string fileName, + AzureKeyVaultConfig azureKeyVaultConfig, string azureKeyVaultClientSecret, + string timestampUrlDefault = TimestampUrlDefault, + string timestampDigestDefault = TimestampDigestDefault) + { + if (Path.GetExtension(fileName) == NugetPackageExtension) + { + NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignTool(x => x + .SetFile(fileName) + .SetKeyVaultCertificateName(azureKeyVaultConfig.AzureKeyVaultCertificate) + .SetKeyVaultUrl(azureKeyVaultConfig.AzureKeyVaultUrl) + .SetKeyVaultClientId(azureKeyVaultConfig.AzureKeyVaultClientId) + .SetKeyVaultTenantId(azureKeyVaultConfig.AzureKeyVaultTenantId) + .SetKeyVaultClientSecret(azureKeyVaultClientSecret) + .SetTimestampRfc3161Url(azureKeyVaultConfig.TimestampUrl ?? timestampUrlDefault) + .SetTimestampDigest(azureKeyVaultConfig.TimestampDigest ?? timestampDigestDefault) + ); + return; + } + + AzureSignToolTasks.AzureSignTool(x => x + .SetFiles(fileName) + .SetKeyVaultCertificateName(azureKeyVaultConfig.AzureKeyVaultCertificate) + .SetKeyVaultUrl(azureKeyVaultConfig.AzureKeyVaultUrl) + .SetKeyVaultClientId(azureKeyVaultConfig.AzureKeyVaultClientId) + .SetKeyVaultTenantId(azureKeyVaultConfig.AzureKeyVaultTenantId) + .SetKeyVaultClientSecret(azureKeyVaultClientSecret) + .SetTimestampRfc3161Url(azureKeyVaultConfig.TimestampUrl ?? timestampUrlDefault) + .SetTimestampDigest(azureKeyVaultConfig.TimestampDigest ?? timestampDigestDefault) + ); + } + } + + /// + /// Represents the configuration for Azure Key Vault. + /// + public class AzureKeyVaultConfig + { + /// + /// Gets or sets the Azure Key Vault certificate. + /// + public string AzureKeyVaultCertificate { get; set; } + + /// + /// Gets or sets the Azure Key Vault URL. + /// + public string AzureKeyVaultUrl { get; set; } + + /// + /// Gets or sets the Azure Key Vault client ID. + /// + public string AzureKeyVaultClientId { get; set; } + + /// + /// Gets or sets the Azure Key Vault tenant ID. + /// + public string AzureKeyVaultTenantId { get; set; } + + /// + /// Gets or sets the timestamp URL. + /// + public string TimestampUrl { get; set; } + + /// + /// Gets or sets the timestamp digest. + /// + public string TimestampDigest { get; set; } + + /// + /// Creates an instance of from the specified JSON content. + /// + /// The JSON content representing the Azure Key Vault configuration. + /// An instance of . + public static AzureKeyVaultConfig Create(string jsonContent) + { + try + { + return Newtonsoft.Json.JsonConvert.DeserializeObject(jsonContent); + } + catch { } + return default; + } + + /// + /// Checks if the Azure Key Vault configuration is valid. + /// + /// true if the configuration is valid; otherwise, false. + public bool IsValid() + { + return !string.IsNullOrEmpty(AzureKeyVaultCertificate) && + !string.IsNullOrEmpty(AzureKeyVaultUrl) && + !string.IsNullOrEmpty(AzureKeyVaultClientId) && + !string.IsNullOrEmpty(AzureKeyVaultTenantId); + } + } +} diff --git a/ricaun.Nuke/Tools/NuGetKeyVaultSignTool/NuGetKeyVaultSignTool.Generated.cs b/ricaun.Nuke/Tools/NuGetKeyVaultSignTool/NuGetKeyVaultSignTool.Generated.cs new file mode 100644 index 0000000..b6652a7 --- /dev/null +++ b/ricaun.Nuke/Tools/NuGetKeyVaultSignTool/NuGetKeyVaultSignTool.Generated.cs @@ -0,0 +1,661 @@ + +using JetBrains.Annotations; +using Newtonsoft.Json; +using Nuke.Common; +using Nuke.Common.Tooling; +using Nuke.Common.Tools; +using Nuke.Common.Utilities.Collections; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Linq; +using System.Text; + +namespace Nuke.Common.Tools.NuGetKeyVaultSignTool; + +/// +///

NuGet Key Vault Sign Tool is similar to nuget sign, with the major difference being that it uses Azure Key Vault for performing the signing process. Similar usage configuration like AzureSignTool, except is used to sign nuget package.

+///

For more details, visit the official website.

+///
+[PublicAPI] +[ExcludeFromCodeCoverage] +[NuGetPackageRequirement(NuGetKeyVaultSignToolPackageId)] +public partial class NuGetKeyVaultSignToolTasks + : IRequireNuGetPackage +{ + /// + /// NuGetKeyVaultSignToolPackageId + /// + public const string NuGetKeyVaultSignToolPackageId = "NuGetKeyVaultSignTool"; + /// + /// Path to the NuGetKeyVaultSignTool executable. + /// + public static string NuGetKeyVaultSignToolPath => + ToolPathResolver.TryGetEnvironmentExecutable("NUGETKEYVAULTSIGNTOOL_EXE") ?? + NuGetToolPathResolver.GetPackageExecutable("NuGetKeyVaultSignTool", "NuGetKeyVaultSignTool.dll"); + /// + /// NuGetKeyVaultSignToolLogger + /// + public static Action NuGetKeyVaultSignToolLogger { get; set; } = ProcessTasks.DefaultLogger; + /// + /// NuGetKeyVaultSignToolExitHandler + /// + public static Action NuGetKeyVaultSignToolExitHandler { get; set; } = ProcessTasks.DefaultExitHandler; + /// + ///

NuGet Key Vault Sign Tool is similar to nuget sign, with the major difference being that it uses Azure Key Vault for performing the signing process. Similar usage configuration like AzureSignTool, except is used to sign nuget package.

+ ///

For more details, visit the official website.

+ ///
+ public static IReadOnlyCollection NuGetKeyVaultSignTool(ArgumentStringHandler arguments, string workingDirectory = null, IReadOnlyDictionary environmentVariables = null, int? timeout = null, bool? logOutput = null, bool? logInvocation = null, Action logger = null, Action exitHandler = null) + { + using var process = ProcessTasks.StartProcess(NuGetKeyVaultSignToolPath, arguments, workingDirectory, environmentVariables, timeout, logOutput, logInvocation, logger ?? NuGetKeyVaultSignToolLogger); + (exitHandler ?? (p => NuGetKeyVaultSignToolExitHandler.Invoke(null, p))).Invoke(process.AssertWaitForExit()); + return process.Output; + } + /// + ///

NuGet Key Vault Sign Tool is similar to nuget sign, with the major difference being that it uses Azure Key Vault for performing the signing process. Similar usage configuration like AzureSignTool, except is used to sign nuget package.

+ ///

For more details, visit the official website.

+ ///
+ /// + ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

+ ///
    + ///
  • <file> via
  • + ///
  • --azure-key-vault-accesstoken via
  • + ///
  • --azure-key-vault-certificate via
  • + ///
  • --azure-key-vault-client-id via
  • + ///
  • --azure-key-vault-client-secret via
  • + ///
  • --azure-key-vault-managed-identity via
  • + ///
  • --azure-key-vault-tenant-id via
  • + ///
  • --azure-key-vault-url via
  • + ///
  • --file-digest via
  • + ///
  • --force via
  • + ///
  • --output via
  • + ///
  • --timestamp-digest via
  • + ///
  • --timestamp-rfc3161 via
  • + ///
+ ///
+ public static IReadOnlyCollection NuGetKeyVaultSignTool(NuGetKeyVaultSignToolSettings toolSettings = null) + { + toolSettings = toolSettings ?? new NuGetKeyVaultSignToolSettings(); + using var process = ProcessTasks.StartProcess(toolSettings); + toolSettings.ProcessExitHandler.Invoke(toolSettings, process.AssertWaitForExit()); + return process.Output; + } + /// + ///

NuGet Key Vault Sign Tool is similar to nuget sign, with the major difference being that it uses Azure Key Vault for performing the signing process. Similar usage configuration like AzureSignTool, except is used to sign nuget package.

+ ///

For more details, visit the official website.

+ ///
+ /// + ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

+ ///
    + ///
  • <file> via
  • + ///
  • --azure-key-vault-accesstoken via
  • + ///
  • --azure-key-vault-certificate via
  • + ///
  • --azure-key-vault-client-id via
  • + ///
  • --azure-key-vault-client-secret via
  • + ///
  • --azure-key-vault-managed-identity via
  • + ///
  • --azure-key-vault-tenant-id via
  • + ///
  • --azure-key-vault-url via
  • + ///
  • --file-digest via
  • + ///
  • --force via
  • + ///
  • --output via
  • + ///
  • --timestamp-digest via
  • + ///
  • --timestamp-rfc3161 via
  • + ///
+ ///
+ public static IReadOnlyCollection NuGetKeyVaultSignTool(Configure configurator) + { + return NuGetKeyVaultSignTool(configurator(new NuGetKeyVaultSignToolSettings())); + } + /// + ///

NuGet Key Vault Sign Tool is similar to nuget sign, with the major difference being that it uses Azure Key Vault for performing the signing process. Similar usage configuration like AzureSignTool, except is used to sign nuget package.

+ ///

For more details, visit the official website.

+ ///
+ /// + ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

+ ///
    + ///
  • <file> via
  • + ///
  • --azure-key-vault-accesstoken via
  • + ///
  • --azure-key-vault-certificate via
  • + ///
  • --azure-key-vault-client-id via
  • + ///
  • --azure-key-vault-client-secret via
  • + ///
  • --azure-key-vault-managed-identity via
  • + ///
  • --azure-key-vault-tenant-id via
  • + ///
  • --azure-key-vault-url via
  • + ///
  • --file-digest via
  • + ///
  • --force via
  • + ///
  • --output via
  • + ///
  • --timestamp-digest via
  • + ///
  • --timestamp-rfc3161 via
  • + ///
+ ///
+ public static IEnumerable<(NuGetKeyVaultSignToolSettings Settings, IReadOnlyCollection Output)> NuGetKeyVaultSignTool(CombinatorialConfigure configurator, int degreeOfParallelism = 1, bool completeOnFailure = false) + { + return configurator.Invoke(NuGetKeyVaultSignTool, NuGetKeyVaultSignToolLogger, degreeOfParallelism, completeOnFailure); + } +} +#region NuGetKeyVaultSignToolSettings +/// +/// Used within . +/// +[PublicAPI] +[ExcludeFromCodeCoverage] +[Serializable] +public partial class NuGetKeyVaultSignToolSettings : ToolSettings +{ + /// + /// Path to the NuGetKeyVaultSignTool executable. + /// + public override string ProcessToolPath => base.ProcessToolPath ?? NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPath; + /// + /// ProcessLogger + /// + public override Action ProcessLogger => base.ProcessLogger ?? NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolLogger; + /// + /// ProcessExitHandler + /// + public override Action ProcessExitHandler => base.ProcessExitHandler ?? NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolExitHandler; + /// + /// Package to sign. + /// + public virtual string File { get; internal set; } + /// + /// A fully qualified URL of the key vault with the certificate that will be used for signing. An example value might be https://my-vault.vault.azure.net. + /// + public virtual string KeyVaultUrl { get; internal set; } + /// + /// This is the client ID used to authenticate to Azure, which will be used to generate an access token. This parameter is not required if an access token is supplied directly with the --azure-key-vault-accesstoken option. If this parameter is supplied, --azure-key-vault-client-secret and --azure-key-vault-tenant-id must be supplied as well. + /// + public virtual string KeyVaultClientId { get; internal set; } + /// + /// This is the client secret used to authenticate to Azure, which will be used to generate an access token. This parameter is not required if an access token is supplied directly with the --azure-key-vault-accesstoken option or when using managed identities with --azure-key-vault-managed-identity. If this parameter is supplied, --azure-key-vault-client-id and --azure-key-vault-tenant-id must be supplied as well. + /// + public virtual string KeyVaultClientSecret { get; internal set; } + /// + /// This is the tenant id used to authenticate to Azure, which will be used to generate an access token. This parameter is not required if an access token is supplied directly with the --azure-key-vault-accesstoken option or when using managed identities with --azure-key-vault-managed-identity. If this parameter is supplied, --azure-key-vault-client-id and --azure-key-vault-client-secret must be supplied as well. + /// + public virtual string KeyVaultTenantId { get; internal set; } + /// + /// The name of the certificate used to perform the signing operation. + /// + public virtual string KeyVaultCertificateName { get; internal set; } + /// + /// An access token used to authenticate to Azure. This can be used instead of the --azure-key-vault-managed-identity, --azure-key-vault-client-id and --azure-key-vault-client-secret options. This is useful if NuGetKeyVaultSignTool is being used as part of another program that is already authenticated and has an access token to Azure. + /// + public virtual string KeyVaultAccessToken { get; internal set; } + /// + /// Use the ambient Managed Identity to authenticate to Azure. This can be used instead of the --azure-key-vault-accesstoken, --azure-key-vault-client-id and --azure-key-vault-client-secret options. This is useful if NuGetKeyVaultSignTool is being used on a VM/service/CLI that is configured for managed identities to Azure. + /// + public virtual bool? KeyVaultManagedIdentity { get; internal set; } + /// + /// A URL to an RFC3161 compliant timestamping service. This parameter serves the same purpose as the /tr option in the Windows SDK signtool. This parameter should be used in favor of the --timestamp option. Using this parameter will allow using modern, RFC3161 timestamps which also support timestamp digest algorithms other than SHA1. + /// + public virtual string TimestampRfc3161Url { get; internal set; } + /// + /// The name of the digest algorithm used for timestamping. This parameter is ignored unless the --timestamp-rfc3161 parameter is also supplied. The default value is sha256. + /// + public virtual NuGetKeyVaultSignToolDigestAlgorithm TimestampDigest { get; internal set; } + /// + /// The name of the digest algorithm used for hashing the file being signed. The default value is sha256. + /// + public virtual NuGetKeyVaultSignToolDigestAlgorithm FileDigest { get; internal set; } + /// + /// Overwrites a signature if it exists. + /// + public virtual bool? Force { get; internal set; } + /// + /// The output file. If omitted, overwrites input. + /// + public virtual string Output { get; internal set; } + /// + /// ConfigureProcessArguments + /// + /// + /// + protected override Arguments ConfigureProcessArguments(Arguments arguments) + { + arguments + .Add("sign") + .Add("{value}", File) + .Add("--azure-key-vault-url {value}", KeyVaultUrl) + .Add("--azure-key-vault-client-id {value}", KeyVaultClientId) + .Add("--azure-key-vault-client-secret {value}", KeyVaultClientSecret, secret: true) + .Add("--azure-key-vault-tenant-id {value}", KeyVaultTenantId) + .Add("--azure-key-vault-certificate {value}", KeyVaultCertificateName) + .Add("--azure-key-vault-accesstoken {value}", KeyVaultAccessToken, secret: true) + .Add("--azure-key-vault-managed-identity", KeyVaultManagedIdentity) + .Add("--timestamp-rfc3161 {value}", TimestampRfc3161Url) + .Add("--timestamp-digest {value}", TimestampDigest) + .Add("--file-digest {value}", FileDigest) + .Add("--force", Force) + .Add("--output {value}", Output); + return base.ConfigureProcessArguments(arguments); + } +} +#endregion +#region NuGetKeyVaultSignToolSettingsExtensions +/// +/// Used within . +/// +[PublicAPI] +[ExcludeFromCodeCoverage] +public static partial class NuGetKeyVaultSignToolSettingsExtensions +{ + #region File + /// + ///

Sets

+ ///

Package to sign.

+ ///
+ [Pure] + public static T SetFile(this T toolSettings, string file) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.File = file; + return toolSettings; + } + /// + ///

Resets

+ ///

Package to sign.

+ ///
+ [Pure] + public static T ResetFile(this T toolSettings) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.File = null; + return toolSettings; + } + #endregion + #region KeyVaultUrl + /// + ///

Sets

+ ///

A fully qualified URL of the key vault with the certificate that will be used for signing. An example value might be https://my-vault.vault.azure.net.

+ ///
+ [Pure] + public static T SetKeyVaultUrl(this T toolSettings, string keyVaultUrl) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.KeyVaultUrl = keyVaultUrl; + return toolSettings; + } + /// + ///

Resets

+ ///

A fully qualified URL of the key vault with the certificate that will be used for signing. An example value might be https://my-vault.vault.azure.net.

+ ///
+ [Pure] + public static T ResetKeyVaultUrl(this T toolSettings) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.KeyVaultUrl = null; + return toolSettings; + } + #endregion + #region KeyVaultClientId + /// + ///

Sets

+ ///

This is the client ID used to authenticate to Azure, which will be used to generate an access token. This parameter is not required if an access token is supplied directly with the --azure-key-vault-accesstoken option. If this parameter is supplied, --azure-key-vault-client-secret and --azure-key-vault-tenant-id must be supplied as well.

+ ///
+ [Pure] + public static T SetKeyVaultClientId(this T toolSettings, string keyVaultClientId) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.KeyVaultClientId = keyVaultClientId; + return toolSettings; + } + /// + ///

Resets

+ ///

This is the client ID used to authenticate to Azure, which will be used to generate an access token. This parameter is not required if an access token is supplied directly with the --azure-key-vault-accesstoken option. If this parameter is supplied, --azure-key-vault-client-secret and --azure-key-vault-tenant-id must be supplied as well.

+ ///
+ [Pure] + public static T ResetKeyVaultClientId(this T toolSettings) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.KeyVaultClientId = null; + return toolSettings; + } + #endregion + #region KeyVaultClientSecret + /// + ///

Sets

+ ///

This is the client secret used to authenticate to Azure, which will be used to generate an access token. This parameter is not required if an access token is supplied directly with the --azure-key-vault-accesstoken option or when using managed identities with --azure-key-vault-managed-identity. If this parameter is supplied, --azure-key-vault-client-id and --azure-key-vault-tenant-id must be supplied as well.

+ ///
+ [Pure] + public static T SetKeyVaultClientSecret(this T toolSettings, [Secret] string keyVaultClientSecret) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.KeyVaultClientSecret = keyVaultClientSecret; + return toolSettings; + } + /// + ///

Resets

+ ///

This is the client secret used to authenticate to Azure, which will be used to generate an access token. This parameter is not required if an access token is supplied directly with the --azure-key-vault-accesstoken option or when using managed identities with --azure-key-vault-managed-identity. If this parameter is supplied, --azure-key-vault-client-id and --azure-key-vault-tenant-id must be supplied as well.

+ ///
+ [Pure] + public static T ResetKeyVaultClientSecret(this T toolSettings) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.KeyVaultClientSecret = null; + return toolSettings; + } + #endregion + #region KeyVaultTenantId + /// + ///

Sets

+ ///

This is the tenant id used to authenticate to Azure, which will be used to generate an access token. This parameter is not required if an access token is supplied directly with the --azure-key-vault-accesstoken option or when using managed identities with --azure-key-vault-managed-identity. If this parameter is supplied, --azure-key-vault-client-id and --azure-key-vault-client-secret must be supplied as well.

+ ///
+ [Pure] + public static T SetKeyVaultTenantId(this T toolSettings, string keyVaultTenantId) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.KeyVaultTenantId = keyVaultTenantId; + return toolSettings; + } + /// + ///

Resets

+ ///

This is the tenant id used to authenticate to Azure, which will be used to generate an access token. This parameter is not required if an access token is supplied directly with the --azure-key-vault-accesstoken option or when using managed identities with --azure-key-vault-managed-identity. If this parameter is supplied, --azure-key-vault-client-id and --azure-key-vault-client-secret must be supplied as well.

+ ///
+ [Pure] + public static T ResetKeyVaultTenantId(this T toolSettings) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.KeyVaultTenantId = null; + return toolSettings; + } + #endregion + #region KeyVaultCertificateName + /// + ///

Sets

+ ///

The name of the certificate used to perform the signing operation.

+ ///
+ [Pure] + public static T SetKeyVaultCertificateName(this T toolSettings, string keyVaultCertificateName) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.KeyVaultCertificateName = keyVaultCertificateName; + return toolSettings; + } + /// + ///

Resets

+ ///

The name of the certificate used to perform the signing operation.

+ ///
+ [Pure] + public static T ResetKeyVaultCertificateName(this T toolSettings) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.KeyVaultCertificateName = null; + return toolSettings; + } + #endregion + #region KeyVaultAccessToken + /// + ///

Sets

+ ///

An access token used to authenticate to Azure. This can be used instead of the --azure-key-vault-managed-identity, --azure-key-vault-client-id and --azure-key-vault-client-secret options. This is useful if NuGetKeyVaultSignTool is being used as part of another program that is already authenticated and has an access token to Azure.

+ ///
+ [Pure] + public static T SetKeyVaultAccessToken(this T toolSettings, [Secret] string keyVaultAccessToken) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.KeyVaultAccessToken = keyVaultAccessToken; + return toolSettings; + } + /// + ///

Resets

+ ///

An access token used to authenticate to Azure. This can be used instead of the --azure-key-vault-managed-identity, --azure-key-vault-client-id and --azure-key-vault-client-secret options. This is useful if NuGetKeyVaultSignTool is being used as part of another program that is already authenticated and has an access token to Azure.

+ ///
+ [Pure] + public static T ResetKeyVaultAccessToken(this T toolSettings) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.KeyVaultAccessToken = null; + return toolSettings; + } + #endregion + #region KeyVaultManagedIdentity + /// + ///

Sets

+ ///

Use the ambient Managed Identity to authenticate to Azure. This can be used instead of the --azure-key-vault-accesstoken, --azure-key-vault-client-id and --azure-key-vault-client-secret options. This is useful if NuGetKeyVaultSignTool is being used on a VM/service/CLI that is configured for managed identities to Azure.

+ ///
+ [Pure] + public static T SetKeyVaultManagedIdentity(this T toolSettings, bool? keyVaultManagedIdentity) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.KeyVaultManagedIdentity = keyVaultManagedIdentity; + return toolSettings; + } + /// + ///

Resets

+ ///

Use the ambient Managed Identity to authenticate to Azure. This can be used instead of the --azure-key-vault-accesstoken, --azure-key-vault-client-id and --azure-key-vault-client-secret options. This is useful if NuGetKeyVaultSignTool is being used on a VM/service/CLI that is configured for managed identities to Azure.

+ ///
+ [Pure] + public static T ResetKeyVaultManagedIdentity(this T toolSettings) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.KeyVaultManagedIdentity = null; + return toolSettings; + } + /// + ///

Enables

+ ///

Use the ambient Managed Identity to authenticate to Azure. This can be used instead of the --azure-key-vault-accesstoken, --azure-key-vault-client-id and --azure-key-vault-client-secret options. This is useful if NuGetKeyVaultSignTool is being used on a VM/service/CLI that is configured for managed identities to Azure.

+ ///
+ [Pure] + public static T EnableKeyVaultManagedIdentity(this T toolSettings) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.KeyVaultManagedIdentity = true; + return toolSettings; + } + /// + ///

Disables

+ ///

Use the ambient Managed Identity to authenticate to Azure. This can be used instead of the --azure-key-vault-accesstoken, --azure-key-vault-client-id and --azure-key-vault-client-secret options. This is useful if NuGetKeyVaultSignTool is being used on a VM/service/CLI that is configured for managed identities to Azure.

+ ///
+ [Pure] + public static T DisableKeyVaultManagedIdentity(this T toolSettings) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.KeyVaultManagedIdentity = false; + return toolSettings; + } + /// + ///

Toggles

+ ///

Use the ambient Managed Identity to authenticate to Azure. This can be used instead of the --azure-key-vault-accesstoken, --azure-key-vault-client-id and --azure-key-vault-client-secret options. This is useful if NuGetKeyVaultSignTool is being used on a VM/service/CLI that is configured for managed identities to Azure.

+ ///
+ [Pure] + public static T ToggleKeyVaultManagedIdentity(this T toolSettings) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.KeyVaultManagedIdentity = !toolSettings.KeyVaultManagedIdentity; + return toolSettings; + } + #endregion + #region TimestampRfc3161Url + /// + ///

Sets

+ ///

A URL to an RFC3161 compliant timestamping service. This parameter serves the same purpose as the /tr option in the Windows SDK signtool. This parameter should be used in favor of the --timestamp option. Using this parameter will allow using modern, RFC3161 timestamps which also support timestamp digest algorithms other than SHA1.

+ ///
+ [Pure] + public static T SetTimestampRfc3161Url(this T toolSettings, string timestampRfc3161Url) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.TimestampRfc3161Url = timestampRfc3161Url; + return toolSettings; + } + /// + ///

Resets

+ ///

A URL to an RFC3161 compliant timestamping service. This parameter serves the same purpose as the /tr option in the Windows SDK signtool. This parameter should be used in favor of the --timestamp option. Using this parameter will allow using modern, RFC3161 timestamps which also support timestamp digest algorithms other than SHA1.

+ ///
+ [Pure] + public static T ResetTimestampRfc3161Url(this T toolSettings) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.TimestampRfc3161Url = null; + return toolSettings; + } + #endregion + #region TimestampDigest + /// + ///

Sets

+ ///

The name of the digest algorithm used for timestamping. This parameter is ignored unless the --timestamp-rfc3161 parameter is also supplied. The default value is sha256.

+ ///
+ [Pure] + public static T SetTimestampDigest(this T toolSettings, NuGetKeyVaultSignToolDigestAlgorithm timestampDigest) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.TimestampDigest = timestampDigest; + return toolSettings; + } + /// + ///

Resets

+ ///

The name of the digest algorithm used for timestamping. This parameter is ignored unless the --timestamp-rfc3161 parameter is also supplied. The default value is sha256.

+ ///
+ [Pure] + public static T ResetTimestampDigest(this T toolSettings) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.TimestampDigest = null; + return toolSettings; + } + #endregion + #region FileDigest + /// + ///

Sets

+ ///

The name of the digest algorithm used for hashing the file being signed. The default value is sha256.

+ ///
+ [Pure] + public static T SetFileDigest(this T toolSettings, NuGetKeyVaultSignToolDigestAlgorithm fileDigest) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.FileDigest = fileDigest; + return toolSettings; + } + /// + ///

Resets

+ ///

The name of the digest algorithm used for hashing the file being signed. The default value is sha256.

+ ///
+ [Pure] + public static T ResetFileDigest(this T toolSettings) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.FileDigest = null; + return toolSettings; + } + #endregion + #region Force + /// + ///

Sets

+ ///

Overwrites a signature if it exists.

+ ///
+ [Pure] + public static T SetForce(this T toolSettings, bool? force) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.Force = force; + return toolSettings; + } + /// + ///

Resets

+ ///

Overwrites a signature if it exists.

+ ///
+ [Pure] + public static T ResetForce(this T toolSettings) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.Force = null; + return toolSettings; + } + /// + ///

Enables

+ ///

Overwrites a signature if it exists.

+ ///
+ [Pure] + public static T EnableForce(this T toolSettings) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.Force = true; + return toolSettings; + } + /// + ///

Disables

+ ///

Overwrites a signature if it exists.

+ ///
+ [Pure] + public static T DisableForce(this T toolSettings) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.Force = false; + return toolSettings; + } + /// + ///

Toggles

+ ///

Overwrites a signature if it exists.

+ ///
+ [Pure] + public static T ToggleForce(this T toolSettings) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.Force = !toolSettings.Force; + return toolSettings; + } + #endregion + #region Output + /// + ///

Sets

+ ///

The output file. If omitted, overwrites input.

+ ///
+ [Pure] + public static T SetOutput(this T toolSettings, string output) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.Output = output; + return toolSettings; + } + /// + ///

Resets

+ ///

The output file. If omitted, overwrites input.

+ ///
+ [Pure] + public static T ResetOutput(this T toolSettings) where T : NuGetKeyVaultSignToolSettings + { + toolSettings = toolSettings.NewInstance(); + toolSettings.Output = null; + return toolSettings; + } + #endregion +} +#endregion +#region NuGetKeyVaultSignToolDigestAlgorithm +/// +/// Used within . +/// +[PublicAPI] +[Serializable] +[ExcludeFromCodeCoverage] +[TypeConverter(typeof(TypeConverter))] +public partial class NuGetKeyVaultSignToolDigestAlgorithm : Enumeration +{ + /// + /// sha1 + /// + public static NuGetKeyVaultSignToolDigestAlgorithm sha1 = (NuGetKeyVaultSignToolDigestAlgorithm) "sha1"; + /// + /// sha256 + /// + public static NuGetKeyVaultSignToolDigestAlgorithm sha256 = (NuGetKeyVaultSignToolDigestAlgorithm) "sha256"; + /// + /// sha512 + /// + public static NuGetKeyVaultSignToolDigestAlgorithm sha384 = (NuGetKeyVaultSignToolDigestAlgorithm) "sha384"; + /// + /// sha512 + /// + public static NuGetKeyVaultSignToolDigestAlgorithm sha512 = (NuGetKeyVaultSignToolDigestAlgorithm) "sha512"; + /// + /// NuGetKeyVaultSignToolDigestAlgorithm + /// + /// + public static implicit operator NuGetKeyVaultSignToolDigestAlgorithm(string value) + { + return new NuGetKeyVaultSignToolDigestAlgorithm { Value = value }; + } +} +#endregion diff --git a/ricaun.Nuke/Tools/NuGetKeyVaultSignTool/NuGetKeyVaultSignTool.json b/ricaun.Nuke/Tools/NuGetKeyVaultSignTool/NuGetKeyVaultSignTool.json new file mode 100644 index 0000000..7ad5acd --- /dev/null +++ b/ricaun.Nuke/Tools/NuGetKeyVaultSignTool/NuGetKeyVaultSignTool.json @@ -0,0 +1,113 @@ +{ + "$schema": "https://raw.githubusercontent.com/nuke-build/nuke/master/source/Nuke.Tooling.Generator/schema.json", + "name": "NuGetKeyVaultSignTool", + "officialUrl": "https://github.com/novotnyllc/NuGetKeyVaultSignTool", + "help": "NuGet Key Vault Sign Tool is similar to nuget sign, with the major difference being that it uses Azure Key Vault for performing the signing process. Similar usage configuration like AzureSignTool, except is used to sign nuget package.", + "nugetPackageId": "NuGetKeyVaultSignTool", + "packageExecutable": "NuGetKeyVaultSignTool.dll", + "tasks": [ + { + "definiteArgument": "sign", + "settingsClass": { + "properties": [ + { + "name": "File", + "type": "string", + "format": "{value}", + "help": "Package to sign." + }, + { + "name": "KeyVaultUrl", + "type": "string", + "format": "--azure-key-vault-url {value}", + "secret": false, + "help": "A fully qualified URL of the key vault with the certificate that will be used for signing. An example value might be https://my-vault.vault.azure.net." + }, + { + "name": "KeyVaultClientId", + "type": "string", + "format": "--azure-key-vault-client-id {value}", + "secret": false, + "help": "This is the client ID used to authenticate to Azure, which will be used to generate an access token. This parameter is not required if an access token is supplied directly with the --azure-key-vault-accesstoken option. If this parameter is supplied, --azure-key-vault-client-secret and --azure-key-vault-tenant-id must be supplied as well." + }, + { + "name": "KeyVaultClientSecret", + "type": "string", + "format": "--azure-key-vault-client-secret {value}", + "secret": true, + "help": "This is the client secret used to authenticate to Azure, which will be used to generate an access token. This parameter is not required if an access token is supplied directly with the --azure-key-vault-accesstoken option or when using managed identities with --azure-key-vault-managed-identity. If this parameter is supplied, --azure-key-vault-client-id and --azure-key-vault-tenant-id must be supplied as well." + }, + { + "name": "KeyVaultTenantId", + "type": "string", + "format": "--azure-key-vault-tenant-id {value}", + "secret": false, + "help": "This is the tenant id used to authenticate to Azure, which will be used to generate an access token. This parameter is not required if an access token is supplied directly with the --azure-key-vault-accesstoken option or when using managed identities with --azure-key-vault-managed-identity. If this parameter is supplied, --azure-key-vault-client-id and --azure-key-vault-client-secret must be supplied as well." + }, + { + "name": "KeyVaultCertificateName", + "type": "string", + "format": "--azure-key-vault-certificate {value}", + "secret": false, + "help": "The name of the certificate used to perform the signing operation." + }, + { + "name": "KeyVaultAccessToken", + "type": "string", + "format": "--azure-key-vault-accesstoken {value}", + "secret": true, + "help": "An access token used to authenticate to Azure. This can be used instead of the --azure-key-vault-managed-identity, --azure-key-vault-client-id and --azure-key-vault-client-secret options. This is useful if NuGetKeyVaultSignTool is being used as part of another program that is already authenticated and has an access token to Azure." + }, + { + "name": "KeyVaultManagedIdentity", + "type": "bool", + "format": "--azure-key-vault-managed-identity", + "secret": false, + "help": "Use the ambient Managed Identity to authenticate to Azure. This can be used instead of the --azure-key-vault-accesstoken, --azure-key-vault-client-id and --azure-key-vault-client-secret options. This is useful if NuGetKeyVaultSignTool is being used on a VM/service/CLI that is configured for managed identities to Azure." + }, + { + "name": "TimestampRfc3161Url", + "type": "string", + "format": "--timestamp-rfc3161 {value}", + "help": "A URL to an RFC3161 compliant timestamping service. This parameter serves the same purpose as the /tr option in the Windows SDK signtool. This parameter should be used in favor of the --timestamp option. Using this parameter will allow using modern, RFC3161 timestamps which also support timestamp digest algorithms other than SHA1." + }, + { + "name": "TimestampDigest", + "type": "NuGetKeyVaultSignToolDigestAlgorithm", + "format": "--timestamp-digest {value}", + "help": "The name of the digest algorithm used for timestamping. This parameter is ignored unless the --timestamp-rfc3161 parameter is also supplied. The default value is sha256." + }, + { + "name": "FileDigest", + "type": "NuGetKeyVaultSignToolDigestAlgorithm", + "format": "--file-digest {value}", + "help": "The name of the digest algorithm used for hashing the file being signed. The default value is sha256." + }, + { + "name": "Force", + "type": "bool", + "format": "--force", + "help": "Overwrites a signature if it exists." + }, + { + "name": "Output", + "type": "string", + "format": "--output {value}", + "help": "The output file. If omitted, overwrites input." + } + ] + } + } + ], + "enumerations": [ + { + "name": "NuGetKeyVaultSignToolDigestAlgorithm", + "values": [ + "sha1", + "sha256", + "sha384", + "sha512" + ] + } + ] +} diff --git a/ricaun.Nuke/build/ricaun.Nuke.targets b/ricaun.Nuke/build/ricaun.Nuke.targets new file mode 100644 index 0000000..7a10e93 --- /dev/null +++ b/ricaun.Nuke/build/ricaun.Nuke.targets @@ -0,0 +1,15 @@ + + + + + + + + + + + + $(NoWarn);NU1505 + + + \ No newline at end of file diff --git a/ricaun.Nuke/ricaun.Nuke.csproj b/ricaun.Nuke/ricaun.Nuke.csproj index 479f81d..305ba02 100644 --- a/ricaun.Nuke/ricaun.Nuke.csproj +++ b/ricaun.Nuke/ricaun.Nuke.csproj @@ -3,11 +3,12 @@ net6.0 false + Latest ricaun.Nuke - 1.8.2 + 1.9.0-alpha @@ -76,4 +77,9 @@ + + + + + From 7e3e7583a1d79a0a731ad3870e26ef7ac876a743 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Fri, 6 Dec 2024 12:10:33 -0300 Subject: [PATCH 02/44] Update `Tests` --- CHANGELOG.md | 3 + ricaun.Nuke.Tests/AzureKeyVaultConfigTests.cs | 56 +++++++++++++++++++ .../{TestsNet.cs => NuGetExtensionTests.cs} | 6 +- ricaun.Nuke.Tests/ricaun.Nuke.Tests.csproj | 4 +- 4 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 ricaun.Nuke.Tests/AzureKeyVaultConfigTests.cs rename ricaun.Nuke.Tests/{TestsNet.cs => NuGetExtensionTests.cs} (90%) diff --git a/CHANGELOG.md b/CHANGELOG.md index db04867..65ac584 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Add `NuGetKeyVaultSignTool` for nuke version `8.*`. - Add `AzureKeyVaultConfig` with json file with `Azure Key Vault` without secrets. - Add `build` with `.targets` to install packages `AzureSignTool` and `NuGetKeyVaultSignTool`. +### Tests +- Update `NuGetExtensionTests` +- Add `AzureKeyVaultConfigTests` ## [1.8.2] / 2024-11-20 ### Updates diff --git a/ricaun.Nuke.Tests/AzureKeyVaultConfigTests.cs b/ricaun.Nuke.Tests/AzureKeyVaultConfigTests.cs new file mode 100644 index 0000000..fef486b --- /dev/null +++ b/ricaun.Nuke.Tests/AzureKeyVaultConfigTests.cs @@ -0,0 +1,56 @@ +using NUnit.Framework; +using ricaun.Nuke.Tools; + +namespace Nuke.NuGetKeyVaultSignTool +{ + public class AzureKeyVaultConfigTests + { + [Test] + public void JsonIsNotValidTest() + { + var content = """ + { + "AzureKeyVaultCertificate": "", + "AzureKeyVaultUrl": "", + "AzureKeyVaultClientId": "", + "AzureKeyVaultTenantId": "" + } + """; + + var azureKeyVaultFile = AzureKeyVaultConfig.Create(content); + Assert.IsNotNull(azureKeyVaultFile); + Assert.IsFalse(azureKeyVaultFile.IsValid()); + } + + [Test] + public void JsonIsNullTest() + { + var content = ""; + + var azureKeyVaultFile = AzureKeyVaultConfig.Create(content); + Assert.IsNull(azureKeyVaultFile); + } + + [Test] + public void JsonIsValidTest() + { + var content = """ + { + "AzureKeyVaultCertificate": "AzureKeyVaultCertificate", + "AzureKeyVaultUrl": "AzureKeyVaultUrl", + "AzureKeyVaultClientId": "AzureKeyVaultClientId", + "AzureKeyVaultTenantId": "AzureKeyVaultTenantId" + } + """; + + var azureKeyVaultFile = AzureKeyVaultConfig.Create(content); + Assert.IsNotNull(azureKeyVaultFile); + Assert.IsTrue(azureKeyVaultFile.IsValid()); + Assert.AreEqual("AzureKeyVaultCertificate", azureKeyVaultFile.AzureKeyVaultCertificate); + Assert.AreEqual("AzureKeyVaultUrl", azureKeyVaultFile.AzureKeyVaultUrl); + Assert.AreEqual("AzureKeyVaultClientId", azureKeyVaultFile.AzureKeyVaultClientId); + Assert.AreEqual("AzureKeyVaultTenantId", azureKeyVaultFile.AzureKeyVaultTenantId); + } + } + +} \ No newline at end of file diff --git a/ricaun.Nuke.Tests/TestsNet.cs b/ricaun.Nuke.Tests/NuGetExtensionTests.cs similarity index 90% rename from ricaun.Nuke.Tests/TestsNet.cs rename to ricaun.Nuke.Tests/NuGetExtensionTests.cs index 699414c..f50c629 100644 --- a/ricaun.Nuke.Tests/TestsNet.cs +++ b/ricaun.Nuke.Tests/NuGetExtensionTests.cs @@ -2,11 +2,10 @@ namespace ricaun.Nuke.Tests { -#if NET - public class TestsNet + public class NuGetExtensionTests { [Test] - public void Test1() + public void Test_PackageNameAndVersion() { var packages = new[] { "ricaun.example.1.2.3.nupkg", @@ -26,5 +25,4 @@ public void Test1() } } } -#endif } \ No newline at end of file diff --git a/ricaun.Nuke.Tests/ricaun.Nuke.Tests.csproj b/ricaun.Nuke.Tests/ricaun.Nuke.Tests.csproj index 5c61cf9..7472eba 100644 --- a/ricaun.Nuke.Tests/ricaun.Nuke.Tests.csproj +++ b/ricaun.Nuke.Tests/ricaun.Nuke.Tests.csproj @@ -1,7 +1,7 @@  - net6;net45 + net6 Latest false @@ -12,7 +12,7 @@ - + From cef6ce4999e5d4649bf9fe7bc2fa839d1871bb4b Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Fri, 6 Dec 2024 12:52:34 -0300 Subject: [PATCH 03/44] Change `Tools` namespace --- ricaun.Nuke/Tools/AzureSignToolUtils.cs | 2 +- .../NuGetKeyVaultSignTool/NuGetKeyVaultSignTool.Generated.cs | 2 +- ricaun.Nuke/ricaun.Nuke.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ricaun.Nuke/Tools/AzureSignToolUtils.cs b/ricaun.Nuke/Tools/AzureSignToolUtils.cs index bdcf46c..5e4dc22 100644 --- a/ricaun.Nuke/Tools/AzureSignToolUtils.cs +++ b/ricaun.Nuke/Tools/AzureSignToolUtils.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using Nuke.Common.Tools.NuGetKeyVaultSignTool; +using ricaun.Nuke.Tools.NuGetKeyVaultSignTool; using Nuke.Common.Tools.AzureSignTool; using System.IO; diff --git a/ricaun.Nuke/Tools/NuGetKeyVaultSignTool/NuGetKeyVaultSignTool.Generated.cs b/ricaun.Nuke/Tools/NuGetKeyVaultSignTool/NuGetKeyVaultSignTool.Generated.cs index b6652a7..5606c6f 100644 --- a/ricaun.Nuke/Tools/NuGetKeyVaultSignTool/NuGetKeyVaultSignTool.Generated.cs +++ b/ricaun.Nuke/Tools/NuGetKeyVaultSignTool/NuGetKeyVaultSignTool.Generated.cs @@ -14,7 +14,7 @@ using System.Linq; using System.Text; -namespace Nuke.Common.Tools.NuGetKeyVaultSignTool; +namespace ricaun.Nuke.Tools.NuGetKeyVaultSignTool; /// ///

NuGet Key Vault Sign Tool is similar to nuget sign, with the major difference being that it uses Azure Key Vault for performing the signing process. Similar usage configuration like AzureSignTool, except is used to sign nuget package.

diff --git a/ricaun.Nuke/ricaun.Nuke.csproj b/ricaun.Nuke/ricaun.Nuke.csproj index 305ba02..28dabdf 100644 --- a/ricaun.Nuke/ricaun.Nuke.csproj +++ b/ricaun.Nuke/ricaun.Nuke.csproj @@ -8,7 +8,7 @@ ricaun.Nuke - 1.9.0-alpha + 1.9.0-alpha.1 From 281e1a7559daa7053a07a86ed61fba07682b7890 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Fri, 6 Dec 2024 16:52:33 -0300 Subject: [PATCH 04/44] Add `PackageDownload` to download tools on the fly. --- Build/Build.csproj | 2 +- Build/IAzureSignTool.cs | 3 + CHANGELOG.md | 5 +- ricaun.Nuke/Tools/AzureSignToolUtils.cs | 94 +++++++++++++++++++++++++ ricaun.Nuke/ricaun.Nuke.csproj | 5 +- 5 files changed, 103 insertions(+), 6 deletions(-) diff --git a/Build/Build.csproj b/Build/Build.csproj index fd86e57..16ed451 100644 --- a/Build/Build.csproj +++ b/Build/Build.csproj @@ -19,6 +19,6 @@ - + diff --git a/Build/IAzureSignTool.cs b/Build/IAzureSignTool.cs index 31688b5..4f07aea 100644 --- a/Build/IAzureSignTool.cs +++ b/Build/IAzureSignTool.cs @@ -8,6 +8,9 @@ public interface IAzureSignTool : IClean, ICompile .Before(Compile) .Executes(() => { + ricaun.Nuke.Tools.AzureSignToolUtils.DownloadAzureSignTool(); + ricaun.Nuke.Tools.AzureSignToolUtils.DownloadNuGetKeyVaultSignTool(); + ricaun.Nuke.Tools.AzureSignToolUtils.EnsureAzureToolIsInstalled(); }); } diff --git a/CHANGELOG.md b/CHANGELOG.md index 65ac584..3283d4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,12 +9,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Enable sign files using `Azure Key Vault`. ### Build - Add `IAzureSignTool` to check if `AzureSignToolUtils` is installed. -- Add import `build` with `.targets` +- [ ] Add import `build` with `.targets` ### Updates - Add `AzureSignToolUtils` to sign files using `AzureSignToolTasks` or `NuGetKeyVaultSignToolTasks`. - Add `NuGetKeyVaultSignTool` for nuke version `8.*`. - Add `AzureKeyVaultConfig` with json file with `Azure Key Vault` without secrets. -- Add `build` with `.targets` to install packages `AzureSignTool` and `NuGetKeyVaultSignTool`. +- [ ] Add `build` with `.targets` to install packages `AzureSignTool` and `NuGetKeyVaultSignTool`. +- Add `PackageDownload` to download `AzureSignTool` and `NuGetKeyVaultSignTool` on the fly. ### Tests - Update `NuGetExtensionTests` - Add `AzureKeyVaultConfigTests` diff --git a/ricaun.Nuke/Tools/AzureSignToolUtils.cs b/ricaun.Nuke/Tools/AzureSignToolUtils.cs index 5e4dc22..f93098e 100644 --- a/ricaun.Nuke/Tools/AzureSignToolUtils.cs +++ b/ricaun.Nuke/Tools/AzureSignToolUtils.cs @@ -6,6 +6,8 @@ using ricaun.Nuke.Tools.NuGetKeyVaultSignTool; using Nuke.Common.Tools.AzureSignTool; using System.IO; +using Nuke.Common.Tools.DotNet; +using Nuke.Common.IO; namespace ricaun.Nuke.Tools { @@ -24,6 +26,9 @@ public class AzureSignToolUtils /// Thrown when the required packages are missing. public static void EnsureAzureToolIsInstalled() { + DownloadAzureSignTool(); + DownloadNuGetKeyVaultSignTool(); + try { _ = AzureSignToolTasks.AzureSignToolPath; @@ -41,6 +46,93 @@ public static void EnsureAzureToolIsInstalled() } } + private static AbsolutePath GetToolInstallationPath() + { + AbsolutePath folder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); + return folder / "Tools"; + } + + private static string PackageDownload(string packageId) + { + var toolFolder = GetToolInstallationPath(); + + DotNetTasks.DotNetToolInstall(x => x + .SetPackageName(packageId) + .SetToolInstallationPath(toolFolder) + ); + + if (Globbing.GlobFiles(toolFolder, $"{packageId}.exe").FirstOrDefault() is AbsolutePath absolutePath) + { + return absolutePath; + } + return null; + } + + /// + /// Download AzureSignTool if not already installed. + /// + public static void DownloadAzureSignTool() + { + try + { + _ = AzureSignToolTasks.AzureSignToolPath; + } + catch (Exception) + { + var packageId = AzureSignToolTasks.AzureSignToolPackageId; + var packageToolExe = PackageDownload(packageId); + + Environment.SetEnvironmentVariable(packageId.ToUpper() + "_EXE", packageToolExe); + } + + _ = AzureSignToolTasks.AzureSignToolPath; + } + + /// + /// Download NuGetKeyVaultSignTool if not already installed. + /// + public static void DownloadNuGetKeyVaultSignTool() + { + try + { + _ = NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPath; + } + catch (Exception) + { + var packageId = NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPackageId; + var packageToolExe = PackageDownload(packageId); + + Environment.SetEnvironmentVariable(packageId.ToUpper() + "_EXE", packageToolExe); + } + + _ = NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPath; + } + + private static void DownloadNuGetKeyVaultSignTool_() + { + try + { + _ = NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPath; + } + catch (Exception) + { + var toolFolder = GetToolInstallationPath(); + var packageId = NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPackageId; + + DotNetTasks.DotNetToolInstall(x => x + .SetPackageName(packageId) + .SetToolInstallationPath(toolFolder) + ); + + if (Globbing.GlobFiles(toolFolder, $"{packageId}.exe").FirstOrDefault() is AbsolutePath packageToolPath) + { + Environment.SetEnvironmentVariable(packageId.ToUpper() + "_EXE", packageToolPath); + } + } + + _ = NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPath; + } + /// /// Signs the specified file using Azure Sign Tool or NuGet Key Vault Sign Tool. /// @@ -56,6 +148,7 @@ public static void Sign(string fileName, { if (Path.GetExtension(fileName) == NugetPackageExtension) { + DownloadNuGetKeyVaultSignTool(); NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignTool(x => x .SetFile(fileName) .SetKeyVaultCertificateName(azureKeyVaultConfig.AzureKeyVaultCertificate) @@ -69,6 +162,7 @@ public static void Sign(string fileName, return; } + DownloadAzureSignTool(); AzureSignToolTasks.AzureSignTool(x => x .SetFiles(fileName) .SetKeyVaultCertificateName(azureKeyVaultConfig.AzureKeyVaultCertificate) diff --git a/ricaun.Nuke/ricaun.Nuke.csproj b/ricaun.Nuke/ricaun.Nuke.csproj index 28dabdf..b2aef83 100644 --- a/ricaun.Nuke/ricaun.Nuke.csproj +++ b/ricaun.Nuke/ricaun.Nuke.csproj @@ -8,7 +8,7 @@ ricaun.Nuke - 1.9.0-alpha.1 + 1.9.0-alpha.2 @@ -78,8 +78,7 @@ - - + From fd3fabbc3988ddf0127bec184866423d060f5722 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Fri, 6 Dec 2024 17:12:18 -0300 Subject: [PATCH 05/44] Update PackageDownload to check if tools exists. --- ricaun.Nuke/Tools/AzureSignToolUtils.cs | 9 +++++++-- ricaun.Nuke/ricaun.Nuke.csproj | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ricaun.Nuke/Tools/AzureSignToolUtils.cs b/ricaun.Nuke/Tools/AzureSignToolUtils.cs index f93098e..d5193e5 100644 --- a/ricaun.Nuke/Tools/AzureSignToolUtils.cs +++ b/ricaun.Nuke/Tools/AzureSignToolUtils.cs @@ -56,14 +56,19 @@ private static string PackageDownload(string packageId) { var toolFolder = GetToolInstallationPath(); + if (Globbing.GlobFiles(toolFolder, $"{packageId}.exe").FirstOrDefault() is AbsolutePath packageToolExeExists) + { + return packageToolExeExists; + } + DotNetTasks.DotNetToolInstall(x => x .SetPackageName(packageId) .SetToolInstallationPath(toolFolder) ); - if (Globbing.GlobFiles(toolFolder, $"{packageId}.exe").FirstOrDefault() is AbsolutePath absolutePath) + if (Globbing.GlobFiles(toolFolder, $"{packageId}.exe").FirstOrDefault() is AbsolutePath packageToolExe) { - return absolutePath; + return packageToolExe; } return null; } diff --git a/ricaun.Nuke/ricaun.Nuke.csproj b/ricaun.Nuke/ricaun.Nuke.csproj index b2aef83..1bcb341 100644 --- a/ricaun.Nuke/ricaun.Nuke.csproj +++ b/ricaun.Nuke/ricaun.Nuke.csproj @@ -8,7 +8,7 @@ ricaun.Nuke - 1.9.0-alpha.2 + 1.9.0-alpha.3 From 4f157d29b11a3eb6de5bc39d4bd937b2854e5da1 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Fri, 6 Dec 2024 17:54:51 -0300 Subject: [PATCH 06/44] Update `PackageDownload` --- ricaun.Nuke/Tools/AzureSignToolUtils.cs | 45 ++++++++++++++----------- ricaun.Nuke/ricaun.Nuke.csproj | 2 +- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/ricaun.Nuke/Tools/AzureSignToolUtils.cs b/ricaun.Nuke/Tools/AzureSignToolUtils.cs index d5193e5..984c15f 100644 --- a/ricaun.Nuke/Tools/AzureSignToolUtils.cs +++ b/ricaun.Nuke/Tools/AzureSignToolUtils.cs @@ -113,30 +113,35 @@ public static void DownloadNuGetKeyVaultSignTool() _ = NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPath; } - private static void DownloadNuGetKeyVaultSignTool_() - { - try - { - _ = NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPath; - } - catch (Exception) - { - var toolFolder = GetToolInstallationPath(); - var packageId = NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPackageId; +private static void DownloadNuGetKeyVaultSignTool_() +{ + try + { + _ = NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPath; + } + catch (Exception) + { + var toolFolder = GetToolInstallationPath(); + var packageId = NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPackageId; - DotNetTasks.DotNetToolInstall(x => x - .SetPackageName(packageId) - .SetToolInstallationPath(toolFolder) - ); + if (Globbing.GlobFiles(toolFolder, $"{packageId}.exe").FirstOrDefault() is AbsolutePath packageToolPathExists) + { + Environment.SetEnvironmentVariable(packageId.ToUpper() + "_EXE", packageToolPathExists); + } - if (Globbing.GlobFiles(toolFolder, $"{packageId}.exe").FirstOrDefault() is AbsolutePath packageToolPath) - { - Environment.SetEnvironmentVariable(packageId.ToUpper() + "_EXE", packageToolPath); - } - } + DotNetTasks.DotNetToolInstall(x => x + .SetPackageName(packageId) + .SetToolInstallationPath(toolFolder) + ); - _ = NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPath; + if (Globbing.GlobFiles(toolFolder, $"{packageId}.exe").FirstOrDefault() is AbsolutePath packageToolPath) + { + Environment.SetEnvironmentVariable(packageId.ToUpper() + "_EXE", packageToolPath); } + } + + _ = NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPath; +} /// /// Signs the specified file using Azure Sign Tool or NuGet Key Vault Sign Tool. diff --git a/ricaun.Nuke/ricaun.Nuke.csproj b/ricaun.Nuke/ricaun.Nuke.csproj index 1bcb341..153519c 100644 --- a/ricaun.Nuke/ricaun.Nuke.csproj +++ b/ricaun.Nuke/ricaun.Nuke.csproj @@ -8,7 +8,7 @@ ricaun.Nuke - 1.9.0-alpha.3 + 1.9.0-alpha.4 From b2033b2db9e8b10118beaa2dab8eebdb50544960 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Fri, 6 Dec 2024 22:02:28 -0300 Subject: [PATCH 07/44] Force to Download Package --- Build/IAzureSignTool.cs | 3 ++ ricaun.Nuke/Tools/AzureSignToolUtils.cs | 57 +++++-------------------- ricaun.Nuke/ricaun.Nuke.csproj | 2 +- 3 files changed, 15 insertions(+), 47 deletions(-) diff --git a/Build/IAzureSignTool.cs b/Build/IAzureSignTool.cs index 4f07aea..e4d92e2 100644 --- a/Build/IAzureSignTool.cs +++ b/Build/IAzureSignTool.cs @@ -9,8 +9,11 @@ public interface IAzureSignTool : IClean, ICompile .Executes(() => { ricaun.Nuke.Tools.AzureSignToolUtils.DownloadAzureSignTool(); + Serilog.Log.Information("DownloadAzureSignTool"); ricaun.Nuke.Tools.AzureSignToolUtils.DownloadNuGetKeyVaultSignTool(); + Serilog.Log.Information("DownloadNuGetKeyVaultSignTool"); ricaun.Nuke.Tools.AzureSignToolUtils.EnsureAzureToolIsInstalled(); + Serilog.Log.Information("EnsureAzureToolIsInstalled"); }); } diff --git a/ricaun.Nuke/Tools/AzureSignToolUtils.cs b/ricaun.Nuke/Tools/AzureSignToolUtils.cs index 984c15f..8704bcc 100644 --- a/ricaun.Nuke/Tools/AzureSignToolUtils.cs +++ b/ricaun.Nuke/Tools/AzureSignToolUtils.cs @@ -8,6 +8,7 @@ using System.IO; using Nuke.Common.Tools.DotNet; using Nuke.Common.IO; +using Nuke.Common.Tooling; namespace ricaun.Nuke.Tools { @@ -78,16 +79,13 @@ private static string PackageDownload(string packageId) /// public static void DownloadAzureSignTool() { - try - { - _ = AzureSignToolTasks.AzureSignToolPath; - } - catch (Exception) + var packageId = AzureSignToolTasks.AzureSignToolPackageId; + var packageIdExe = packageId.ToUpper() + "_EXE"; + + if (ToolPathResolver.TryGetEnvironmentExecutable(packageIdExe) is null) { - var packageId = AzureSignToolTasks.AzureSignToolPackageId; var packageToolExe = PackageDownload(packageId); - - Environment.SetEnvironmentVariable(packageId.ToUpper() + "_EXE", packageToolExe); + Environment.SetEnvironmentVariable(packageIdExe, packageToolExe); } _ = AzureSignToolTasks.AzureSignToolPath; @@ -98,51 +96,18 @@ public static void DownloadAzureSignTool() ///
public static void DownloadNuGetKeyVaultSignTool() { - try - { - _ = NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPath; - } - catch (Exception) + var packageId = NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPackageId; + var packageIdExe = packageId.ToUpper() + "_EXE"; + + if (ToolPathResolver.TryGetEnvironmentExecutable(packageIdExe) is null) { - var packageId = NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPackageId; var packageToolExe = PackageDownload(packageId); - - Environment.SetEnvironmentVariable(packageId.ToUpper() + "_EXE", packageToolExe); + Environment.SetEnvironmentVariable(packageIdExe, packageToolExe); } _ = NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPath; } -private static void DownloadNuGetKeyVaultSignTool_() -{ - try - { - _ = NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPath; - } - catch (Exception) - { - var toolFolder = GetToolInstallationPath(); - var packageId = NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPackageId; - - if (Globbing.GlobFiles(toolFolder, $"{packageId}.exe").FirstOrDefault() is AbsolutePath packageToolPathExists) - { - Environment.SetEnvironmentVariable(packageId.ToUpper() + "_EXE", packageToolPathExists); - } - - DotNetTasks.DotNetToolInstall(x => x - .SetPackageName(packageId) - .SetToolInstallationPath(toolFolder) - ); - - if (Globbing.GlobFiles(toolFolder, $"{packageId}.exe").FirstOrDefault() is AbsolutePath packageToolPath) - { - Environment.SetEnvironmentVariable(packageId.ToUpper() + "_EXE", packageToolPath); - } - } - - _ = NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPath; -} - /// /// Signs the specified file using Azure Sign Tool or NuGet Key Vault Sign Tool. /// diff --git a/ricaun.Nuke/ricaun.Nuke.csproj b/ricaun.Nuke/ricaun.Nuke.csproj index 153519c..23bfd82 100644 --- a/ricaun.Nuke/ricaun.Nuke.csproj +++ b/ricaun.Nuke/ricaun.Nuke.csproj @@ -8,7 +8,7 @@ ricaun.Nuke - 1.9.0-alpha.4 + 1.9.0-alpha.5 From 6d8c490636cfb6f7d7f5a490d045fda05f94d7b1 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Tue, 10 Dec 2024 20:58:46 -0300 Subject: [PATCH 08/44] Use `Requires` --- Build/.nuke/.gitignore | 1 + Build/IAzureSignTool.cs | 23 +++++++++++++++++------ CHANGELOG.md | 3 +++ ricaun.Nuke/Components/IClean.cs | 10 ++++++++++ ricaun.Nuke/Components/ISign.cs | 4 ++++ ricaun.Nuke/ricaun.Nuke.csproj | 2 +- 6 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 Build/.nuke/.gitignore diff --git a/Build/.nuke/.gitignore b/Build/.nuke/.gitignore new file mode 100644 index 0000000..9c595a6 --- /dev/null +++ b/Build/.nuke/.gitignore @@ -0,0 +1 @@ +temp diff --git a/Build/IAzureSignTool.cs b/Build/IAzureSignTool.cs index e4d92e2..b6f3f8d 100644 --- a/Build/IAzureSignTool.cs +++ b/Build/IAzureSignTool.cs @@ -1,19 +1,30 @@ using Nuke.Common; +using Nuke.Common.Tools.AzureSignTool; +using Nuke.Common.Tools.GitVersion; +using Nuke.Common.Tools.NuGet; using ricaun.Nuke.Components; +using ricaun.Nuke.Tools.NuGetKeyVaultSignTool; public interface IAzureSignTool : IClean, ICompile { Target AzureSignTool => _ => _ .TriggeredBy(Clean) .Before(Compile) + //.Requires() + //.Requires() + .Requires() + .Requires() .Executes(() => { - ricaun.Nuke.Tools.AzureSignToolUtils.DownloadAzureSignTool(); - Serilog.Log.Information("DownloadAzureSignTool"); - ricaun.Nuke.Tools.AzureSignToolUtils.DownloadNuGetKeyVaultSignTool(); - Serilog.Log.Information("DownloadNuGetKeyVaultSignTool"); + Serilog.Log.Information(AzureSignToolTasks.AzureSignToolPath); + Serilog.Log.Information(NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPath); - ricaun.Nuke.Tools.AzureSignToolUtils.EnsureAzureToolIsInstalled(); - Serilog.Log.Information("EnsureAzureToolIsInstalled"); + //ricaun.Nuke.Tools.AzureSignToolUtils.DownloadAzureSignTool(); + //Serilog.Log.Information("DownloadAzureSignTool"); + //ricaun.Nuke.Tools.AzureSignToolUtils.DownloadNuGetKeyVaultSignTool(); + //Serilog.Log.Information("DownloadNuGetKeyVaultSignTool"); + + //ricaun.Nuke.Tools.AzureSignToolUtils.EnsureAzureToolIsInstalled(); + //Serilog.Log.Information("EnsureAzureToolIsInstalled"); }); } diff --git a/CHANGELOG.md b/CHANGELOG.md index 3283d4a..37e35fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Enable sign files using `Azure Key Vault`. ### Build - Add `IAzureSignTool` to check if `AzureSignToolUtils` is installed. +- Update `IAzureSignTool` with `Requires`. - [ ] Add import `build` with `.targets` ### Updates - Add `AzureSignToolUtils` to sign files using `AzureSignToolTasks` or `NuGetKeyVaultSignToolTasks`. @@ -16,6 +17,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Add `AzureKeyVaultConfig` with json file with `Azure Key Vault` without secrets. - [ ] Add `build` with `.targets` to install packages `AzureSignTool` and `NuGetKeyVaultSignTool`. - Add `PackageDownload` to download `AzureSignTool` and `NuGetKeyVaultSignTool` on the fly. +- Update `IClear` with `CreateTemporaryIgnore`. +- Update `ISign` with `Requires`. ### Tests - Update `NuGetExtensionTests` - Add `AzureKeyVaultConfigTests` diff --git a/ricaun.Nuke/Components/IClean.cs b/ricaun.Nuke/Components/IClean.cs index 1e4b3bd..b2028e1 100644 --- a/ricaun.Nuke/Components/IClean.cs +++ b/ricaun.Nuke/Components/IClean.cs @@ -1,4 +1,5 @@ using Nuke.Common; +using Nuke.Common.IO; using ricaun.Nuke.Extensions; namespace ricaun.Nuke.Components @@ -14,7 +15,16 @@ public interface IClean : IHazSolution, INukeBuild Target Clean => _ => _ .Executes(() => { + CreateTemporaryIgnore(); Solution.ClearSolution(BuildProjectDirectory); }); + + + private void CreateTemporaryIgnore() + { + var tempIgnore = TemporaryDirectory / ".." / ".gitignore"; + if (!tempIgnore.FileExists()) + tempIgnore.WriteAllText("temp"); + } } } diff --git a/ricaun.Nuke/Components/ISign.cs b/ricaun.Nuke/Components/ISign.cs index aa7fd31..760e7bc 100644 --- a/ricaun.Nuke/Components/ISign.cs +++ b/ricaun.Nuke/Components/ISign.cs @@ -1,8 +1,10 @@ using Nuke.Common; using Nuke.Common.IO; using Nuke.Common.ProjectModel; +using Nuke.Common.Tools.AzureSignTool; using Nuke.Common.Utilities.Collections; using ricaun.Nuke.Extensions; +using ricaun.Nuke.Tools.NuGetKeyVaultSignTool; namespace ricaun.Nuke.Components { @@ -16,6 +18,8 @@ public interface ISign : ICompile, IHazSign, IHazSolution, INukeBuild /// Target Sign => _ => _ .TriggeredBy(Compile) + .Requires() + .Requires() .Executes(() => { SignProject(MainProject); diff --git a/ricaun.Nuke/ricaun.Nuke.csproj b/ricaun.Nuke/ricaun.Nuke.csproj index 23bfd82..14913d0 100644 --- a/ricaun.Nuke/ricaun.Nuke.csproj +++ b/ricaun.Nuke/ricaun.Nuke.csproj @@ -8,7 +8,7 @@ ricaun.Nuke - 1.9.0-alpha.5 + 1.9.0-alpha.6 From 4677cbf50fa682d6ac50af4f58562715f5bb01d1 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Wed, 11 Dec 2024 20:37:54 -0300 Subject: [PATCH 09/44] Add `HttpAuthTasks` to get/post files --- CHANGELOG.md | 1 + ricaun.Nuke/IO/HttpAuthTasks.cs | 367 ++++++++++++++++++++++++++++++++ ricaun.Nuke/ricaun.Nuke.csproj | 6 +- 3 files changed, 369 insertions(+), 5 deletions(-) create mode 100644 ricaun.Nuke/IO/HttpAuthTasks.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 37e35fe..2d81c9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Add `PackageDownload` to download `AzureSignTool` and `NuGetKeyVaultSignTool` on the fly. - Update `IClear` with `CreateTemporaryIgnore`. - Update `ISign` with `Requires`. +- Add `HttpAuthTasks` to get/post files. ### Tests - Update `NuGetExtensionTests` - Add `AzureKeyVaultConfigTests` diff --git a/ricaun.Nuke/IO/HttpAuthTasks.cs b/ricaun.Nuke/IO/HttpAuthTasks.cs new file mode 100644 index 0000000..c76606a --- /dev/null +++ b/ricaun.Nuke/IO/HttpAuthTasks.cs @@ -0,0 +1,367 @@ +using Nuke.Common; +using Nuke.Common.IO; +using Nuke.Common.Tooling; +using System; +using System.Collections.Generic; +using System.IO; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading.Tasks; + +namespace ricaun.Nuke.IO; + +public static class HttpAuthTasks +{ + #region HttpPost + public static async Task HttpPostFileAsync( + string uri, + string filePath, + string authorization = null, + Dictionary formData = null, + string fileStreamContentName = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + var content = CreateFormDataContent(filePath, formData, fileStreamContentName); + return await HttpPostAsync(uri, content, authorization, clientConfigurator, headerConfigurator); + } + + public static string HttpPostFile( + string uri, + string filePath, + string authorization = null, + Dictionary formData = null, + string fileStreamContentName = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + return HttpPostFileAsync(uri, filePath, authorization, formData, fileStreamContentName, clientConfigurator, headerConfigurator).GetAwaiter().GetResult(); + } + + public static async Task HttpPostAsync( + string uri, + object content, + string authorization = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + return await HttpPostAsync(uri, JsonHttpContent(content), authorization, clientConfigurator, headerConfigurator); + } + + public static string HttpPost( + string uri, + object content, + string authorization = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + return HttpPostAsync(uri, content, authorization, clientConfigurator, headerConfigurator).GetAwaiter().GetResult(); + } + + public static async Task HttpPostAsync( + string uri, + HttpContent httpContent = null, + string authorization = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + var httpClient = CreateHttpClient(authorization, clientConfigurator, headerConfigurator); + return await httpClient.PostAsync(uri, httpContent).Result.Content.ReadAsStringAsync(); + } + public static string HttpPost( + string uri, + HttpContent httpContent = null, + string authorization = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + return HttpPostAsync(uri, httpContent, authorization, clientConfigurator, headerConfigurator).GetAwaiter().GetResult(); + } + #endregion + + #region HttpPut + public static async Task HttpPutFileAsync( + string uri, + string filePath, + string authorization = null, + Dictionary formData = null, + string fileStreamContentName = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + var content = CreateFormDataContent(filePath, formData, fileStreamContentName); + return await HttpPostAsync(uri, content, authorization, clientConfigurator, headerConfigurator); + } + + public static string HttpPutFile( + string uri, + string filePath, + string authorization = null, + Dictionary formData = null, + string fileStreamContentName = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + return HttpPutFileAsync(uri, filePath, authorization, formData, fileStreamContentName, clientConfigurator, headerConfigurator).GetAwaiter().GetResult(); + } + + public static async Task HttpPutAsync( + string uri, + object content, + string authorization = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + return await HttpPutAsync(uri, JsonHttpContent(content), authorization, clientConfigurator, headerConfigurator); + } + + public static string HttpPut( + string uri, + object content, + string authorization = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + return HttpPutAsync(uri, content, authorization, clientConfigurator, headerConfigurator).GetAwaiter().GetResult(); + } + public static async Task HttpPutAsync( + string uri, + HttpContent httpContent = null, + string authorization = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + var httpClient = CreateHttpClient(authorization, clientConfigurator, headerConfigurator); + return await httpClient.PutAsync(uri, httpContent).Result.Content.ReadAsStringAsync(); + } + public static string HttpPut( + string uri, + HttpContent httpContent = null, + string authorization = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + return HttpPutAsync(uri, httpContent, authorization, clientConfigurator, headerConfigurator).GetAwaiter().GetResult(); + } + #endregion + + #region HttpPatch + public static async Task HttpPatchFileAsync( + string uri, + string filePath, + string authorization = null, + Dictionary formData = null, + string fileStreamContentName = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + var content = CreateFormDataContent(filePath, formData, fileStreamContentName); + return await HttpPostAsync(uri, content, authorization, clientConfigurator, headerConfigurator); + } + + public static string HttpPatchFile( + string uri, + string filePath, + string authorization = null, + Dictionary formData = null, + string fileStreamContentName = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + return HttpPatchFileAsync(uri, filePath, authorization, formData, fileStreamContentName, clientConfigurator, headerConfigurator).GetAwaiter().GetResult(); + } + + public static async Task HttpPatchAsync( + string uri, + object content, + string authorization = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + return await HttpPatchAsync(uri, JsonHttpContent(content), authorization, clientConfigurator, headerConfigurator); + } + + public static string HttpPatch( + string uri, + object content, + string authorization = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + return HttpPatchAsync(uri, content, authorization, clientConfigurator, headerConfigurator).GetAwaiter().GetResult(); + } + public static async Task HttpPatchAsync( + string uri, + HttpContent httpContent = null, + string authorization = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + var httpClient = CreateHttpClient(authorization, clientConfigurator, headerConfigurator); + return await httpClient.PatchAsync(uri, httpContent).Result.Content.ReadAsStringAsync(); + } + public static string HttpPatch( + string uri, + HttpContent httpContent = null, + string authorization = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + return HttpPatchAsync(uri, httpContent, authorization, clientConfigurator, headerConfigurator).GetAwaiter().GetResult(); + } + #endregion + + #region HttpGet + public static void HttpGetFile( + string uri, + string path, + string authorization = null, + FileMode mode = FileMode.Create, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + HttpGetFileAsync(uri, path, authorization, mode, clientConfigurator, headerConfigurator).GetAwaiter().GetResult(); + } + public static async Task HttpGetFileAsync( + string uri, + AbsolutePath path, + string authorization = null, + FileMode mode = FileMode.Create, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + var httpClient = CreateHttpClient(authorization, clientConfigurator, headerConfigurator); + var response = await httpClient.GetAsync(uri); + Assert.True(response.IsSuccessStatusCode, $"{response.ReasonPhrase}: {uri}"); + + path.Parent.CreateDirectory(); + await using var fileStream = File.Open(path, mode); + await response.Content.CopyToAsync(fileStream); + } + public static async Task HttpGetAsync( + string uri, + string authorization = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + var httpClient = CreateHttpClient(authorization, clientConfigurator, headerConfigurator); + return await httpClient.GetAsync(uri).Result.Content.ReadAsStringAsync(); + } + public static string HttpGet( + string uri, + string authorization = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + return HttpGetAsync(uri, authorization, clientConfigurator, headerConfigurator).GetAwaiter().GetResult(); + } + #endregion + + #region HttpDelete + public static async Task HttpDeleteAsync( + string uri, + string authorization = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + var httpClient = CreateHttpClient(authorization, clientConfigurator, headerConfigurator); + return await httpClient.DeleteAsync(uri).Result.Content.ReadAsStringAsync(); + } + public static string HttpDelete( + string uri, + string authorization = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + return HttpDeleteAsync(uri, authorization, clientConfigurator, headerConfigurator).GetAwaiter().GetResult(); + } + #endregion + + #region HttpClient + public static TimeSpan DefaultTimeout = TimeSpan.FromSeconds(10); + + private static HttpClient CreateHttpClient( + string authorization = null, + Configure clientConfigurator = null, + Action headerConfigurator = null) + { + var httpClient = new HttpClient { Timeout = DefaultTimeout }; + SetBearerAuthorization(httpClient, authorization); + clientConfigurator?.Invoke(httpClient); + headerConfigurator?.Invoke(httpClient.DefaultRequestHeaders); + return httpClient; + } + private static void SetBearerAuthorization(HttpClient httpClient, string authorization = null) + { + const string HeaderAuthorization = "Authorization"; + if (!string.IsNullOrEmpty(authorization)) + { + httpClient.DefaultRequestHeaders.Add(HeaderAuthorization, $"Bearer {authorization}"); + } + } + + private static HttpContent JsonHttpContent(object content) + { + if (content is null) + content = string.Empty; + + HttpContent httpContent = null; + if (content is string stringContent) + { + httpContent = new StringContent(stringContent); + } + else if (content is HttpContent httpContentTo) + { + httpContent = httpContentTo; + } + else + { + const string MediaTypeJson = "application/json"; + httpContent = new StringContent(content.ToJson(), System.Text.Encoding.UTF8, MediaTypeJson); + } + + return httpContent; + } + + internal static MultipartFormDataContent CreateFormDataContent(string filePath, Dictionary formData = null, string fileStreamContentName = null) + { + if (!File.Exists(filePath)) + throw new FileNotFoundException("File not found.", filePath); + + var content = new MultipartFormDataContent(); + + if (formData is not null) + { + foreach (KeyValuePair vp in formData) + { + content.Add(new StringContent(vp.Value), vp.Key); + } + } + + if (string.IsNullOrEmpty(fileStreamContentName)) fileStreamContentName = "file"; + + var streamContent = new StreamContent(new FileStream(filePath, FileMode.Open)); + content.Add(streamContent, fileStreamContentName, Path.GetFileName(filePath)); + + return content; + } + #endregion + +} +internal static class JsonExtension +{ + internal static string ToJson(this object obj) + { + if (obj is string t) + return t; + + return Newtonsoft.Json.JsonConvert.SerializeObject(obj); + } + internal static T FromJson(this string json) + { + if (json is T t) + return t; + + return Newtonsoft.Json.JsonConvert.DeserializeObject(json); + } +} \ No newline at end of file diff --git a/ricaun.Nuke/ricaun.Nuke.csproj b/ricaun.Nuke/ricaun.Nuke.csproj index 14913d0..337a30f 100644 --- a/ricaun.Nuke/ricaun.Nuke.csproj +++ b/ricaun.Nuke/ricaun.Nuke.csproj @@ -8,7 +8,7 @@ ricaun.Nuke - 1.9.0-alpha.6 + 1.9.0-alpha.7 @@ -77,8 +77,4 @@
- - - -
From adc41a120618537f4ec984ba42f8fff781048886 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Wed, 11 Dec 2024 21:27:22 -0300 Subject: [PATCH 10/44] Remove `Requires` --- Build/IAzureSignTool.cs | 7 ++++--- CHANGELOG.md | 4 ++-- ricaun.Nuke/Components/ISign.cs | 4 ++-- ricaun.Nuke/ricaun.Nuke.csproj | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Build/IAzureSignTool.cs b/Build/IAzureSignTool.cs index b6f3f8d..08fb8c8 100644 --- a/Build/IAzureSignTool.cs +++ b/Build/IAzureSignTool.cs @@ -12,14 +12,15 @@ public interface IAzureSignTool : IClean, ICompile .Before(Compile) //.Requires() //.Requires() - .Requires() - .Requires() + //.Requires() + //.Requires() .Executes(() => { + ricaun.Nuke.Tools.AzureSignToolUtils.EnsureAzureToolIsInstalled(); + Serilog.Log.Information(AzureSignToolTasks.AzureSignToolPath); Serilog.Log.Information(NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPath); - //ricaun.Nuke.Tools.AzureSignToolUtils.DownloadAzureSignTool(); //Serilog.Log.Information("DownloadAzureSignTool"); //ricaun.Nuke.Tools.AzureSignToolUtils.DownloadNuGetKeyVaultSignTool(); //Serilog.Log.Information("DownloadNuGetKeyVaultSignTool"); diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d81c9c..2d6f5bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Enable sign files using `Azure Key Vault`. ### Build - Add `IAzureSignTool` to check if `AzureSignToolUtils` is installed. -- Update `IAzureSignTool` with `Requires`. +- [ ] Update `IAzureSignTool` with `Requires`. - [ ] Add import `build` with `.targets` ### Updates - Add `AzureSignToolUtils` to sign files using `AzureSignToolTasks` or `NuGetKeyVaultSignToolTasks`. @@ -18,7 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - [ ] Add `build` with `.targets` to install packages `AzureSignTool` and `NuGetKeyVaultSignTool`. - Add `PackageDownload` to download `AzureSignTool` and `NuGetKeyVaultSignTool` on the fly. - Update `IClear` with `CreateTemporaryIgnore`. -- Update `ISign` with `Requires`. +- [ ] Update `ISign` with `Requires`. - Add `HttpAuthTasks` to get/post files. ### Tests - Update `NuGetExtensionTests` diff --git a/ricaun.Nuke/Components/ISign.cs b/ricaun.Nuke/Components/ISign.cs index 760e7bc..3cfe1ca 100644 --- a/ricaun.Nuke/Components/ISign.cs +++ b/ricaun.Nuke/Components/ISign.cs @@ -18,8 +18,8 @@ public interface ISign : ICompile, IHazSign, IHazSolution, INukeBuild /// Target Sign => _ => _ .TriggeredBy(Compile) - .Requires() - .Requires() + //.Requires() + //.Requires() .Executes(() => { SignProject(MainProject); diff --git a/ricaun.Nuke/ricaun.Nuke.csproj b/ricaun.Nuke/ricaun.Nuke.csproj index 337a30f..b8c0330 100644 --- a/ricaun.Nuke/ricaun.Nuke.csproj +++ b/ricaun.Nuke/ricaun.Nuke.csproj @@ -8,7 +8,7 @@ ricaun.Nuke - 1.9.0-alpha.7 + 1.9.0-alpha.8 From 435563b62b8ca8de42d05fab70730abe28e643eb Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Wed, 11 Dec 2024 23:18:49 -0300 Subject: [PATCH 11/44] Update `IsPathTooLong` --- CHANGELOG.md | 1 + ricaun.Nuke/Extensions/PathTooLongUtils.cs | 2 +- ricaun.Nuke/ricaun.Nuke.csproj | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d6f5bc..a2dd641 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Update `IClear` with `CreateTemporaryIgnore`. - [ ] Update `ISign` with `Requires`. - Add `HttpAuthTasks` to get/post files. +- Update `IsPathTooLong` to equal or greater than `260`. ### Tests - Update `NuGetExtensionTests` - Add `AzureKeyVaultConfigTests` diff --git a/ricaun.Nuke/Extensions/PathTooLongUtils.cs b/ricaun.Nuke/Extensions/PathTooLongUtils.cs index 7942c76..828f5a4 100644 --- a/ricaun.Nuke/Extensions/PathTooLongUtils.cs +++ b/ricaun.Nuke/Extensions/PathTooLongUtils.cs @@ -53,7 +53,7 @@ public int GetFilePathLong() /// public bool IsPathTooLong() { - return GetFilePathLong() > MAX_PATH; + return GetFilePathLong() >= MAX_PATH; } /// diff --git a/ricaun.Nuke/ricaun.Nuke.csproj b/ricaun.Nuke/ricaun.Nuke.csproj index b8c0330..2763e5e 100644 --- a/ricaun.Nuke/ricaun.Nuke.csproj +++ b/ricaun.Nuke/ricaun.Nuke.csproj @@ -8,7 +8,7 @@ ricaun.Nuke - 1.9.0-alpha.8 + 1.9.0-alpha.9 From 52f074a477070ffba588264e8d1af3477b8b845d Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Wed, 11 Dec 2024 23:34:42 -0300 Subject: [PATCH 12/44] Remove `CreateTemporaryIgnore` --- CHANGELOG.md | 2 +- ricaun.Nuke/Components/IClean.cs | 2 +- ricaun.Nuke/ricaun.Nuke.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2dd641..9df466c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Add `AzureKeyVaultConfig` with json file with `Azure Key Vault` without secrets. - [ ] Add `build` with `.targets` to install packages `AzureSignTool` and `NuGetKeyVaultSignTool`. - Add `PackageDownload` to download `AzureSignTool` and `NuGetKeyVaultSignTool` on the fly. -- Update `IClear` with `CreateTemporaryIgnore`. +- [ ] Update `IClear` with `CreateTemporaryIgnore`. - [ ] Update `ISign` with `Requires`. - Add `HttpAuthTasks` to get/post files. - Update `IsPathTooLong` to equal or greater than `260`. diff --git a/ricaun.Nuke/Components/IClean.cs b/ricaun.Nuke/Components/IClean.cs index b2028e1..9a67214 100644 --- a/ricaun.Nuke/Components/IClean.cs +++ b/ricaun.Nuke/Components/IClean.cs @@ -15,7 +15,7 @@ public interface IClean : IHazSolution, INukeBuild Target Clean => _ => _ .Executes(() => { - CreateTemporaryIgnore(); + //CreateTemporaryIgnore(); Solution.ClearSolution(BuildProjectDirectory); }); diff --git a/ricaun.Nuke/ricaun.Nuke.csproj b/ricaun.Nuke/ricaun.Nuke.csproj index 2763e5e..dd24a87 100644 --- a/ricaun.Nuke/ricaun.Nuke.csproj +++ b/ricaun.Nuke/ricaun.Nuke.csproj @@ -8,7 +8,7 @@ ricaun.Nuke - 1.9.0-alpha.9 + 1.9.0-alpha.10 From 72ead8173c1656c42d23a6e61d2c2c9ee303c910 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Thu, 12 Dec 2024 15:59:26 -0300 Subject: [PATCH 13/44] Update `HttpAuthTasks` docs --- CHANGELOG.md | 1 + ricaun.Nuke/IO/HttpAuthTasks.cs | 243 +++++++++++++++++++++++++++++++- 2 files changed, 238 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9df466c..f39286f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - [ ] Update `IClear` with `CreateTemporaryIgnore`. - [ ] Update `ISign` with `Requires`. - Add `HttpAuthTasks` to get/post files. +- Update `HttpAuthTasks` docs. - Update `IsPathTooLong` to equal or greater than `260`. ### Tests - Update `NuGetExtensionTests` diff --git a/ricaun.Nuke/IO/HttpAuthTasks.cs b/ricaun.Nuke/IO/HttpAuthTasks.cs index c76606a..d15bfea 100644 --- a/ricaun.Nuke/IO/HttpAuthTasks.cs +++ b/ricaun.Nuke/IO/HttpAuthTasks.cs @@ -10,9 +10,23 @@ namespace ricaun.Nuke.IO; +/// +/// Provides a set of methods for performing HTTP requests with authentication. +/// public static class HttpAuthTasks { #region HttpPost + /// + /// Performs an asynchronous HTTP POST request with a file as the content. + /// + /// The URI to send the request to. + /// The path of the file to be sent as content. + /// The authorization token for the request. + /// The form data to be included in the request. + /// The name of the file stream content. + /// The configurator for the HttpClient. + /// The configurator for the HttpRequestHeaders. + /// The response content as a string. public static async Task HttpPostFileAsync( string uri, string filePath, @@ -26,6 +40,17 @@ public static async Task HttpPostFileAsync( return await HttpPostAsync(uri, content, authorization, clientConfigurator, headerConfigurator); } + /// + /// Performs a synchronous HTTP POST request with a file as the content. + /// + /// The URI to send the request to. + /// The path of the file to be sent as content. + /// The authorization token for the request. + /// The form data to be included in the request. + /// The name of the file stream content. + /// The configurator for the HttpClient. + /// The configurator for the HttpRequestHeaders. + /// The response content as a string. public static string HttpPostFile( string uri, string filePath, @@ -38,6 +63,15 @@ public static string HttpPostFile( return HttpPostFileAsync(uri, filePath, authorization, formData, fileStreamContentName, clientConfigurator, headerConfigurator).GetAwaiter().GetResult(); } + /// + /// Performs an asynchronous HTTP POST request with a JSON object as the content. + /// + /// The URI to send the request to. + /// The JSON object to be sent as content. + /// The authorization token for the request. + /// The configurator for the HttpClient. + /// The configurator for the HttpRequestHeaders. + /// The response content as a string. public static async Task HttpPostAsync( string uri, object content, @@ -48,6 +82,15 @@ public static async Task HttpPostAsync( return await HttpPostAsync(uri, JsonHttpContent(content), authorization, clientConfigurator, headerConfigurator); } + /// + /// Performs a synchronous HTTP POST request with a JSON object as the content. + /// + /// The URI to send the request to. + /// The JSON object to be sent as content. + /// The authorization token for the request. + /// The configurator for the HttpClient. + /// The configurator for the HttpRequestHeaders. + /// The response content as a string. public static string HttpPost( string uri, object content, @@ -58,6 +101,15 @@ public static string HttpPost( return HttpPostAsync(uri, content, authorization, clientConfigurator, headerConfigurator).GetAwaiter().GetResult(); } + /// + /// Performs an asynchronous HTTP POST request with a custom HttpContent object as the content. + /// + /// The URI to send the request to. + /// The custom HttpContent object to be sent as content. + /// The authorization token for the request. + /// The configurator for the HttpClient. + /// The configurator for the HttpRequestHeaders. + /// The response content as a string. public static async Task HttpPostAsync( string uri, HttpContent httpContent = null, @@ -68,6 +120,16 @@ public static async Task HttpPostAsync( var httpClient = CreateHttpClient(authorization, clientConfigurator, headerConfigurator); return await httpClient.PostAsync(uri, httpContent).Result.Content.ReadAsStringAsync(); } + + /// + /// Performs a synchronous HTTP POST request with a custom HttpContent object as the content. + /// + /// The URI to send the request to. + /// The custom HttpContent object to be sent as content. + /// The authorization token for the request. + /// The configurator for the HttpClient. + /// The configurator for the HttpRequestHeaders. + /// The response content as a string. public static string HttpPost( string uri, HttpContent httpContent = null, @@ -80,6 +142,17 @@ public static string HttpPost( #endregion #region HttpPut + /// + /// Sends an HTTP PUT request to the specified URI asynchronously and saves the response content to a file. + /// + /// The URI to which the request is sent. + /// The path of the file to be sent in the request. + /// The authorization header value. + /// The form data to be sent in the request. + /// The name of the file stream content. + /// A delegate to configure the . + /// A delegate to configure the request headers. + /// A task representing the asynchronous operation. The task result contains the response content as a string. public static async Task HttpPutFileAsync( string uri, string filePath, @@ -93,6 +166,17 @@ public static async Task HttpPutFileAsync( return await HttpPostAsync(uri, content, authorization, clientConfigurator, headerConfigurator); } + /// + /// Sends an HTTP PUT request to the specified URI and saves the response content to a file. + /// + /// The URI to which the request is sent. + /// The path of the file to be sent in the request. + /// The authorization header value. + /// The form data to be sent in the request. + /// The name of the file stream content. + /// A delegate to configure the . + /// A delegate to configure the request headers. + /// The response content as a string. public static string HttpPutFile( string uri, string filePath, @@ -105,6 +189,15 @@ public static string HttpPutFile( return HttpPutFileAsync(uri, filePath, authorization, formData, fileStreamContentName, clientConfigurator, headerConfigurator).GetAwaiter().GetResult(); } + /// + /// Sends an HTTP PUT request to the specified URI asynchronously. + /// + /// The URI to which the request is sent. + /// The content to be sent in the request. + /// The authorization header value. + /// A delegate to configure the . + /// A delegate to configure the request headers. + /// A task representing the asynchronous operation. The task result contains the response content as a string. public static async Task HttpPutAsync( string uri, object content, @@ -115,6 +208,15 @@ public static async Task HttpPutAsync( return await HttpPutAsync(uri, JsonHttpContent(content), authorization, clientConfigurator, headerConfigurator); } + /// + /// Sends an HTTP PUT request to the specified URI. + /// + /// The URI to which the request is sent. + /// The content to be sent in the request. + /// The authorization header value. + /// A delegate to configure the . + /// A delegate to configure the request headers. + /// The response content as a string. public static string HttpPut( string uri, object content, @@ -124,6 +226,15 @@ public static string HttpPut( { return HttpPutAsync(uri, content, authorization, clientConfigurator, headerConfigurator).GetAwaiter().GetResult(); } + /// + /// Sends an HTTP PUT request to the specified URI asynchronously. + /// + /// The URI to which the request is sent. + /// The HTTP content to send with the request. + /// The authorization header value. + /// A delegate to configure the . + /// A delegate to configure the request headers. + /// A task representing the asynchronous operation. The task result contains the response content as a string. public static async Task HttpPutAsync( string uri, HttpContent httpContent = null, @@ -134,6 +245,15 @@ public static async Task HttpPutAsync( var httpClient = CreateHttpClient(authorization, clientConfigurator, headerConfigurator); return await httpClient.PutAsync(uri, httpContent).Result.Content.ReadAsStringAsync(); } + /// + /// Sends an HTTP PUT request to the specified URI and returns the response content as a string. + /// + /// The URI to which the request is sent. + /// The HTTP content to send with the request. + /// The authorization header value. + /// A delegate to configure the . + /// A delegate to configure the request headers. + /// The response content as a string. public static string HttpPut( string uri, HttpContent httpContent = null, @@ -146,6 +266,17 @@ public static string HttpPut( #endregion #region HttpPatch + /// + /// Sends an HTTP PATCH request to the specified URI asynchronously and saves the response content to a file. + /// + /// The URI to which the request is sent. + /// The path of the file to be sent in the request. + /// The authorization header value. + /// The form data to be sent in the request. + /// The name of the file stream content. + /// A delegate to configure the . + /// A delegate to configure the request headers. + /// A task representing the asynchronous operation. The task result contains the response content as a string. public static async Task HttpPatchFileAsync( string uri, string filePath, @@ -159,6 +290,17 @@ public static async Task HttpPatchFileAsync( return await HttpPostAsync(uri, content, authorization, clientConfigurator, headerConfigurator); } + /// + /// Sends an HTTP PATCH request to the specified URI and saves the response content to a file. + /// + /// The URI to which the request is sent. + /// The path of the file to be sent in the request. + /// The authorization header value. + /// The form data to be sent in the request. + /// The name of the file stream content. + /// A delegate to configure the . + /// A delegate to configure the request headers. + /// The response content as a string. public static string HttpPatchFile( string uri, string filePath, @@ -171,6 +313,15 @@ public static string HttpPatchFile( return HttpPatchFileAsync(uri, filePath, authorization, formData, fileStreamContentName, clientConfigurator, headerConfigurator).GetAwaiter().GetResult(); } + /// + /// Sends an HTTP PATCH request to the specified URI asynchronously. + /// + /// The URI to which the request is sent. + /// The content to be sent in the request. + /// The authorization header value. + /// A delegate to configure the . + /// A delegate to configure the request headers. + /// A task representing the asynchronous operation. The task result contains the response content as a string. public static async Task HttpPatchAsync( string uri, object content, @@ -181,6 +332,15 @@ public static async Task HttpPatchAsync( return await HttpPatchAsync(uri, JsonHttpContent(content), authorization, clientConfigurator, headerConfigurator); } + /// + /// Sends an HTTP PATCH request to the specified URI. + /// + /// The URI to which the request is sent. + /// The content to be sent in the request. + /// The authorization header value. + /// A delegate to configure the . + /// A delegate to configure the request headers. + /// The response content as a string. public static string HttpPatch( string uri, object content, @@ -190,6 +350,16 @@ public static string HttpPatch( { return HttpPatchAsync(uri, content, authorization, clientConfigurator, headerConfigurator).GetAwaiter().GetResult(); } + + /// + /// Sends an HTTP PATCH request to the specified URI asynchronously. + /// + /// The URI to which the request is sent. + /// The HTTP content to send with the request. + /// The authorization header value. + /// A delegate to configure the . + /// A delegate to configure the request headers. + /// A task representing the asynchronous operation. The task result contains the response content as a string. public static async Task HttpPatchAsync( string uri, HttpContent httpContent = null, @@ -200,6 +370,15 @@ public static async Task HttpPatchAsync( var httpClient = CreateHttpClient(authorization, clientConfigurator, headerConfigurator); return await httpClient.PatchAsync(uri, httpContent).Result.Content.ReadAsStringAsync(); } + /// + /// Sends an HTTP PATCH request to the specified URI and returns the response content as a string. + /// + /// The URI to which the request is sent. + /// The HTTP content to send with the request. + /// The authorization header value. + /// A delegate to configure the . + /// A delegate to configure the request headers. + /// The response content as a string. public static string HttpPatch( string uri, HttpContent httpContent = null, @@ -212,6 +391,15 @@ public static string HttpPatch( #endregion #region HttpGet + /// + /// Sends an HTTP GET request to the specified URI and saves the response content to a file. + /// + /// The URI to which the request is sent. + /// The path where the response content will be saved. + /// The authorization header value. + /// The file mode used to create the file. + /// A delegate to configure the . + /// A delegate to configure the request headers. public static void HttpGetFile( string uri, string path, @@ -222,6 +410,16 @@ public static void HttpGetFile( { HttpGetFileAsync(uri, path, authorization, mode, clientConfigurator, headerConfigurator).GetAwaiter().GetResult(); } + /// + /// Sends an HTTP GET request to the specified URI asynchronously and saves the response content to a file. + /// + /// The URI to which the request is sent. + /// The path where the response content will be saved. + /// The authorization header value. + /// The file mode used to create the file. + /// A delegate to configure the . + /// A delegate to configure the request headers. + /// A task representing the asynchronous operation. public static async Task HttpGetFileAsync( string uri, AbsolutePath path, @@ -238,6 +436,14 @@ public static async Task HttpGetFileAsync( await using var fileStream = File.Open(path, mode); await response.Content.CopyToAsync(fileStream); } + /// + /// Sends an HTTP GET request to the specified URI asynchronously and returns the response content as a string. + /// + /// The URI to which the request is sent. + /// The authorization header value. + /// A delegate to configure the . + /// A delegate to configure the request headers. + /// A task representing the asynchronous operation. The task result contains the response content as a string. public static async Task HttpGetAsync( string uri, string authorization = null, @@ -247,6 +453,14 @@ public static async Task HttpGetAsync( var httpClient = CreateHttpClient(authorization, clientConfigurator, headerConfigurator); return await httpClient.GetAsync(uri).Result.Content.ReadAsStringAsync(); } + /// + /// Sends an HTTP GET request to the specified URI and returns the response content as a string. + /// + /// The URI to which the request is sent. + /// The authorization header value. + /// A delegate to configure the . + /// A delegate to configure the request headers. + /// The response content as a string. public static string HttpGet( string uri, string authorization = null, @@ -258,6 +472,14 @@ public static string HttpGet( #endregion #region HttpDelete + /// + /// Sends an HTTP DELETE request to the specified URI and returns the response content as a string asynchronously. + /// + /// The URI to which the request is sent. + /// The authorization header value. + /// A delegate to configure the . + /// A delegate to configure the request headers. + /// A task representing the asynchronous operation. The task result contains the response content as a string. public static async Task HttpDeleteAsync( string uri, string authorization = null, @@ -267,6 +489,14 @@ public static async Task HttpDeleteAsync( var httpClient = CreateHttpClient(authorization, clientConfigurator, headerConfigurator); return await httpClient.DeleteAsync(uri).Result.Content.ReadAsStringAsync(); } + /// + /// Sends an HTTP DELETE request to the specified URI and returns the response content as a string. + /// + /// The URI to which the request is sent. + /// The authorization header value. + /// A delegate to configure the . + /// A delegate to configure the request headers. + /// The response content as a string. public static string HttpDelete( string uri, string authorization = null, @@ -278,7 +508,10 @@ public static string HttpDelete( #endregion #region HttpClient - public static TimeSpan DefaultTimeout = TimeSpan.FromSeconds(10); + /// + /// DefaultTimeout (30 seconds) + /// + public static TimeSpan DefaultTimeout = TimeSpan.FromSeconds(30); private static HttpClient CreateHttpClient( string authorization = null, @@ -346,10 +579,7 @@ internal static MultipartFormDataContent CreateFormDataContent(string filePath, return content; } #endregion - -} -internal static class JsonExtension -{ + #region Json internal static string ToJson(this object obj) { if (obj is string t) @@ -364,4 +594,5 @@ internal static T FromJson(this string json) return Newtonsoft.Json.JsonConvert.DeserializeObject(json); } -} \ No newline at end of file + #endregion +} From 2cf5916a28aaf9a2a3cf16f1caf26a064b8582ff Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Thu, 12 Dec 2024 16:21:51 -0300 Subject: [PATCH 14/44] Update `SignExtension.Sign` to sign NuGet or files. --- CHANGELOG.md | 1 + ricaun.Nuke/Components/IHazSign.cs | 6 +++--- ricaun.Nuke/Extensions/SignExtension.cs | 20 +++++++++++++++++++- ricaun.Nuke/ricaun.Nuke.csproj | 5 +++++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f39286f..321d75a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Add `HttpAuthTasks` to get/post files. - Update `HttpAuthTasks` docs. - Update `IsPathTooLong` to equal or greater than `260`. +- Update `SignExtension.Sign` to sign NuGet or files. ### Tests - Update `NuGetExtensionTests` - Add `AzureKeyVaultConfigTests` diff --git a/ricaun.Nuke/Components/IHazSign.cs b/ricaun.Nuke/Components/IHazSign.cs index bc20d1a..8eefc56 100644 --- a/ricaun.Nuke/Components/IHazSign.cs +++ b/ricaun.Nuke/Components/IHazSign.cs @@ -70,15 +70,15 @@ public bool SignFolder(string folder, string namePattern = "*", bool dllSign = t if (dllSign) Globbing.GlobFiles(folder, $"**/{namePattern}.dll") - .ForEach(file => SignExtension.SignBinary(certPath, certPassword, file)); + .ForEach(file => SignExtension.Sign(certPath, certPassword, file)); if (nupkgSign) Globbing.GlobFiles(folder, $"**/{namePattern}.nupkg") - .ForEach(file => SignExtension.SignNuGet(certPath, certPassword, file)); + .ForEach(file => SignExtension.Sign(certPath, certPassword, file)); if (exeSign) Globbing.GlobFiles(folder, $"**/{namePattern}.exe") - .ForEach(file => SignExtension.SignBinary(certPath, certPassword, file)); + .ForEach(file => SignExtension.Sign(certPath, certPassword, file)); return Globbing.GlobFiles(folder, $"**/{namePattern}").Count > 0; } diff --git a/ricaun.Nuke/Extensions/SignExtension.cs b/ricaun.Nuke/Extensions/SignExtension.cs index b6e2221..c3701bd 100644 --- a/ricaun.Nuke/Extensions/SignExtension.cs +++ b/ricaun.Nuke/Extensions/SignExtension.cs @@ -71,6 +71,24 @@ public static bool CreateCerFile(string fileNamePfx, string passwordPfx, string if (File.Exists(cert)) return true; return CreateCertificatesCer(fileNamePfx, passwordPfx, cert); } + + /// + /// Sign the specified file using the provided certificate. + /// + /// The path to the certificate file. + /// The password for the certificate. + /// The path to the file to be signed. + /// NuGet files use . + public static void Sign(string certPath, string certPassword, string filePath) + { + if (Path.GetExtension(filePath) == ".nupkg") + { + SignNuGet(certPath, certPassword, filePath); + return; + } + SignBinary(certPath, certPassword, filePath); + } + /// /// https://github.com/DataDog/dd-trace-dotnet/blob/master/tracer/build/_build/Build.Gitlab.cs /// @@ -124,7 +142,7 @@ public static void SignBinary(string certPath, string certPassword, string binar } /// - /// Sign Nuget + /// Sign NuGet /// /// /// diff --git a/ricaun.Nuke/ricaun.Nuke.csproj b/ricaun.Nuke/ricaun.Nuke.csproj index dd24a87..5b5ae23 100644 --- a/ricaun.Nuke/ricaun.Nuke.csproj +++ b/ricaun.Nuke/ricaun.Nuke.csproj @@ -77,4 +77,9 @@ + + + + + From bbb17f2c3663102c233be48f94c20ef9199b3874 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Thu, 12 Dec 2024 16:30:36 -0300 Subject: [PATCH 15/44] Update `SignProject` to sign files using `Azure Key Vault` if available --- CHANGELOG.md | 1 + ricaun.Nuke/Components/IHazSign.cs | 34 ++++++++++++++++++++++++------ ricaun.Nuke/ricaun.Nuke.csproj | 4 ++-- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 321d75a..1fe1370 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Update `HttpAuthTasks` docs. - Update `IsPathTooLong` to equal or greater than `260`. - Update `SignExtension.Sign` to sign NuGet or files. +- Update `SignProject` to sign files using `Azure Key Vault` if available. ### Tests - Update `NuGetExtensionTests` - Add `AzureKeyVaultConfigTests` diff --git a/ricaun.Nuke/Components/IHazSign.cs b/ricaun.Nuke/Components/IHazSign.cs index 8eefc56..ab11fb0 100644 --- a/ricaun.Nuke/Components/IHazSign.cs +++ b/ricaun.Nuke/Components/IHazSign.cs @@ -3,6 +3,8 @@ using Nuke.Common.ProjectModel; using Nuke.Common.Utilities.Collections; using ricaun.Nuke.Extensions; +using ricaun.Nuke.Tools; +using System; namespace ricaun.Nuke.Components { @@ -61,24 +63,44 @@ public bool SignFolder(string folder, string namePattern = "*", bool dllSign = t return false; } - var certPath = SignExtension.VerifySignFile(SignFile, BuildAssemblyDirectory); - var certPassword = SignPassword; + Action signFile = null; - SignExtension.CreateCerFile(certPath, certPassword, BuildAssemblyDirectory); + if (AzureKeyVaultConfig.Create(SignFile) is AzureKeyVaultConfig azureKeyVaultConfig) + { + var azureKeyVaultClientSecret = SignPassword; + void SignUsingAzureKeyVault(string file) + { + AzureSignToolUtils.Sign(file, azureKeyVaultConfig, azureKeyVaultClientSecret); + } + signFile = SignUsingAzureKeyVault; + } + else + { + var certPath = SignExtension.VerifySignFile(SignFile, BuildAssemblyDirectory); + var certPassword = SignPassword; + + SignExtension.CreateCerFile(certPath, certPassword, BuildAssemblyDirectory); + + void SignUsingCerFile(string file) + { + SignExtension.Sign(certPath, certPassword, file); + } + signFile = SignUsingCerFile; + } Serilog.Log.Information($"SignFolder [{namePattern}]: {folder}"); if (dllSign) Globbing.GlobFiles(folder, $"**/{namePattern}.dll") - .ForEach(file => SignExtension.Sign(certPath, certPassword, file)); + .ForEach(signFile); if (nupkgSign) Globbing.GlobFiles(folder, $"**/{namePattern}.nupkg") - .ForEach(file => SignExtension.Sign(certPath, certPassword, file)); + .ForEach(signFile); if (exeSign) Globbing.GlobFiles(folder, $"**/{namePattern}.exe") - .ForEach(file => SignExtension.Sign(certPath, certPassword, file)); + .ForEach(signFile); return Globbing.GlobFiles(folder, $"**/{namePattern}").Count > 0; } diff --git a/ricaun.Nuke/ricaun.Nuke.csproj b/ricaun.Nuke/ricaun.Nuke.csproj index 5b5ae23..46f4832 100644 --- a/ricaun.Nuke/ricaun.Nuke.csproj +++ b/ricaun.Nuke/ricaun.Nuke.csproj @@ -77,9 +77,9 @@ - + From 9c9ed339386ef18ac751ff132beb2d78c6fdc783 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Thu, 12 Dec 2024 16:31:21 -0300 Subject: [PATCH 16/44] Add `build` with `.targets` --- CHANGELOG.md | 2 +- ricaun.Nuke/ricaun.Nuke.csproj | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fe1370..f29cf8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Add `AzureSignToolUtils` to sign files using `AzureSignToolTasks` or `NuGetKeyVaultSignToolTasks`. - Add `NuGetKeyVaultSignTool` for nuke version `8.*`. - Add `AzureKeyVaultConfig` with json file with `Azure Key Vault` without secrets. -- [ ] Add `build` with `.targets` to install packages `AzureSignTool` and `NuGetKeyVaultSignTool`. +- Add `build` with `.targets` to install packages `AzureSignTool` and `NuGetKeyVaultSignTool`. - Add `PackageDownload` to download `AzureSignTool` and `NuGetKeyVaultSignTool` on the fly. - [ ] Update `IClear` with `CreateTemporaryIgnore`. - [ ] Update `ISign` with `Requires`. diff --git a/ricaun.Nuke/ricaun.Nuke.csproj b/ricaun.Nuke/ricaun.Nuke.csproj index 46f4832..5b5ae23 100644 --- a/ricaun.Nuke/ricaun.Nuke.csproj +++ b/ricaun.Nuke/ricaun.Nuke.csproj @@ -77,9 +77,9 @@ - + From a04fe4800deeb79294ddc8863fd4b7c4b2444e32 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Thu, 12 Dec 2024 16:33:09 -0300 Subject: [PATCH 17/44] Add import `build` with `.targets` --- Build/Build.csproj | 2 +- CHANGELOG.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Build/Build.csproj b/Build/Build.csproj index 16ed451..fd86e57 100644 --- a/Build/Build.csproj +++ b/Build/Build.csproj @@ -19,6 +19,6 @@ - + diff --git a/CHANGELOG.md b/CHANGELOG.md index f29cf8c..0d3f729 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Build - Add `IAzureSignTool` to check if `AzureSignToolUtils` is installed. - [ ] Update `IAzureSignTool` with `Requires`. -- [ ] Add import `build` with `.targets` +- Add import `build` with `.targets` ### Updates - Add `AzureSignToolUtils` to sign files using `AzureSignToolTasks` or `NuGetKeyVaultSignToolTasks`. - Add `NuGetKeyVaultSignTool` for nuke version `8.*`. From 01cfe84c6cfb29a85925b90427e2ab4f6ff38c1b Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Thu, 12 Dec 2024 16:34:24 -0300 Subject: [PATCH 18/44] Version `1.9.0-alpha.11` --- ricaun.Nuke/ricaun.Nuke.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ricaun.Nuke/ricaun.Nuke.csproj b/ricaun.Nuke/ricaun.Nuke.csproj index 5b5ae23..024aac9 100644 --- a/ricaun.Nuke/ricaun.Nuke.csproj +++ b/ricaun.Nuke/ricaun.Nuke.csproj @@ -8,7 +8,7 @@ ricaun.Nuke - 1.9.0-alpha.10 + 1.9.0-alpha.11 From 188ca30c8b57144e6bbe96633ffc169881edcea2 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Thu, 12 Dec 2024 16:49:36 -0300 Subject: [PATCH 19/44] Update `AzureSignToolUtils` to not download packages --- ricaun.Nuke/Tools/AzureSignToolUtils.cs | 4 ++-- ricaun.Nuke/ricaun.Nuke.csproj | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ricaun.Nuke/Tools/AzureSignToolUtils.cs b/ricaun.Nuke/Tools/AzureSignToolUtils.cs index 8704bcc..dce5cb3 100644 --- a/ricaun.Nuke/Tools/AzureSignToolUtils.cs +++ b/ricaun.Nuke/Tools/AzureSignToolUtils.cs @@ -123,7 +123,7 @@ public static void Sign(string fileName, { if (Path.GetExtension(fileName) == NugetPackageExtension) { - DownloadNuGetKeyVaultSignTool(); + //DownloadNuGetKeyVaultSignTool(); NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignTool(x => x .SetFile(fileName) .SetKeyVaultCertificateName(azureKeyVaultConfig.AzureKeyVaultCertificate) @@ -137,7 +137,7 @@ public static void Sign(string fileName, return; } - DownloadAzureSignTool(); + //DownloadAzureSignTool(); AzureSignToolTasks.AzureSignTool(x => x .SetFiles(fileName) .SetKeyVaultCertificateName(azureKeyVaultConfig.AzureKeyVaultCertificate) diff --git a/ricaun.Nuke/ricaun.Nuke.csproj b/ricaun.Nuke/ricaun.Nuke.csproj index 024aac9..68234b7 100644 --- a/ricaun.Nuke/ricaun.Nuke.csproj +++ b/ricaun.Nuke/ricaun.Nuke.csproj @@ -8,7 +8,7 @@ ricaun.Nuke - 1.9.0-alpha.11 + 1.9.0-alpha.12 From 70f72f848fae703b5b9daa4e8fd8bb78fdba5eed Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Thu, 12 Dec 2024 17:10:09 -0300 Subject: [PATCH 20/44] Add `Directory.Build.props` --- Directory.Build.props | 5 +++++ ricaun.Nuke.sln | 3 ++- ricaun.Nuke/ricaun.Nuke.csproj | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 Directory.Build.props diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..bdf924f --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,5 @@ + + + 1.9.0-alpha.12 + + \ No newline at end of file diff --git a/ricaun.Nuke.sln b/ricaun.Nuke.sln index 82b75d5..3d618f3 100644 --- a/ricaun.Nuke.sln +++ b/ricaun.Nuke.sln @@ -10,6 +10,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution", "Solution", "{4EED1749-7A3F-47C6-8361-F4E45A143AFA}" ProjectSection(SolutionItems) = preProject CHANGELOG.md = CHANGELOG.md + Directory.Build.props = Directory.Build.props README.md = README.md EndProjectSection EndProject @@ -19,7 +20,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ricaun.Nuke.RevitAddin.Exam EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ricaun.Nuke.Example.Tests", "ricaun.Nuke.Example.Tests\ricaun.Nuke.Example.Tests.csproj", "{36867697-93A0-4F07-AA4D-78FD70985EDE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ricaun.Nuke.Tests", "ricaun.Nuke.Tests\ricaun.Nuke.Tests.csproj", "{80F1FFD0-AB40-40BE-83E6-10E425F41B30}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ricaun.Nuke.Tests", "ricaun.Nuke.Tests\ricaun.Nuke.Tests.csproj", "{80F1FFD0-AB40-40BE-83E6-10E425F41B30}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/ricaun.Nuke/ricaun.Nuke.csproj b/ricaun.Nuke/ricaun.Nuke.csproj index 68234b7..e534cc6 100644 --- a/ricaun.Nuke/ricaun.Nuke.csproj +++ b/ricaun.Nuke/ricaun.Nuke.csproj @@ -8,7 +8,7 @@ ricaun.Nuke - 1.9.0-alpha.12 + 1.9.0 From 3f69d43b33b024eed8d5e7738c96fe2989d35ee6 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Thu, 12 Dec 2024 18:10:31 -0300 Subject: [PATCH 21/44] Update `HttpAuthTasks` --- ricaun.Nuke/IO/HttpAuthTasks.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ricaun.Nuke/IO/HttpAuthTasks.cs b/ricaun.Nuke/IO/HttpAuthTasks.cs index d15bfea..39d2d41 100644 --- a/ricaun.Nuke/IO/HttpAuthTasks.cs +++ b/ricaun.Nuke/IO/HttpAuthTasks.cs @@ -579,6 +579,7 @@ internal static MultipartFormDataContent CreateFormDataContent(string filePath, return content; } #endregion + #region Json internal static string ToJson(this object obj) { From 9cd908fbc03f0f30f156a993824b6734f15669d0 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Tue, 17 Dec 2024 14:08:06 -0300 Subject: [PATCH 22/44] Add version `Information` in the `CommonExtension`. --- Build/Build.csproj | 2 +- CHANGELOG.md | 5 +++-- Directory.Build.props | 2 +- ricaun.Nuke/CommonExtension.cs | 30 +++++++++++++++++++++++++++++- ricaun.Nuke/ricaun.Nuke.csproj | 7 ++----- 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/Build/Build.csproj b/Build/Build.csproj index fd86e57..16ed451 100644 --- a/Build/Build.csproj +++ b/Build/Build.csproj @@ -19,6 +19,6 @@ - + diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d3f729..2894f86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,12 +10,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Build - Add `IAzureSignTool` to check if `AzureSignToolUtils` is installed. - [ ] Update `IAzureSignTool` with `Requires`. -- Add import `build` with `.targets` +- [ ] Add import `build` with `.targets` ### Updates +- Add version `Information` in the `CommonExtension`. - Add `AzureSignToolUtils` to sign files using `AzureSignToolTasks` or `NuGetKeyVaultSignToolTasks`. - Add `NuGetKeyVaultSignTool` for nuke version `8.*`. - Add `AzureKeyVaultConfig` with json file with `Azure Key Vault` without secrets. -- Add `build` with `.targets` to install packages `AzureSignTool` and `NuGetKeyVaultSignTool`. +- [ ] Add `build` with `.targets` to install packages `AzureSignTool` and `NuGetKeyVaultSignTool`. - Add `PackageDownload` to download `AzureSignTool` and `NuGetKeyVaultSignTool` on the fly. - [ ] Update `IClear` with `CreateTemporaryIgnore`. - [ ] Update `ISign` with `Requires`. diff --git a/Directory.Build.props b/Directory.Build.props index bdf924f..688ed7e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 1.9.0-alpha.12 + 1.9.0-beta \ No newline at end of file diff --git a/ricaun.Nuke/CommonExtension.cs b/ricaun.Nuke/CommonExtension.cs index 90efccb..87a170b 100644 --- a/ricaun.Nuke/CommonExtension.cs +++ b/ricaun.Nuke/CommonExtension.cs @@ -1,4 +1,6 @@ using Nuke.Common; +using Nuke.Common.Utilities; +using System.Linq; namespace ricaun.Nuke { @@ -13,7 +15,33 @@ public static class CommonExtension /// /// /// - public static T From(this T nukeBuild) where T : INukeBuild => (T)(object)nukeBuild; + public static T From(this T nukeBuild) where T : INukeBuild + { + ShowVersion(); + return (T)(object)nukeBuild; + } + + internal static void ShowVersion() + { + Information(); + var assemblyName = typeof(CommonExtension).Assembly.GetName().Name; + foreach (var item in System.AppDomain.CurrentDomain.GetAssemblies() + .Where(e => e.GetName().Name.StartsWith(assemblyName, System.StringComparison.InvariantCultureIgnoreCase))) + { + Information($"{item.GetName().Name} {item.GetVersionText()}"); + } + } + + internal static void Information(string text = null) + { + try + { + // internal static void Information(string text = null) + typeof(Host).GetMethod("Information",System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static) + .Invoke(null, new object[] { text }); + } + catch { }; + } } } diff --git a/ricaun.Nuke/ricaun.Nuke.csproj b/ricaun.Nuke/ricaun.Nuke.csproj index e534cc6..535b270 100644 --- a/ricaun.Nuke/ricaun.Nuke.csproj +++ b/ricaun.Nuke/ricaun.Nuke.csproj @@ -14,10 +14,7 @@ - - .Dev - - + ricaun Luiz Henrique Cassettari @@ -79,7 +76,7 @@ - + From d9c5724e85b66ec8f3741045d4f4d77a087212ed Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Tue, 17 Dec 2024 14:08:55 -0300 Subject: [PATCH 23/44] Add `PackageDownload` to download --- ricaun.Nuke/Tools/AzureSignToolUtils.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ricaun.Nuke/Tools/AzureSignToolUtils.cs b/ricaun.Nuke/Tools/AzureSignToolUtils.cs index dce5cb3..8704bcc 100644 --- a/ricaun.Nuke/Tools/AzureSignToolUtils.cs +++ b/ricaun.Nuke/Tools/AzureSignToolUtils.cs @@ -123,7 +123,7 @@ public static void Sign(string fileName, { if (Path.GetExtension(fileName) == NugetPackageExtension) { - //DownloadNuGetKeyVaultSignTool(); + DownloadNuGetKeyVaultSignTool(); NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignTool(x => x .SetFile(fileName) .SetKeyVaultCertificateName(azureKeyVaultConfig.AzureKeyVaultCertificate) @@ -137,7 +137,7 @@ public static void Sign(string fileName, return; } - //DownloadAzureSignTool(); + DownloadAzureSignTool(); AzureSignToolTasks.AzureSignTool(x => x .SetFiles(fileName) .SetKeyVaultCertificateName(azureKeyVaultConfig.AzureKeyVaultCertificate) From 54286ca281fa51872164f6d7877bba029e18325c Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Tue, 17 Dec 2024 14:18:03 -0300 Subject: [PATCH 24/44] Update `GetToolInstallationPath` to use user temp folder --- CHANGELOG.md | 1 + ricaun.Nuke/Tools/AzureSignToolUtils.cs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2894f86..c01bcf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Update `IsPathTooLong` to equal or greater than `260`. - Update `SignExtension.Sign` to sign NuGet or files. - Update `SignProject` to sign files using `Azure Key Vault` if available. +- Update `GetToolInstallationPath` to use user temp folder. ### Tests - Update `NuGetExtensionTests` - Add `AzureKeyVaultConfigTests` diff --git a/ricaun.Nuke/Tools/AzureSignToolUtils.cs b/ricaun.Nuke/Tools/AzureSignToolUtils.cs index 8704bcc..282c4e8 100644 --- a/ricaun.Nuke/Tools/AzureSignToolUtils.cs +++ b/ricaun.Nuke/Tools/AzureSignToolUtils.cs @@ -49,7 +49,8 @@ public static void EnsureAzureToolIsInstalled() private static AbsolutePath GetToolInstallationPath() { - AbsolutePath folder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); + var assemblyName = typeof(AzureSignToolUtils).Assembly.GetName(); + AbsolutePath folder = (AbsolutePath) Path.GetTempPath() / assemblyName.Name / assemblyName.Version.ToString(3); return folder / "Tools"; } From b1bf8d11f3c708e03bbf57cbbe1051d20f3a7fbc Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Tue, 17 Dec 2024 14:36:54 -0300 Subject: [PATCH 25/44] Update `TestRunUtil` icons to circle with color --- CHANGELOG.md | 1 + Directory.Build.props | 2 +- ricaun.Nuke/Utils/TestRunUtil.cs | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c01bcf5..30a0596 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Update `SignExtension.Sign` to sign NuGet or files. - Update `SignProject` to sign files using `Azure Key Vault` if available. - Update `GetToolInstallationPath` to use user temp folder. +- Update `TestRunUtil` icons to circle with color. ### Tests - Update `NuGetExtensionTests` - Add `AzureKeyVaultConfigTests` diff --git a/Directory.Build.props b/Directory.Build.props index 688ed7e..ffe9c01 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 1.9.0-beta + 1.9.0-beta.1 \ No newline at end of file diff --git a/ricaun.Nuke/Utils/TestRunUtil.cs b/ricaun.Nuke/Utils/TestRunUtil.cs index 365b958..515c7d2 100644 --- a/ricaun.Nuke/Utils/TestRunUtil.cs +++ b/ricaun.Nuke/Utils/TestRunUtil.cs @@ -253,9 +253,9 @@ public static string GetDetailsTestReport(AbsolutePath resultFile) } #region Utils - const string IconFailed = ":x:"; - const string IconSkipped = ":warning:"; - const string IconPassed = ":heavy_check_mark:"; + const string IconFailed = ":red_circle:"; + const string IconSkipped = ":yellow_circle:"; + const string IconPassed = ":green_circle:"; /// /// GetIcon /// From a9c08973884c07a58d7cbe8af6373b6be7e0cef9 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Tue, 17 Dec 2024 15:53:19 -0300 Subject: [PATCH 26/44] Add `Resource` and `Resource.pt-BR` to test sign files. --- CHANGELOG.md | 2 + .../Properties/Resource.Designer.cs | 72 ++++++++++ .../Properties/Resource.pt-BR.resx | 123 ++++++++++++++++++ .../Properties/Resource.resx | 123 ++++++++++++++++++ .../ricaun.Nuke.RevitAddin.Example.csproj | 15 +++ 5 files changed, 335 insertions(+) create mode 100644 ricaun.Nuke.RevitAddin.Example/Properties/Resource.Designer.cs create mode 100644 ricaun.Nuke.RevitAddin.Example/Properties/Resource.pt-BR.resx create mode 100644 ricaun.Nuke.RevitAddin.Example/Properties/Resource.resx diff --git a/CHANGELOG.md b/CHANGELOG.md index 30a0596..9872f5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Update `SignProject` to sign files using `Azure Key Vault` if available. - Update `GetToolInstallationPath` to use user temp folder. - Update `TestRunUtil` icons to circle with color. +### Example +- Add `Resource` and `Resource.pt-BR` to test sign files. ### Tests - Update `NuGetExtensionTests` - Add `AzureKeyVaultConfigTests` diff --git a/ricaun.Nuke.RevitAddin.Example/Properties/Resource.Designer.cs b/ricaun.Nuke.RevitAddin.Example/Properties/Resource.Designer.cs new file mode 100644 index 0000000..dce1317 --- /dev/null +++ b/ricaun.Nuke.RevitAddin.Example/Properties/Resource.Designer.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace ricaun.Nuke.RevitAddin.Example.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resource { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resource() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ricaun.Nuke.RevitAddin.Example.Properties.Resource", typeof(Resource).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Text. + /// + internal static string Text { + get { + return ResourceManager.GetString("Text", resourceCulture); + } + } + } +} diff --git a/ricaun.Nuke.RevitAddin.Example/Properties/Resource.pt-BR.resx b/ricaun.Nuke.RevitAddin.Example/Properties/Resource.pt-BR.resx new file mode 100644 index 0000000..f7b59cd --- /dev/null +++ b/ricaun.Nuke.RevitAddin.Example/Properties/Resource.pt-BR.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Texto + + \ No newline at end of file diff --git a/ricaun.Nuke.RevitAddin.Example/Properties/Resource.resx b/ricaun.Nuke.RevitAddin.Example/Properties/Resource.resx new file mode 100644 index 0000000..8c9dc5f --- /dev/null +++ b/ricaun.Nuke.RevitAddin.Example/Properties/Resource.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Text + + \ No newline at end of file diff --git a/ricaun.Nuke.RevitAddin.Example/ricaun.Nuke.RevitAddin.Example.csproj b/ricaun.Nuke.RevitAddin.Example/ricaun.Nuke.RevitAddin.Example.csproj index 20d12a5..dd57f4a 100644 --- a/ricaun.Nuke.RevitAddin.Example/ricaun.Nuke.RevitAddin.Example.csproj +++ b/ricaun.Nuke.RevitAddin.Example/ricaun.Nuke.RevitAddin.Example.csproj @@ -124,4 +124,19 @@ + + + True + True + Resource.resx + + + + + + ResXFileCodeGenerator + Resource.Designer.cs + + + \ No newline at end of file From 45c94a47ca949f94c4a8c46ac2dc182cfacaafef Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Tue, 17 Dec 2024 15:59:07 -0300 Subject: [PATCH 27/44] Update `AzureSignToolUtils` sign to ignore exception --- CHANGELOG.md | 1 + Directory.Build.props | 2 +- ricaun.Nuke/Tools/AzureSignToolUtils.cs | 42 +++++++++++++++---------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9872f5b..9aa6b63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Update `SignProject` to sign files using `Azure Key Vault` if available. - Update `GetToolInstallationPath` to use user temp folder. - Update `TestRunUtil` icons to circle with color. +- Update `AzureSignToolUtils` sign to ignore exception. ### Example - Add `Resource` and `Resource.pt-BR` to test sign files. ### Tests diff --git a/Directory.Build.props b/Directory.Build.props index ffe9c01..762838f 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 1.9.0-beta.1 + 1.9.0-beta.2 \ No newline at end of file diff --git a/ricaun.Nuke/Tools/AzureSignToolUtils.cs b/ricaun.Nuke/Tools/AzureSignToolUtils.cs index 282c4e8..f7a059f 100644 --- a/ricaun.Nuke/Tools/AzureSignToolUtils.cs +++ b/ricaun.Nuke/Tools/AzureSignToolUtils.cs @@ -122,11 +122,27 @@ public static void Sign(string fileName, string timestampUrlDefault = TimestampUrlDefault, string timestampDigestDefault = TimestampDigestDefault) { - if (Path.GetExtension(fileName) == NugetPackageExtension) + try { - DownloadNuGetKeyVaultSignTool(); - NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignTool(x => x - .SetFile(fileName) + if (Path.GetExtension(fileName) == NugetPackageExtension) + { + DownloadNuGetKeyVaultSignTool(); + NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignTool(x => x + .SetFile(fileName) + .SetKeyVaultCertificateName(azureKeyVaultConfig.AzureKeyVaultCertificate) + .SetKeyVaultUrl(azureKeyVaultConfig.AzureKeyVaultUrl) + .SetKeyVaultClientId(azureKeyVaultConfig.AzureKeyVaultClientId) + .SetKeyVaultTenantId(azureKeyVaultConfig.AzureKeyVaultTenantId) + .SetKeyVaultClientSecret(azureKeyVaultClientSecret) + .SetTimestampRfc3161Url(azureKeyVaultConfig.TimestampUrl ?? timestampUrlDefault) + .SetTimestampDigest(azureKeyVaultConfig.TimestampDigest ?? timestampDigestDefault) + ); + return; + } + + DownloadAzureSignTool(); + AzureSignToolTasks.AzureSignTool(x => x + .SetFiles(fileName) .SetKeyVaultCertificateName(azureKeyVaultConfig.AzureKeyVaultCertificate) .SetKeyVaultUrl(azureKeyVaultConfig.AzureKeyVaultUrl) .SetKeyVaultClientId(azureKeyVaultConfig.AzureKeyVaultClientId) @@ -135,20 +151,12 @@ public static void Sign(string fileName, .SetTimestampRfc3161Url(azureKeyVaultConfig.TimestampUrl ?? timestampUrlDefault) .SetTimestampDigest(azureKeyVaultConfig.TimestampDigest ?? timestampDigestDefault) ); - return; } - - DownloadAzureSignTool(); - AzureSignToolTasks.AzureSignTool(x => x - .SetFiles(fileName) - .SetKeyVaultCertificateName(azureKeyVaultConfig.AzureKeyVaultCertificate) - .SetKeyVaultUrl(azureKeyVaultConfig.AzureKeyVaultUrl) - .SetKeyVaultClientId(azureKeyVaultConfig.AzureKeyVaultClientId) - .SetKeyVaultTenantId(azureKeyVaultConfig.AzureKeyVaultTenantId) - .SetKeyVaultClientSecret(azureKeyVaultClientSecret) - .SetTimestampRfc3161Url(azureKeyVaultConfig.TimestampUrl ?? timestampUrlDefault) - .SetTimestampDigest(azureKeyVaultConfig.TimestampDigest ?? timestampDigestDefault) - ); + catch (Exception ex) + { + Serilog.Log.Error($"Azure Sign Error: {Path.GetFileName(fileName)} - {ex.Message}"); + Serilog.Log.Information(ex.ToString()); + } } } From 7e3f4d65f49ae4483129c195707269fa689c0815 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Tue, 17 Dec 2024 16:01:03 -0300 Subject: [PATCH 28/44] Update `Build.yml` --- .github/workflows/{Develop.yml => Build.yml} | 11 ++++---- .github/workflows/Publish.yml | 29 -------------------- README.md | 2 +- 3 files changed, 6 insertions(+), 36 deletions(-) rename .github/workflows/{Develop.yml => Build.yml} (87%) delete mode 100644 .github/workflows/Publish.yml diff --git a/.github/workflows/Develop.yml b/.github/workflows/Build.yml similarity index 87% rename from .github/workflows/Develop.yml rename to .github/workflows/Build.yml index 93a6070..37e4bf9 100644 --- a/.github/workflows/Develop.yml +++ b/.github/workflows/Build.yml @@ -1,21 +1,20 @@ # ------------------------------------------------------------------------------ -# Develop.yml +# Build.yml # ------------------------------------------------------------------------------ -name: Develop +name: Build on: push: - branches-ignore: - - master pull_request: branches-ignore: - master + - main workflow_dispatch: jobs: - Develop: - name: Develop + Build: + name: Build runs-on: windows-latest steps: - uses: actions/checkout@v1 diff --git a/.github/workflows/Publish.yml b/.github/workflows/Publish.yml deleted file mode 100644 index eeb8fc3..0000000 --- a/.github/workflows/Publish.yml +++ /dev/null @@ -1,29 +0,0 @@ -# ------------------------------------------------------------------------------ -# Publish.yml -# ------------------------------------------------------------------------------ - -name: Publish - -on: - push: - branches: - - master - workflow_dispatch: - -jobs: - Publish: - name: Publish - runs-on: windows-latest - steps: - - uses: actions/checkout@v1 - - - name: Run './build/build.cmd' - run: ./build/build.cmd --root ./build - env: - GitHubToken: ${{ secrets.GITHUB_TOKEN }} - - NugetApiUrl: ${{ secrets.NUGET_API_URL }} - NugetApiKey: ${{ secrets.NUGET_API_KEY }} - - SignFile: ${{ secrets.SIGN_FILE }} - SignPassword: ${{ secrets.SIGN_PASSWORD }} \ No newline at end of file diff --git a/README.md b/README.md index 3bb8bac..1b4cc9f 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This package is to simplify the build automation system using [Nuke.Common](http [![Visual Studio 2022](https://img.shields.io/badge/Visual%20Studio-2022-blue)](../..) [![Nuke](https://img.shields.io/badge/Nuke-Build-blue)](https://nuke.build/) [![License MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) -[![Publish](https://github.com/ricaun-io/ricaun.Nuke/actions/workflows/Publish.yml/badge.svg)](https://github.com/ricaun-io/ricaun.Nuke/actions) +[![Build](https://github.com/ricaun-io/ricaun.Nuke/actions/workflows/Build.yml/badge.svg)](https://github.com/ricaun-io/ricaun.Nuke/actions) [![Release](https://img.shields.io/nuget/v/ricaun.Nuke?logo=nuget&label=release&color=blue)](https://www.nuget.org/packages/ricaun.Nuke) # Examples From 5ca5e2b62319f31ff78186a9ca8f86045bcb4918 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Tue, 17 Dec 2024 16:01:40 -0300 Subject: [PATCH 29/44] Use Azure --- .github/workflows/Build.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 37e4bf9..4985a51 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -27,5 +27,7 @@ jobs: NugetApiUrl: ${{ secrets.NUGET_API_URL }} NugetApiKey: ${{ secrets.NUGET_API_KEY }} - SignFile: ${{ secrets.SIGN_FILE }} - SignPassword: ${{ secrets.SIGN_PASSWORD }} \ No newline at end of file + # SignFile: ${{ secrets.SIGN_FILE }} + # SignPassword: ${{ secrets.SIGN_PASSWORD }} + SignFile: ${{ secrets.AZURE_KEY_VAULT_FILE }} + SignPassword: ${{ secrets.AZURE_KEY_VAULT_PASSWORD }} \ No newline at end of file From 9cccfbde361627089231af59fe26b8a7083aec63 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Tue, 17 Dec 2024 16:23:46 -0300 Subject: [PATCH 30/44] Update `AzureSignToolUtils` to ignore if file is already signed. --- CHANGELOG.md | 1 + Directory.Build.props | 2 +- ricaun.Nuke/Extensions/NuGetExtension.cs | 15 +++++++++++++++ ricaun.Nuke/Extensions/SignExtension.cs | 14 +++++++------- ricaun.Nuke/Tools/AzureSignToolUtils.cs | 17 ++++++++++------- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9aa6b63..ae00e06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Update `GetToolInstallationPath` to use user temp folder. - Update `TestRunUtil` icons to circle with color. - Update `AzureSignToolUtils` sign to ignore exception. +- Update `AzureSignToolUtils` to ignore if file is already signed. ### Example - Add `Resource` and `Resource.pt-BR` to test sign files. ### Tests diff --git a/Directory.Build.props b/Directory.Build.props index 762838f..9012c01 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 1.9.0-beta.2 + 1.9.0-beta.3 \ No newline at end of file diff --git a/ricaun.Nuke/Extensions/NuGetExtension.cs b/ricaun.Nuke/Extensions/NuGetExtension.cs index dd3945e..3d40d82 100644 --- a/ricaun.Nuke/Extensions/NuGetExtension.cs +++ b/ricaun.Nuke/Extensions/NuGetExtension.cs @@ -46,6 +46,21 @@ public static NugetVersionInfo Parse(string packageFileName) /// public static class NuGetExtension { + /// + /// NuGetFileExtension (.nupkg) + /// + public const string NuGetFileExtension = ".nupkg"; + + /// + /// Check if file has NuGet extension (.nupkg) + /// + /// + /// + public static bool IsNuGetFile(string filePath) + { + return Path.GetExtension(filePath).Equals(NuGetFileExtension, StringComparison.InvariantCultureIgnoreCase); + } + /// /// TryGetPackageNameAndVersion /// diff --git a/ricaun.Nuke/Extensions/SignExtension.cs b/ricaun.Nuke/Extensions/SignExtension.cs index c3701bd..7d605f1 100644 --- a/ricaun.Nuke/Extensions/SignExtension.cs +++ b/ricaun.Nuke/Extensions/SignExtension.cs @@ -81,7 +81,7 @@ public static bool CreateCerFile(string fileNamePfx, string passwordPfx, string /// NuGet files use . public static void Sign(string certPath, string certPassword, string filePath) { - if (Path.GetExtension(filePath) == ".nupkg") + if (NuGetExtension.IsNuGetFile(filePath)) { SignNuGet(certPath, certPassword, filePath); return; @@ -167,20 +167,20 @@ public static void SignNuGet(string certPath, string certPassword, string binary } /// - /// Has Signature + /// Has Signature in the file or NuGet /// - /// + /// /// - static bool HasSignature(string fileInfo) + public static bool HasSignature(string filePath) { - if (fileInfo.EndsWith(".nupkg")) + if (NuGetExtension.IsNuGetFile(filePath)) { - return NuGetExtension.NuGetVerifySignatures(fileInfo); + return NuGetExtension.NuGetVerifySignatures(filePath); } try { - System.Security.Cryptography.X509Certificates.X509Certificate.CreateFromSignedFile(fileInfo); + System.Security.Cryptography.X509Certificates.X509Certificate.CreateFromSignedFile(filePath); return true; } catch diff --git a/ricaun.Nuke/Tools/AzureSignToolUtils.cs b/ricaun.Nuke/Tools/AzureSignToolUtils.cs index f7a059f..eeb8eb8 100644 --- a/ricaun.Nuke/Tools/AzureSignToolUtils.cs +++ b/ricaun.Nuke/Tools/AzureSignToolUtils.cs @@ -9,6 +9,7 @@ using Nuke.Common.Tools.DotNet; using Nuke.Common.IO; using Nuke.Common.Tooling; +using ricaun.Nuke.Extensions; namespace ricaun.Nuke.Tools { @@ -19,7 +20,6 @@ public class AzureSignToolUtils { private const string TimestampUrlDefault = "http://timestamp.digicert.com"; private const string TimestampDigestDefault = "sha256"; - private const string NugetPackageExtension = ".nupkg"; /// /// Ensures that Azure Sign Tool and NuGet Key Vault Sign Tool are installed. @@ -112,23 +112,26 @@ public static void DownloadNuGetKeyVaultSignTool() /// /// Signs the specified file using Azure Sign Tool or NuGet Key Vault Sign Tool. /// - /// The name of the file to sign. + /// The name of the file to sign. /// The Azure Key Vault configuration. /// The Azure Key Vault client secret. /// The default timestamp URL. /// The default timestamp digest. - public static void Sign(string fileName, + public static void Sign(string filePath, AzureKeyVaultConfig azureKeyVaultConfig, string azureKeyVaultClientSecret, string timestampUrlDefault = TimestampUrlDefault, string timestampDigestDefault = TimestampDigestDefault) { try { - if (Path.GetExtension(fileName) == NugetPackageExtension) + if (SignExtension.HasSignature(filePath)) + return; + + if (NuGetExtension.IsNuGetFile(filePath)) { DownloadNuGetKeyVaultSignTool(); NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignTool(x => x - .SetFile(fileName) + .SetFile(filePath) .SetKeyVaultCertificateName(azureKeyVaultConfig.AzureKeyVaultCertificate) .SetKeyVaultUrl(azureKeyVaultConfig.AzureKeyVaultUrl) .SetKeyVaultClientId(azureKeyVaultConfig.AzureKeyVaultClientId) @@ -142,7 +145,7 @@ public static void Sign(string fileName, DownloadAzureSignTool(); AzureSignToolTasks.AzureSignTool(x => x - .SetFiles(fileName) + .SetFiles(filePath) .SetKeyVaultCertificateName(azureKeyVaultConfig.AzureKeyVaultCertificate) .SetKeyVaultUrl(azureKeyVaultConfig.AzureKeyVaultUrl) .SetKeyVaultClientId(azureKeyVaultConfig.AzureKeyVaultClientId) @@ -154,7 +157,7 @@ public static void Sign(string fileName, } catch (Exception ex) { - Serilog.Log.Error($"Azure Sign Error: {Path.GetFileName(fileName)} - {ex.Message}"); + Serilog.Log.Error($"Azure Sign Error: {Path.GetFileName(filePath)} - {ex.Message}"); Serilog.Log.Information(ex.ToString()); } } From f9f79a71331db02bd83b143befada972f44e7e6d Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Tue, 17 Dec 2024 16:43:33 -0300 Subject: [PATCH 31/44] Update readme --- README.md | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1b4cc9f..c542d53 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,14 @@ class Build : NukeBuild, IPublishPack ## Environment Variables -### Publish Package Github +### Publish Github + +```yml +env: + GitHubToken: ${{ secrets.GITHUB_TOKEN }} +``` + +### SignFile and SignPassword ```yml env: @@ -60,6 +67,41 @@ env: SignPassword: ${{ secrets.SIGN_PASSWORD }} ``` +`SignFile` could be a `file/url/Base64` to the certificate file. +`SignPassword` is the password to the certificate file. + +#### SignFile using `Azure Key Vault` + +To simplify the configuration to sign with `Azure Key Vault` using the same environment variables are used `SignFile` and `SignPassword`. + +```yml +env: + GitHubToken: ${{ secrets.GITHUB_TOKEN }} + SignFile: ${{ secrets.AZURE_KEY_VAULT_FILE }} + SignPassword: ${{ secrets.AZURE_KEY_VAULT_PASSWORD }} +``` + +##### AZURE_KEY_VAULT_FILE + +The `AZURE_KEY_VAULT_FILE` is a `json` with the base configuration of the certificated in the `Azure Key Vault`: + +```json +{ + "AzureKeyVaultCertificate": "AzureKeyVaultCertificate", + "AzureKeyVaultUrl": "AzureKeyVaultUrl", + "AzureKeyVaultClientId": "AzureKeyVaultClientId", + "AzureKeyVaultTenantId": "AzureKeyVaultTenantId", + "TimestampUrl" : "http://timestamp.digicert.com" + "TimestampDigest" : "sha256" +} +``` + +The `TimestampUrl` and `TimestampDigest` are optional. + +##### AZURE_KEY_VAULT_PASSWORD + +The `AZURE_KEY_VAULT_PASSWORD` is the `AzureKeyVaultClientSecret` of the `Azure Key Vault` certificate. + ### Publish Package Nuget ```yml From 657fd0ff6869ae63e1427af47c3e42e4b1de35c5 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Tue, 17 Dec 2024 16:44:55 -0300 Subject: [PATCH 32/44] Update readme --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 9012c01..35c4b0c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 1.9.0-beta.3 + 1.9.0-beta.4 \ No newline at end of file From f3f443149acf0169b7fbe54193db86f16fed2bb5 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Tue, 17 Dec 2024 17:16:14 -0300 Subject: [PATCH 33/44] Update `HasSignature` to use `PathTooLongUtils` --- CHANGELOG.md | 1 + ricaun.Nuke/Extensions/SignExtension.cs | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae00e06..3c7b768 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Update `TestRunUtil` icons to circle with color. - Update `AzureSignToolUtils` sign to ignore exception. - Update `AzureSignToolUtils` to ignore if file is already signed. +- Update `HasSignature` to use `PathTooLongUtils` to check if file is signed. (Fix: #77) ### Example - Add `Resource` and `Resource.pt-BR` to test sign files. ### Tests diff --git a/ricaun.Nuke/Extensions/SignExtension.cs b/ricaun.Nuke/Extensions/SignExtension.cs index 7d605f1..32a650e 100644 --- a/ricaun.Nuke/Extensions/SignExtension.cs +++ b/ricaun.Nuke/Extensions/SignExtension.cs @@ -180,7 +180,11 @@ public static bool HasSignature(string filePath) try { - System.Security.Cryptography.X509Certificates.X509Certificate.CreateFromSignedFile(filePath); + using (var utils = new PathTooLongUtils.FileMoveToTemp(filePath)) + { + filePath = utils.GetFilePath(); + System.Security.Cryptography.X509Certificates.X509Certificate.CreateFromSignedFile(filePath); + } return true; } catch From 0ff874f3c991fb5406d048ad80347bcfa200b711 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Tue, 17 Dec 2024 17:16:25 -0300 Subject: [PATCH 34/44] Version beta.5 --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 35c4b0c..4b61b75 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 1.9.0-beta.4 + 1.9.0-beta.5 \ No newline at end of file From 087ceebf5ca2319918b26f5e133fda44b7af4aa5 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Tue, 17 Dec 2024 17:54:12 -0300 Subject: [PATCH 35/44] Remove `target` and `Require` --- Build/Build.csproj | 2 -- Build/IAzureSignTool.cs | 13 ------------- CHANGELOG.md | 5 ----- Directory.Build.props | 2 +- ricaun.Nuke/Components/IClean.cs | 12 +----------- ricaun.Nuke/Components/ISign.cs | 4 ---- ricaun.Nuke/build/ricaun.Nuke.targets | 15 --------------- ricaun.Nuke/ricaun.Nuke.csproj | 5 ----- 8 files changed, 2 insertions(+), 56 deletions(-) delete mode 100644 ricaun.Nuke/build/ricaun.Nuke.targets diff --git a/Build/Build.csproj b/Build/Build.csproj index 16ed451..736a54d 100644 --- a/Build/Build.csproj +++ b/Build/Build.csproj @@ -19,6 +19,4 @@ - - diff --git a/Build/IAzureSignTool.cs b/Build/IAzureSignTool.cs index 08fb8c8..5ddaa70 100644 --- a/Build/IAzureSignTool.cs +++ b/Build/IAzureSignTool.cs @@ -1,7 +1,5 @@ using Nuke.Common; using Nuke.Common.Tools.AzureSignTool; -using Nuke.Common.Tools.GitVersion; -using Nuke.Common.Tools.NuGet; using ricaun.Nuke.Components; using ricaun.Nuke.Tools.NuGetKeyVaultSignTool; @@ -10,22 +8,11 @@ public interface IAzureSignTool : IClean, ICompile Target AzureSignTool => _ => _ .TriggeredBy(Clean) .Before(Compile) - //.Requires() - //.Requires() - //.Requires() - //.Requires() .Executes(() => { ricaun.Nuke.Tools.AzureSignToolUtils.EnsureAzureToolIsInstalled(); Serilog.Log.Information(AzureSignToolTasks.AzureSignToolPath); Serilog.Log.Information(NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPath); - - //Serilog.Log.Information("DownloadAzureSignTool"); - //ricaun.Nuke.Tools.AzureSignToolUtils.DownloadNuGetKeyVaultSignTool(); - //Serilog.Log.Information("DownloadNuGetKeyVaultSignTool"); - - //ricaun.Nuke.Tools.AzureSignToolUtils.EnsureAzureToolIsInstalled(); - //Serilog.Log.Information("EnsureAzureToolIsInstalled"); }); } diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c7b768..79305f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,17 +9,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Enable sign files using `Azure Key Vault`. ### Build - Add `IAzureSignTool` to check if `AzureSignToolUtils` is installed. -- [ ] Update `IAzureSignTool` with `Requires`. -- [ ] Add import `build` with `.targets` ### Updates - Add version `Information` in the `CommonExtension`. - Add `AzureSignToolUtils` to sign files using `AzureSignToolTasks` or `NuGetKeyVaultSignToolTasks`. - Add `NuGetKeyVaultSignTool` for nuke version `8.*`. - Add `AzureKeyVaultConfig` with json file with `Azure Key Vault` without secrets. -- [ ] Add `build` with `.targets` to install packages `AzureSignTool` and `NuGetKeyVaultSignTool`. - Add `PackageDownload` to download `AzureSignTool` and `NuGetKeyVaultSignTool` on the fly. -- [ ] Update `IClear` with `CreateTemporaryIgnore`. -- [ ] Update `ISign` with `Requires`. - Add `HttpAuthTasks` to get/post files. - Update `HttpAuthTasks` docs. - Update `IsPathTooLong` to equal or greater than `260`. diff --git a/Directory.Build.props b/Directory.Build.props index 4b61b75..7f50035 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 1.9.0-beta.5 + 1.9.0-beta.6 \ No newline at end of file diff --git a/ricaun.Nuke/Components/IClean.cs b/ricaun.Nuke/Components/IClean.cs index 9a67214..10d32c1 100644 --- a/ricaun.Nuke/Components/IClean.cs +++ b/ricaun.Nuke/Components/IClean.cs @@ -1,5 +1,4 @@ using Nuke.Common; -using Nuke.Common.IO; using ricaun.Nuke.Extensions; namespace ricaun.Nuke.Components @@ -15,16 +14,7 @@ public interface IClean : IHazSolution, INukeBuild Target Clean => _ => _ .Executes(() => { - //CreateTemporaryIgnore(); Solution.ClearSolution(BuildProjectDirectory); }); - - - private void CreateTemporaryIgnore() - { - var tempIgnore = TemporaryDirectory / ".." / ".gitignore"; - if (!tempIgnore.FileExists()) - tempIgnore.WriteAllText("temp"); - } } -} +} \ No newline at end of file diff --git a/ricaun.Nuke/Components/ISign.cs b/ricaun.Nuke/Components/ISign.cs index 3cfe1ca..aa7fd31 100644 --- a/ricaun.Nuke/Components/ISign.cs +++ b/ricaun.Nuke/Components/ISign.cs @@ -1,10 +1,8 @@ using Nuke.Common; using Nuke.Common.IO; using Nuke.Common.ProjectModel; -using Nuke.Common.Tools.AzureSignTool; using Nuke.Common.Utilities.Collections; using ricaun.Nuke.Extensions; -using ricaun.Nuke.Tools.NuGetKeyVaultSignTool; namespace ricaun.Nuke.Components { @@ -18,8 +16,6 @@ public interface ISign : ICompile, IHazSign, IHazSolution, INukeBuild /// Target Sign => _ => _ .TriggeredBy(Compile) - //.Requires() - //.Requires() .Executes(() => { SignProject(MainProject); diff --git a/ricaun.Nuke/build/ricaun.Nuke.targets b/ricaun.Nuke/build/ricaun.Nuke.targets deleted file mode 100644 index 7a10e93..0000000 --- a/ricaun.Nuke/build/ricaun.Nuke.targets +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - $(NoWarn);NU1505 - - - \ No newline at end of file diff --git a/ricaun.Nuke/ricaun.Nuke.csproj b/ricaun.Nuke/ricaun.Nuke.csproj index 535b270..698a957 100644 --- a/ricaun.Nuke/ricaun.Nuke.csproj +++ b/ricaun.Nuke/ricaun.Nuke.csproj @@ -74,9 +74,4 @@ - - - - - From 43c3f104aaeeaa8eece140b2cd0589debca943bf Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Tue, 17 Dec 2024 21:24:03 -0300 Subject: [PATCH 36/44] Enable `IAssetRelease` to release assets before `GitRelease` and `GitPreRelease` --- Build/Build.cs | 16 +++++ CHANGELOG.md | 1 + Directory.Build.props | 2 +- ricaun.Nuke/Components/IAssetRelease.cs | 75 ++++++++++++++++++++++++ ricaun.Nuke/Components/IGitPreRelease.cs | 2 +- ricaun.Nuke/Components/IGitRelease.cs | 22 +++++-- 6 files changed, 111 insertions(+), 7 deletions(-) create mode 100644 ricaun.Nuke/Components/IAssetRelease.cs 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 }; From b9814b7ef7c795528f37fb368725b6647ef73e6c Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Tue, 17 Dec 2024 22:07:10 -0300 Subject: [PATCH 37/44] Add `ILocalAssetRelease` to test `AssetRelease` --- Build/.nuke/build.schema.json | 1 + Build/Build.cs | 19 ++------------ Build/ILocalAssetRelease.cs | 35 +++++++++++++++++++++++++ CHANGELOG.md | 1 + Directory.Build.props | 2 +- ricaun.Nuke/Components/IAssetRelease.cs | 8 +++--- ricaun.Nuke/Components/IGitRelease.cs | 3 ++- 7 files changed, 46 insertions(+), 23 deletions(-) create mode 100644 Build/ILocalAssetRelease.cs diff --git a/Build/.nuke/build.schema.json b/Build/.nuke/build.schema.json index 8eb15af..3fd3e1e 100644 --- a/Build/.nuke/build.schema.json +++ b/Build/.nuke/build.schema.json @@ -31,6 +31,7 @@ "CompileExample", "GitPreRelease", "GitRelease", + "LocalAssetRelease", "Pack", "PrePack", "Release", diff --git a/Build/Build.cs b/Build/Build.cs index 416e3d3..ad8e768 100644 --- a/Build/Build.cs +++ b/Build/Build.cs @@ -3,24 +3,9 @@ using ricaun.Nuke; using ricaun.Nuke.Components; -class AssetRelease : IAssetRelease +class Build : NukeBuild, IPublishPack, ICompileExample, ITest, IShowGitVersion, IAzureSignTool, IPrePack, ILocalAssetRelease { - 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; + IAssetRelease IHazAssetRelease.AssetRelease => new AssetRelease(); //bool IPack.UnlistNuget => true; bool ITest.TestBuildStopWhenFailed => false; public static int Main() => Execute(x => x.From().Build); diff --git a/Build/ILocalAssetRelease.cs b/Build/ILocalAssetRelease.cs new file mode 100644 index 0000000..f46b7a7 --- /dev/null +++ b/Build/ILocalAssetRelease.cs @@ -0,0 +1,35 @@ +using Nuke.Common; +using ricaun.Nuke.Components; +using ricaun.Nuke.Extensions; + +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.Assets) + { + Serilog.Log.Information($"File: {file}"); + } + } +} + +public interface ILocalAssetRelease : IClean, ICompile, IHazAssetRelease +{ + Target LocalAssetRelease => _ => _ + .TriggeredBy(Clean) + .Before(Compile) + .Executes(() => + { + var releaseAssets = new ReleaseAssets + { + Project = MainProject, + Version = "0.0.0", + Notes = "Release Notes", + }; + ReleaseAsset(releaseAssets); + }); +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 90a4fbe..b7b70f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Enable `IAssetRelease` to release assets before `GitRelease` and `GitPreRelease`. ### Build - Add `IAzureSignTool` to check if `AzureSignToolUtils` is installed. +- Add `ILocalAssetRelease` to test `AssetRelease` assets before release. ### Updates - Add version `Information` in the `CommonExtension`. - Add `AzureSignToolUtils` to sign files using `AzureSignToolTasks` or `NuGetKeyVaultSignToolTasks`. diff --git a/Directory.Build.props b/Directory.Build.props index 9479514..8a7aec6 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 1.9.0-beta.7 + 1.9.0-beta.8 \ No newline at end of file diff --git a/ricaun.Nuke/Components/IAssetRelease.cs b/ricaun.Nuke/Components/IAssetRelease.cs index f2a248e..dc0499c 100644 --- a/ricaun.Nuke/Components/IAssetRelease.cs +++ b/ricaun.Nuke/Components/IAssetRelease.cs @@ -1,7 +1,7 @@ -using Nuke.Common.IO; +using Nuke.Common; +using Nuke.Common.IO; using Nuke.Common.ProjectModel; using ricaun.Nuke.IO; -using System.Collections.Generic; namespace ricaun.Nuke.Components { @@ -28,7 +28,7 @@ public class ReleaseAssets /// /// Gets the collection of zip files to be released. /// - public IReadOnlyCollection Files { get; init; } + public AbsolutePath[] Assets { get; init; } = new AbsolutePath[] { }; /// /// Gets a value indicating whether the release is a prerelease. @@ -54,7 +54,7 @@ public void ReleaseAsset(ReleaseAssets releaseAssets) { if (AssetRelease is IAssetRelease assetRelease) { - Serilog.Log.Information($"Asset Release {assetRelease}"); + Serilog.Log.Information($"ReleaseAsset: {assetRelease}"); assetRelease.ReleaseAsset(releaseAssets); } } diff --git a/ricaun.Nuke/Components/IGitRelease.cs b/ricaun.Nuke/Components/IGitRelease.cs index 7106e80..8492a0a 100644 --- a/ricaun.Nuke/Components/IGitRelease.cs +++ b/ricaun.Nuke/Components/IGitRelease.cs @@ -7,6 +7,7 @@ using ricaun.Nuke.Extensions; using System; using System.IO; +using System.Linq; namespace ricaun.Nuke.Components { @@ -80,7 +81,7 @@ void ReleaseGitHubProject(Project project, bool releaseAsPrerelease = false) Project = project, Version = version, Notes = releaseNotes, - Files = releaseFiles, + Assets = releaseFiles.ToArray(), Prerelease = releaseAsPrerelease }; From a395540b75fe64562b35598e3326a3d8ca3aca71 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Wed, 18 Dec 2024 12:10:03 -0300 Subject: [PATCH 38/44] Update `ci` --- .github/workflows/Build.yml | 4 ++-- Directory.Build.props | 2 +- README.md | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 4985a51..3918b90 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -29,5 +29,5 @@ jobs: # SignFile: ${{ secrets.SIGN_FILE }} # SignPassword: ${{ secrets.SIGN_PASSWORD }} - SignFile: ${{ secrets.AZURE_KEY_VAULT_FILE }} - SignPassword: ${{ secrets.AZURE_KEY_VAULT_PASSWORD }} \ No newline at end of file + SignFile: ${{ secrets.SIGN_FILE_AZURE }} + SignPassword: ${{ secrets.SIGN_PASSWORD_AZURE }} \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props index 8a7aec6..e3fb86e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 1.9.0-beta.8 + 1.9.0-beta.9 \ No newline at end of file diff --git a/README.md b/README.md index c542d53..f164c83 100644 --- a/README.md +++ b/README.md @@ -77,13 +77,13 @@ To simplify the configuration to sign with `Azure Key Vault` using the same envi ```yml env: GitHubToken: ${{ secrets.GITHUB_TOKEN }} - SignFile: ${{ secrets.AZURE_KEY_VAULT_FILE }} - SignPassword: ${{ secrets.AZURE_KEY_VAULT_PASSWORD }} + SignFile: ${{ secrets.SIGN_FILE_AZURE }} + SignPassword: ${{ secrets.SIGN_PASSWORD_AZURE }} ``` -##### AZURE_KEY_VAULT_FILE +##### SIGN_FILE_AZURE -The `AZURE_KEY_VAULT_FILE` is a `json` with the base configuration of the certificated in the `Azure Key Vault`: +The `SIGN_FILE_AZURE` is a `json` with the base configuration of the certificated in the `Azure Key Vault`: ```json { @@ -98,9 +98,9 @@ The `AZURE_KEY_VAULT_FILE` is a `json` with the base configuration of the certif The `TimestampUrl` and `TimestampDigest` are optional. -##### AZURE_KEY_VAULT_PASSWORD +##### SIGN_PASSWORD_AZURE -The `AZURE_KEY_VAULT_PASSWORD` is the `AzureKeyVaultClientSecret` of the `Azure Key Vault` certificate. +The `SIGN_PASSWORD_AZURE` is the `AzureKeyVaultClientSecret` of the `Azure Key Vault` certificate. ### Publish Package Nuget From 8c36f4c0421d168c732c978959f183ea8ec96363 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Wed, 18 Dec 2024 15:45:02 -0300 Subject: [PATCH 39/44] Enable `SkipForked` --- Build/.nuke/build.schema.json | 3 + Build/IShowGitVersion.cs | 21 +++- CHANGELOG.md | 1 + Directory.Build.props | 2 +- .../ricaun.Nuke.Example.Tests.csproj | 2 +- ricaun.Nuke/Components/IGitPreRelease.cs | 1 + ricaun.Nuke/Components/IGitRelease.cs | 1 + ricaun.Nuke/Components/IHazGitRepository.cs | 117 +++++++++++------- ricaun.Nuke/Components/IPack.cs | 1 + ricaun.Nuke/Components/IPrePack.cs | 1 + ricaun.Nuke/Extensions/GitHubExtension.cs | 22 ++++ 11 files changed, 124 insertions(+), 48 deletions(-) diff --git a/Build/.nuke/build.schema.json b/Build/.nuke/build.schema.json index 3fd3e1e..9454c2f 100644 --- a/Build/.nuke/build.schema.json +++ b/Build/.nuke/build.schema.json @@ -111,6 +111,9 @@ "allOf": [ { "properties": { + "EnableForkedRepository": { + "type": "boolean" + }, "Folder": { "type": "string" }, diff --git a/Build/IShowGitVersion.cs b/Build/IShowGitVersion.cs index 490251e..c76782c 100644 --- a/Build/IShowGitVersion.cs +++ b/Build/IShowGitVersion.cs @@ -1,8 +1,9 @@ using Nuke.Common; +using Nuke.Common.Git; using ricaun.Nuke.Components; using ricaun.Nuke.Extensions; -public interface IShowGitVersion : IHazGitVersion, IHazChangelog, IClean, ICompile +public interface IShowGitVersion : IHazGitVersion, IHazGitRepository, IHazChangelog, IClean, ICompile { Target ShowGitVersion => _ => _ .TriggeredBy(Clean) @@ -23,5 +24,23 @@ public interface IShowGitVersion : IHazGitVersion, IHazChangelog, IClean, ICompi System.IO.Path.Combine(BuildAssemblyDirectory, $"latest.json")); } catch { } + + + Serilog.Log.Information("Commit = {Value}", GitRepository.Commit); + Serilog.Log.Information("Branch = {Value}", GitRepository.Branch); + Serilog.Log.Information("Tags = {Value}", GitRepository.Tags); + Serilog.Log.Information("Head = {Value}", GitRepository.Head); + Serilog.Log.Information("Identifier = {Value}", GitRepository.Identifier); + + Serilog.Log.Information("IsForked = {Value}", GitRepository.IsForked()); + + Serilog.Log.Information("main branch = {Value}", GitRepository.IsOnMainBranch()); + Serilog.Log.Information("main/master branch = {Value}", GitRepository.IsOnMainOrMasterBranch()); + Serilog.Log.Information("release/* branch = {Value}", GitRepository.IsOnReleaseBranch()); + Serilog.Log.Information("hotfix/* branch = {Value}", GitRepository.IsOnHotfixBranch()); + + Serilog.Log.Information("Https URL = {Value}", GitRepository.HttpsUrl); + Serilog.Log.Information("SSH URL = {Value}", GitRepository.SshUrl); + }); } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index b7b70f8..c35d0d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Features - Enable sign files using `Azure Key Vault`. - Enable `IAssetRelease` to release assets before `GitRelease` and `GitPreRelease`. +- Enable `SkipForked` to skip release if forked repository. ### Build - Add `IAzureSignTool` to check if `AzureSignToolUtils` is installed. - Add `ILocalAssetRelease` to test `AssetRelease` assets before release. diff --git a/Directory.Build.props b/Directory.Build.props index e3fb86e..787c5a1 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 1.9.0-beta.9 + 1.9.0-rc \ No newline at end of file diff --git a/ricaun.Nuke.Example.Tests/ricaun.Nuke.Example.Tests.csproj b/ricaun.Nuke.Example.Tests/ricaun.Nuke.Example.Tests.csproj index 544eff1..90fdb2a 100644 --- a/ricaun.Nuke.Example.Tests/ricaun.Nuke.Example.Tests.csproj +++ b/ricaun.Nuke.Example.Tests/ricaun.Nuke.Example.Tests.csproj @@ -14,7 +14,7 @@ - net7.0 + net8.0 diff --git a/ricaun.Nuke/Components/IGitPreRelease.cs b/ricaun.Nuke/Components/IGitPreRelease.cs index 6d8d69a..bd6d1fc 100644 --- a/ricaun.Nuke/Components/IGitPreRelease.cs +++ b/ricaun.Nuke/Components/IGitPreRelease.cs @@ -38,6 +38,7 @@ public bool HasPreReleaseFilter(string version) .OnlyWhenStatic(() => GitHubToken.SkipEmpty()) .OnlyWhenStatic(() => IsServerBuild) .OnlyWhenDynamic(() => GitRepository.IsOnDevelopBranch()) + .OnlyWhenDynamic(() => SkipForked()) .Executes(() => { var project = MainProject; diff --git a/ricaun.Nuke/Components/IGitRelease.cs b/ricaun.Nuke/Components/IGitRelease.cs index 8492a0a..e636af6 100644 --- a/ricaun.Nuke/Components/IGitRelease.cs +++ b/ricaun.Nuke/Components/IGitRelease.cs @@ -26,6 +26,7 @@ public interface IGitRelease : IRelease, IHazGitRepository, IHazGitVersion, IHaz .OnlyWhenStatic(() => GitHubToken.SkipEmpty()) .OnlyWhenStatic(() => IsServerBuild) .OnlyWhenDynamic(() => GitRepository.IsOnMainOrMasterBranch()) + .OnlyWhenDynamic(() => SkipForked()) .Executes(() => { var project = MainProject; diff --git a/ricaun.Nuke/Components/IHazGitRepository.cs b/ricaun.Nuke/Components/IHazGitRepository.cs index dfc25a0..82892f3 100644 --- a/ricaun.Nuke/Components/IHazGitRepository.cs +++ b/ricaun.Nuke/Components/IHazGitRepository.cs @@ -1,45 +1,72 @@ -using Nuke.Common; -using Nuke.Common.Git; - -namespace ricaun.Nuke.Components -{ - /// - /// IHazGitRepository - /// - public interface IHazGitRepository : INukeBuild - { - /// - /// GitHubToken - /// - [Secret][Parameter] public string GitHubToken => TryGetValue(() => GitHubToken); - - /// - /// GitRepository - /// - [GitRepository] GitRepository GitRepository => TryGetValue(() => GitRepository); - - /// - /// GetGitRepositoryPackageUrl (default: https://nuget.pkg.github.com/repository_owner/index.json) - /// - /// - public string GetGitRepositoryPackageUrl() - { - if (GitRepository == null) - { - Serilog.Log.Warning($"GitRepository not found."); - return ""; - } - return $@"https://nuget.pkg.github.com/{GetGitRepositoryOwner()}/index.json"; - } - - /// - /// GetGitRepositoryOwner based on the GitRepository.Identifier - /// - /// - public string GetGitRepositoryOwner() - { - if (GitRepository == null) return ""; - return GitRepository.Identifier?.Split("/")[0]; - } - } -} +using Nuke.Common; +using Nuke.Common.Git; +using ricaun.Nuke.Extensions; + +namespace ricaun.Nuke.Components +{ + /// + /// IHazGitRepository + /// + public interface IHazGitRepository : INukeBuild + { + /// + /// GitHubToken + /// + [Secret][Parameter] public string GitHubToken => TryGetValue(() => GitHubToken); + + /// + /// GitRepository + /// + [GitRepository] GitRepository GitRepository => TryGetValue(() => GitRepository); + + /// + /// GetGitRepositoryPackageUrl (default: https://nuget.pkg.github.com/repository_owner/index.json) + /// + /// + public string GetGitRepositoryPackageUrl() + { + if (GitRepository == null) + { + Serilog.Log.Warning($"GitRepository not found."); + return ""; + } + return $@"https://nuget.pkg.github.com/{GetGitRepositoryOwner()}/index.json"; + } + + /// + /// GetGitRepositoryOwner based on the GitRepository.Identifier + /// + /// + public string GetGitRepositoryOwner() + { + if (GitRepository == null) return ""; + return GitRepository.Identifier?.Split("/")[0]; + } + + /// + /// Indicates whether the forked repository is enabled. + /// + [Parameter] + bool EnableForkedRepository => TryGetValue(() => EnableForkedRepository) ?? false; + + /// + /// Determines if the forked repository should be skipped. + /// + /// True if the forked repository should be skipped; otherwise, false. + public bool SkipForked() + { + if (EnableForkedRepository) + return false; + + return IsGitRepositoryForked(); + } + /// + /// IsGitRepositoryForked + /// + /// + public bool IsGitRepositoryForked() + { + return GitRepository.IsForked(); + } + } +} diff --git a/ricaun.Nuke/Components/IPack.cs b/ricaun.Nuke/Components/IPack.cs index ba16b7c..f2ab5ba 100644 --- a/ricaun.Nuke/Components/IPack.cs +++ b/ricaun.Nuke/Components/IPack.cs @@ -29,6 +29,7 @@ public interface IPack : IHazPack, IGitRelease .OnlyWhenStatic(() => NugetApiKey.SkipEmpty()) .OnlyWhenStatic(() => IsServerBuild) .OnlyWhenDynamic(() => GitRepository.IsOnMainOrMasterBranch()) + .OnlyWhenDynamic(() => SkipForked()) .Executes(() => { var releaseDirectory = GetReleaseDirectory(MainProject); diff --git a/ricaun.Nuke/Components/IPrePack.cs b/ricaun.Nuke/Components/IPrePack.cs index 84e2e78..a7b9718 100644 --- a/ricaun.Nuke/Components/IPrePack.cs +++ b/ricaun.Nuke/Components/IPrePack.cs @@ -24,6 +24,7 @@ public interface IPrePack : IPack, IGitPreRelease .OnlyWhenStatic(() => NugetApiKey.SkipEmpty()) .OnlyWhenStatic(() => IsServerBuild) .OnlyWhenDynamic(() => GitRepository.IsOnDevelopBranch()) + .OnlyWhenDynamic(() => SkipForked()) .Executes(() => { var version = MainProject.GetInformationalVersion(); diff --git a/ricaun.Nuke/Extensions/GitHubExtension.cs b/ricaun.Nuke/Extensions/GitHubExtension.cs index a54c463..aec2e67 100644 --- a/ricaun.Nuke/Extensions/GitHubExtension.cs +++ b/ricaun.Nuke/Extensions/GitHubExtension.cs @@ -1,4 +1,5 @@ using Nuke.Common; +using Nuke.Common.Git; using Nuke.Common.IO; using Nuke.Common.Tools.GitHub; using Octokit; @@ -14,6 +15,27 @@ namespace ricaun.Nuke.Extensions /// public static class GitHubExtension { + /// + /// Determines whether the specified Git repository is a fork. + /// + /// The Git repository to check. + /// + /// true if the specified Git repository is a fork; otherwise, false. + /// + public static bool IsForked(this GitRepository gitRepository) + { + if (gitRepository is null) + return false; + + var gitHubOwner = gitRepository.GetGitHubOwner(); + var gitHubName = gitRepository.GetGitHubName(); + var repository = GitHubTasks.GitHubClient.Repository + .Get(gitHubOwner, gitHubName) + .Result; + + return repository.Fork; + } + #region GitHubUtil /// /// Check if Tags already exists. From 0b5729b6588f844499725cd834bf7da9a26c0338 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Wed, 18 Dec 2024 15:59:40 -0300 Subject: [PATCH 40/44] Fix `SkipForked` --- ricaun.Nuke/Components/IHazGitRepository.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ricaun.Nuke/Components/IHazGitRepository.cs b/ricaun.Nuke/Components/IHazGitRepository.cs index 82892f3..6347900 100644 --- a/ricaun.Nuke/Components/IHazGitRepository.cs +++ b/ricaun.Nuke/Components/IHazGitRepository.cs @@ -58,7 +58,10 @@ public bool SkipForked() if (EnableForkedRepository) return false; - return IsGitRepositoryForked(); + if (IsGitRepositoryForked()) + return true; + + return false; } /// /// IsGitRepositoryForked From 130ecc94059e76a5bb7a061ea5b4c707e078b5a7 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Wed, 18 Dec 2024 16:05:51 -0300 Subject: [PATCH 41/44] Invert `SkipForked` --- ricaun.Nuke/Components/IHazGitRepository.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ricaun.Nuke/Components/IHazGitRepository.cs b/ricaun.Nuke/Components/IHazGitRepository.cs index 6347900..85572f9 100644 --- a/ricaun.Nuke/Components/IHazGitRepository.cs +++ b/ricaun.Nuke/Components/IHazGitRepository.cs @@ -52,16 +52,16 @@ public string GetGitRepositoryOwner() /// /// Determines if the forked repository should be skipped. /// - /// True if the forked repository should be skipped; otherwise, false. + /// False if the forked repository should be skipped; otherwise, true. public bool SkipForked() { if (EnableForkedRepository) - return false; + return true; if (IsGitRepositoryForked()) - return true; + return false; - return false; + return true; } /// /// IsGitRepositoryForked From 8790658fcbbe44f65f3e47dea307eba5089d6a49 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Wed, 18 Dec 2024 17:17:33 -0300 Subject: [PATCH 42/44] Update `IsForked` --- Directory.Build.props | 2 +- ricaun.Nuke/Extensions/GitHubExtension.cs | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 787c5a1..a5d5f12 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 1.9.0-rc + 1.9.0-rc.1 \ No newline at end of file diff --git a/ricaun.Nuke/Extensions/GitHubExtension.cs b/ricaun.Nuke/Extensions/GitHubExtension.cs index aec2e67..964da5c 100644 --- a/ricaun.Nuke/Extensions/GitHubExtension.cs +++ b/ricaun.Nuke/Extensions/GitHubExtension.cs @@ -27,13 +27,21 @@ public static bool IsForked(this GitRepository gitRepository) if (gitRepository is null) return false; - var gitHubOwner = gitRepository.GetGitHubOwner(); - var gitHubName = gitRepository.GetGitHubName(); - var repository = GitHubTasks.GitHubClient.Repository - .Get(gitHubOwner, gitHubName) - .Result; + try + { + var gitHubOwner = gitRepository.GetGitHubOwner(); + var gitHubName = gitRepository.GetGitHubName(); + var repository = GitHubTasks.GitHubClient.Repository + .Get(gitHubOwner, gitHubName) + .Result; - return repository.Fork; + return repository.Fork; + } + catch + { + // Private repository is not forked. + return false; + } } #region GitHubUtil From 9c45e7962b660efc015f894e3437188d5ead2b83 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Wed, 18 Dec 2024 20:46:01 -0300 Subject: [PATCH 43/44] Update `ExecuteReleaseAsset` to execute `IHazAssetRelease` and build with `IAssetRelease` --- Build/Build.cs | 1 + Build/ILocalAssetRelease.cs | 4 ++-- CHANGELOG.md | 1 + Directory.Build.props | 2 +- ricaun.Nuke/Components/IAssetRelease.cs | 7 ++++++- ricaun.Nuke/Components/IGitRelease.cs | 2 +- 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Build/Build.cs b/Build/Build.cs index ad8e768..76c5658 100644 --- a/Build/Build.cs +++ b/Build/Build.cs @@ -5,6 +5,7 @@ class Build : NukeBuild, IPublishPack, ICompileExample, ITest, IShowGitVersion, IAzureSignTool, IPrePack, ILocalAssetRelease { + public void ReleaseAsset(ReleaseAssets releaseAssets) { } IAssetRelease IHazAssetRelease.AssetRelease => new AssetRelease(); //bool IPack.UnlistNuget => true; bool ITest.TestBuildStopWhenFailed => false; diff --git a/Build/ILocalAssetRelease.cs b/Build/ILocalAssetRelease.cs index f46b7a7..197fcc6 100644 --- a/Build/ILocalAssetRelease.cs +++ b/Build/ILocalAssetRelease.cs @@ -17,7 +17,7 @@ public void ReleaseAsset(ReleaseAssets releaseAssets) } } -public interface ILocalAssetRelease : IClean, ICompile, IHazAssetRelease +public interface ILocalAssetRelease : IClean, ICompile, IHazAssetRelease, IAssetRelease { Target LocalAssetRelease => _ => _ .TriggeredBy(Clean) @@ -30,6 +30,6 @@ public interface ILocalAssetRelease : IClean, ICompile, IHazAssetRelease Version = "0.0.0", Notes = "Release Notes", }; - ReleaseAsset(releaseAssets); + ExecuteReleaseAsset(releaseAssets); }); } diff --git a/CHANGELOG.md b/CHANGELOG.md index c35d0d8..657dd21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Update `AzureSignToolUtils` sign to ignore exception. - Update `AzureSignToolUtils` to ignore if file is already signed. - Update `HasSignature` to use `PathTooLongUtils` to check if file is signed. (Fix: #77) +- Update `ExecuteReleaseAsset` to execute `IHazAssetRelease` and build with `IAssetRelease` ### Example - Add `Resource` and `Resource.pt-BR` to test sign files. ### Tests diff --git a/Directory.Build.props b/Directory.Build.props index a5d5f12..8808b33 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 1.9.0-rc.1 + 1.9.0-rc.2 \ No newline at end of file diff --git a/ricaun.Nuke/Components/IAssetRelease.cs b/ricaun.Nuke/Components/IAssetRelease.cs index dc0499c..bb09f3d 100644 --- a/ricaun.Nuke/Components/IAssetRelease.cs +++ b/ricaun.Nuke/Components/IAssetRelease.cs @@ -50,13 +50,18 @@ public interface IHazAssetRelease /// Releases the specified assets. /// /// The assets to be released. - public void ReleaseAsset(ReleaseAssets releaseAssets) + public void ExecuteReleaseAsset(ReleaseAssets releaseAssets) { if (AssetRelease is IAssetRelease assetRelease) { Serilog.Log.Information($"ReleaseAsset: {assetRelease}"); assetRelease.ReleaseAsset(releaseAssets); } + if (this is IAssetRelease buildAssetRelease) + { + Serilog.Log.Information($"ReleaseAsset: {buildAssetRelease}"); + buildAssetRelease.ReleaseAsset(releaseAssets); + } } } diff --git a/ricaun.Nuke/Components/IGitRelease.cs b/ricaun.Nuke/Components/IGitRelease.cs index e636af6..760158d 100644 --- a/ricaun.Nuke/Components/IGitRelease.cs +++ b/ricaun.Nuke/Components/IGitRelease.cs @@ -86,7 +86,7 @@ void ReleaseGitHubProject(Project project, bool releaseAsPrerelease = false) Prerelease = releaseAsPrerelease }; - ReleaseAsset(releaseAssets); + ExecuteReleaseAsset(releaseAssets); var newRelease = new Octokit.NewRelease(version) { From 186a0b6c24230b96f423e8459c0828970a5eb5ad Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Thu, 19 Dec 2024 10:51:51 -0300 Subject: [PATCH 44/44] Version 1.9.0 --- CHANGELOG.md | 2 +- Directory.Build.props | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 657dd21..258cd60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [1.9.0] / 2024-12-06 +## [1.9.0] / 2024-12-06 - 2024-12-19 ### Features - Enable sign files using `Azure Key Vault`. - Enable `IAssetRelease` to release assets before `GitRelease` and `GitPreRelease`. diff --git a/Directory.Build.props b/Directory.Build.props index 8808b33..3af54d3 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 1.9.0-rc.2 + 1.9.0 \ No newline at end of file