Skip to content

Commit

Permalink
Merge pull request #68 from ricaun-io/develop
Browse files Browse the repository at this point in the history
Version 1.7.2
  • Loading branch information
ricaun authored Nov 19, 2023
2 parents 6feb0c3 + 66beaab commit cc877b4
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 31 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ 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.7.2] / 2023-10-05 - 2023-11-18
### Features
- Enable `SignBinary` with `PathTooLong` path.
### Updated
- Create `PathTooLongUtils` to prevent `PathTooLongException`
### Fix
- Add `+` split with fix `GetInformationalVersion` with `+` in version. (Fix: #67)

## [1.7.1] / 2023-10-05
### Features
- Prerelease Nuget force to unlist.
Expand Down Expand Up @@ -319,6 +327,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- First Release

[vNext]: ../../compare/1.0.0...HEAD
[1.7.2]: ../../compare/1.7.1...1.7.2
[1.7.1]: ../../compare/1.7.0...1.7.1
[1.7.0]: ../../compare/1.6.1...1.7.0
[1.6.1]: ../../compare/1.6.0...1.6.1
Expand Down
2 changes: 1 addition & 1 deletion ricaun.Nuke/Extensions/AssemblyExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static bool IsVersionPreRelease(this Project project)
/// </summary>
/// <param name="project"></param>
/// <returns></returns>
public static string GetInformationalVersion(this Project project) => project.GetFileVersionInfo()?.ProductVersion;
public static string GetInformationalVersion(this Project project) => project.GetFileVersionInfo()?.ProductVersion.Split('+').First();

/// <summary>
/// GetCompany => CompanyName
Expand Down
80 changes: 80 additions & 0 deletions ricaun.Nuke/Extensions/PathTooLongUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.IO;

namespace ricaun.Nuke.Extensions
{
/// <summary>
/// PathTooLongUtils
/// </summary>
public class PathTooLongUtils
{
/// <summary>
/// MAX_PATH
/// </summary>
public const int MAX_PATH = 260;
/// <summary>
/// FileMoveToTempUtils
/// </summary>
public class FileMoveToTemp : IDisposable
{
private readonly string filePath;
private string tempFilePath;
/// <summary>
/// FileMoveToTempUtils
/// </summary>
/// <param name="filePath"></param>
public FileMoveToTemp(string filePath)
{
this.filePath = filePath;
Initialize();
}

private void Initialize()
{
if (IsPathTooLong())
{
tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetFileName(this.filePath));
File.Move(this.filePath, tempFilePath, true);
}
}

/// <summary>
/// GetFilePathLong
/// </summary>
/// <returns></returns>
public int GetFilePathLong()
{
return GetFilePath().Length;
}

/// <summary>
/// Check if path is too long
/// </summary>
/// <returns></returns>
public bool IsPathTooLong()
{
return GetFilePathLong() > MAX_PATH;
}

/// <summary>
/// GetFilePath
/// </summary>
/// <returns></returns>
public string GetFilePath()
{
return tempFilePath ?? filePath;
}

/// <summary>
/// Dispose
/// </summary>
public void Dispose()
{
if (tempFilePath is null)
return;

File.Move(tempFilePath, filePath, true);
}
}
}
}
61 changes: 32 additions & 29 deletions ricaun.Nuke/Extensions/SignExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public static bool CreateCerFile(string fileNamePfx, string passwordPfx, string
if (File.Exists(cert)) return true;
return CreateCertificatesCer(fileNamePfx, passwordPfx, cert);
}

/// <summary>
/// https://github.com/DataDog/dd-trace-dotnet/blob/master/tracer/build/_build/Build.Gitlab.cs
/// </summary>
Expand All @@ -80,44 +79,48 @@ public static bool CreateCerFile(string fileNamePfx, string passwordPfx, string
/// <param name="binaryPath"></param>
public static void SignBinary(string certPath, string certPassword, string binaryPath)
{
if (binaryPath.Length > 260)
using (var utils = new PathTooLongUtils.FileMoveToTemp(binaryPath))
{
var messageError = $"FilePath.Length to big: {binaryPath}";
Serilog.Log.Error(messageError);
throw new PathTooLongException(messageError);
}
var filePath = utils.GetFilePath();
if (utils.IsPathTooLong())
{
var messageError = $"FilePath.Length too long: {filePath}";
Serilog.Log.Error(messageError);
throw new PathTooLongException(messageError);
}

if (HasSignature(binaryPath)) return;
if (HasSignature(filePath)) return;

Serilog.Log.Information($"Signing: {binaryPath}");
Serilog.Log.Information($"Signing [{utils.GetFilePathLong()}]: {filePath}");

if (!SignToolTasks.SignToolPath.SkipEmpty())
{
Serilog.Log.Error($"SignToolPath is not found, set SIGNTOOL_EXE enviroment variable path... {SignToolTasks.SignToolPath}");
return;
}

foreach (var timestampServer in timestampServers)
{
try
if (!SignToolTasks.SignToolPath.SkipEmpty())
{
SignToolTasks.SignTool(x => x
.SetFiles(binaryPath)
.SetFile(certPath)
.SetPassword(certPassword)
.SetTimestampServerUrl(timestampServer)
.SetFileDigestAlgorithm(SignToolDigestAlgorithm.SHA256)
.EnableQuiet()
);
Serilog.Log.Information($"Signing done with {timestampServer}");
Serilog.Log.Error($"SignToolPath is not found, set SIGNTOOL_EXE enviroment variable path... {SignToolTasks.SignToolPath}");
return;
}
catch (Exception)

foreach (var timestampServer in timestampServers)
{
Serilog.Log.Warning($"Failed to sign file with {timestampServer}");
try
{
SignToolTasks.SignTool(x => x
.SetFiles(filePath)
.SetFile(certPath)
.SetPassword(certPassword)
.SetTimestampServerUrl(timestampServer)
.SetFileDigestAlgorithm(SignToolDigestAlgorithm.SHA256)
.EnableQuiet()
);
Serilog.Log.Information($"Signing done with {timestampServer}");
return;
}
catch (Exception)
{
Serilog.Log.Warning($"Failed to sign file with {timestampServer}");
}
}
Serilog.Log.Error($"Failed to sign file {filePath}");
}
Serilog.Log.Error($"Failed to sign file {binaryPath}");
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion ricaun.Nuke/ricaun.Nuke.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<PropertyGroup>
<PackageId>ricaun.Nuke</PackageId>
<Version>1.7.1</Version>
<Version>1.7.2</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down

0 comments on commit cc877b4

Please sign in to comment.