Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 1.9.2 #81

Merged
merged 11 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
env:
GitHubToken: ${{ secrets.GITHUB_TOKEN }}

NugetApiUrl: ${{ secrets.NUGET_API_URL }}
NugetApiKey: ${{ secrets.NUGET_API_KEY }}
NuGetApiUrl: ${{ secrets.NUGET_API_URL }}
NuGetApiKey: ${{ secrets.NUGET_API_KEY }}

SignFile: ${{ secrets.SIGN_FILE }}
SignPassword: ${{ secrets.SIGN_PASSWORD }}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ 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.2] / 2025-01-19
### Updated
- Add `NuGetTasks` delete, sign and verify.
- Rename `NuGetApiUrl`, `NuGetApiKey` and `UnlistNuGet`.
### Fixed
- Fix `HttpAuthTasks` dispose file stream in `CreateFormDataContent`.

## [1.9.1] / 2025-01-03
### Updated
- Force to uninstall local `Tools` to remove cache when `.exe` is not found. (Fix: #79)
Expand Down Expand Up @@ -393,6 +400,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.2]: ../../compare/1.9.1...1.9.2
[1.9.1]: ../../compare/1.9.0...1.9.1
[1.9.0]: ../../compare/1.8.2...1.9.0
[1.8.2]: ../../compare/1.8.1...1.8.2
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>1.9.1</Version>
<Version>1.9.2</Version>
</PropertyGroup>
</Project>
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This package is to simplify the build automation system using [Nuke.Common](https://www.nuget.org/packages/Nuke.Common/).

[![Visual Studio 2022](https://img.shields.io/badge/Visual%20Studio-2022-blue)](../..)
[![Visual Studio 2022](https://img.shields.io/badge/Visual%20Studio-2022-blue)](https://github.com/ricaun-io/ricaun.Nuke)
[![Nuke](https://img.shields.io/badge/Nuke-Build-blue)](https://nuke.build/)
[![License MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![Build](https://github.com/ricaun-io/ricaun.Nuke/actions/workflows/Build.yml/badge.svg)](https://github.com/ricaun-io/ricaun.Nuke/actions)
Expand Down Expand Up @@ -102,15 +102,15 @@ The `TimestampUrl` and `TimestampDigest` are optional.

The `SIGN_PASSWORD_AZURE` is the `AzureKeyVaultClientSecret` of the `Azure Key Vault` certificate.

### Publish Package Nuget
### Publish Package NuGet

```yml
env:
GitHubToken: ${{ secrets.GITHUB_TOKEN }}
SignFile: ${{ secrets.SIGN_FILE }}
SignPassword: ${{ secrets.SIGN_PASSWORD }}
NugetApiUrl: ${{ secrets.NUGET_API_URL }}
NugetApiKey: ${{ secrets.NUGET_API_KEY }}
NuGetApiUrl: ${{ secrets.NUGET_API_URL }}
NuGetApiKey: ${{ secrets.NUGET_API_KEY }}
```

# Build.cs - ITest
Expand Down
14 changes: 7 additions & 7 deletions ricaun.Nuke/Components/IHazPack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ namespace ricaun.Nuke.Components
public interface IHazPack : IHazGitRepository, INukeBuild
{
/// <summary>
/// NugetApiUrl
/// NuGetApiUrl
/// </summary>
[Secret][Parameter] public string NugetApiUrl => TryGetValue(() => NugetApiUrl) ?? GetGitRepositoryPackageUrl();
[Secret][Parameter] public string NuGetApiUrl => TryGetValue(() => NuGetApiUrl) ?? GetGitRepositoryPackageUrl();
/// <summary>
/// NugetApiKey
/// NuGetApiKey
/// </summary>
[Secret][Parameter] public string NugetApiKey => TryGetValue(() => NugetApiKey) ?? GitHubToken;
[Secret][Parameter] public string NuGetApiKey => TryGetValue(() => NuGetApiKey) ?? GitHubToken;

/// <summary>
/// DotNetNuGetPush
/// </summary>
/// <param name="packageFilePath"></param>
void DotNetNuGetPush(AbsolutePath packageFilePath)
{
NuGetExtension.DotNetNuGetPush(NugetApiUrl, NugetApiKey, packageFilePath);
NuGetExtension.DotNetNuGetPush(NuGetApiUrl, NuGetApiKey, packageFilePath);
}

/// <summary>
Expand All @@ -35,8 +35,8 @@ void DotNetNuGetPush(AbsolutePath packageFilePath)
void DotNetNuGetPrerelease(AbsolutePath packageFilePath)
{
var packageNameVersion = packageFilePath.Name;
NuGetExtension.DotNetNuGetPush(NugetApiUrl, NugetApiKey, packageFilePath);
NuGetExtension.NuGetUnlist(NugetApiUrl, NugetApiKey, packageNameVersion);
NuGetExtension.DotNetNuGetPush(NuGetApiUrl, NuGetApiKey, packageFilePath);
NuGetExtension.NuGetUnlist(NuGetApiUrl, NuGetApiKey, packageNameVersion);
}

/// <summary>
Expand Down
10 changes: 5 additions & 5 deletions ricaun.Nuke/Components/IPack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ namespace ricaun.Nuke.Components
public interface IPack : IHazPack, IGitRelease
{
/// <summary>
/// UnlistNuget (Default: false)
/// UnlistNuGet (Default: false)
/// </summary>
/// <remarks>This feature only works on 'api.nuget.org' to unlist package.</remarks>
[Parameter]
bool UnlistNuget => TryGetValue<bool?>(() => UnlistNuget) ?? false;
bool UnlistNuGet => TryGetValue<bool?>(() => UnlistNuGet) ?? false;

/// <summary>
/// Target Pack
/// </summary>
Target Pack => _ => _
.TriggeredBy(Release)
.After(GitRelease)
.OnlyWhenStatic(() => NugetApiUrl.SkipEmpty())
.OnlyWhenStatic(() => NugetApiKey.SkipEmpty())
.OnlyWhenStatic(() => NuGetApiUrl.SkipEmpty())
.OnlyWhenStatic(() => NuGetApiKey.SkipEmpty())
.OnlyWhenStatic(() => IsServerBuild)
.OnlyWhenDynamic(() => GitRepository.IsOnMainOrMasterBranch())
.OnlyWhenDynamic(() => SkipForked())
Expand All @@ -35,7 +35,7 @@ public interface IPack : IHazPack, IGitRelease
var releaseDirectory = GetReleaseDirectory(MainProject);
var packages = Globbing.GlobFiles(releaseDirectory, "**/*.nupkg");

if (UnlistNuget)
if (UnlistNuGet)
{
packages.ForEach(DotNetNuGetPrerelease);
return;
Expand Down
4 changes: 2 additions & 2 deletions ricaun.Nuke/Components/IPrePack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public interface IPrePack : IPack, IGitPreRelease
.TriggeredBy(Release)
.After(Pack)
.After(GitPreRelease)
.OnlyWhenStatic(() => NugetApiUrl.SkipEmpty())
.OnlyWhenStatic(() => NugetApiKey.SkipEmpty())
.OnlyWhenStatic(() => NuGetApiUrl.SkipEmpty())
.OnlyWhenStatic(() => NuGetApiKey.SkipEmpty())
.OnlyWhenStatic(() => IsServerBuild)
.OnlyWhenDynamic(() => GitRepository.IsOnDevelopBranch())
.OnlyWhenDynamic(() => SkipForked())
Expand Down
10 changes: 5 additions & 5 deletions ricaun.Nuke/Extensions/AssemblyExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static string GetInformationalVersion(this Project project)
{
return fileVersionInfo?.ProductVersion.Split('+').First();
}
if (project.GetNugetVersionInfo() is NugetVersionInfo nugetVersionInfo)
if (project.GetNuGetVersionInfo() is NuGetVersionInfo nugetVersionInfo)
{
return nugetVersionInfo?.ProductVersion.Split('+').First();
}
Expand Down Expand Up @@ -145,19 +145,19 @@ public static FileVersionInfo GetFileVersionInfo(this Project project)
}

/// <summary>
/// Get NugetVersionInfo of the first nupkg file found
/// Get NuGetVersionInfo of the first nupkg file found
/// </summary>
/// <param name="project"></param>
/// <returns></returns>
public static NugetVersionInfo GetNugetVersionInfo(this Project project)
public static NuGetVersionInfo GetNuGetVersionInfo(this Project project)
{
var sourceDir = project.Directory;
var searchPattern = $"*{project.Name}*.nupkg";
var nupkgFiles = Directory.GetFiles(sourceDir, searchPattern, SearchOption.AllDirectories);
foreach (var nupkgFile in nupkgFiles)
{
var nugetVersionInfo = NugetVersionInfo.Parse(nupkgFile);
if (nugetVersionInfo is NugetVersionInfo) return nugetVersionInfo;
var nugetVersionInfo = NuGetVersionInfo.Parse(nupkgFile);
if (nugetVersionInfo is NuGetVersionInfo) return nugetVersionInfo;
}

return null;
Expand Down
70 changes: 35 additions & 35 deletions ricaun.Nuke/Extensions/NuGetExtension.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using Nuke.Common.IO;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.NuGet;
using ricaun.Nuke.Tools.NuGet;
using System;
using System.IO;

namespace ricaun.Nuke.Extensions
{
/// <summary>
/// NugetVersionInfo
/// NuGetVersionInfo
/// </summary>
public class NugetVersionInfo
public class NuGetVersionInfo
{
/// <summary>
/// ProductName
Expand All @@ -21,17 +22,17 @@ public class NugetVersionInfo
public string ProductVersion { get; private set; }

/// <summary>
/// Parse <paramref name="packageFileName"/> and return a new instance of <see cref="NugetVersionInfo"/>
/// Parse <paramref name="packageFileName"/> and return a new instance of <see cref="NuGetVersionInfo"/>
/// </summary>
/// <param name="packageFileName"></param>
/// <returns></returns>
public static NugetVersionInfo Parse(string packageFileName)
public static NuGetVersionInfo Parse(string packageFileName)
{
string packageName;
string packageVersion;
if (NuGetExtension.TryGetPackageNameAndVersion(packageFileName, out packageName, out packageVersion))
{
return new NugetVersionInfo
return new NuGetVersionInfo
{
ProductName = packageName,
ProductVersion = packageVersion
Expand Down Expand Up @@ -87,17 +88,17 @@ public static bool TryGetPackageNameAndVersion(string packageFileName, out strin
}

/// <summary>
/// IsSourceNugetOrg
/// IsSourceNuGetOrg
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static bool IsSourceNugetOrg(string source)
public static bool IsSourceNuGetOrg(string source)
{
return source.Contains("api.nuget.org");
}

/// <summary>
/// NugetDelete (Only works with 'api.nuget.org' to unlist package)
/// NuGetDelete (Only works with 'api.nuget.org' to unlist package)
/// </summary>
/// <param name="source"></param>
/// <param name="apiKey"></param>
Expand All @@ -106,7 +107,7 @@ public static bool IsSourceNugetOrg(string source)
/// <remarks>https://learn.microsoft.com/en-us/nuget/reference/cli-reference/cli-ref-delete</remarks>
public static bool NuGetUnlist(string source, string apiKey, string packageFileName)
{
if (IsSourceNugetOrg(source) == false)
if (IsSourceNuGetOrg(source) == false)
return false;

Serilog.Log.Information($"NuGetUnlist: {packageFileName}");
Expand All @@ -117,15 +118,14 @@ public static bool NuGetUnlist(string source, string apiKey, string packageFileN
Serilog.Log.Information($"NuGet delete: {packageName} {packageVersion}");
try
{
NuGetTasks.NuGet(
$"delete {packageName} {packageVersion}" +
$" -Source {source}" +
$" -ApiKey {apiKey}" +
$" -NonInteractive",
logOutput: false,
logInvocation: false
); // don't print to std out/err

NuGetTasks.NuGetDelete(s => s
.SetPackageId(packageName)
.SetPackageVersion(packageVersion)
.SetSource(source)
.SetApiKey(apiKey)
.EnableNonInteractive()
.DisableProcessLogInvocation()
);
return true;
}
catch (Exception ex)
Expand All @@ -144,11 +144,12 @@ public static bool NuGetVerifySignatures(string packageFileName)
{
try
{
NuGetTasks.NuGet(
$"verify -Signatures \"{packageFileName}\"",
logOutput: false,
logInvocation: false
); // don't print to std out/err
NuGetTasks.NuGetVerify(s => s
.SetTargetPath(packageFileName)
.DisableProcessLogOutput()
.DisableProcessLogInvocation()
);

return true;
}
catch
Expand All @@ -158,27 +159,26 @@ public static bool NuGetVerifySignatures(string packageFileName)
}

/// <summary>
/// NugetSign
/// NuGetSign
/// </summary>
/// <param name="packageFileName"></param>
/// <param name="certPath"></param>
/// <param name="certPassword"></param>
/// <param name="timestampServer"></param>
/// <returns></returns>
public static bool NugetSign(string packageFileName, string certPath, string certPassword, string timestampServer)
public static bool NuGetSign(string packageFileName, string certPath, string certPassword, string timestampServer)
{
try
{
Serilog.Log.Information($"NuGet sign: {packageFileName}");
NuGetTasks.NuGet(
$"sign \"{packageFileName}\"" +
$" -CertificatePath {certPath}" +
$" -CertificatePassword {certPassword}" +
$" -Timestamper {timestampServer}" +
$" -NonInteractive",
logOutput: false,
logInvocation: false
); // don't print to std out/err
NuGetTasks.NuGetSign(s => s
.SetTargetPath(packageFileName)
.SetCertificatePath(certPath)
.SetCertificatePassword(certPassword)
.SetTimestamper(timestampServer)
.EnableNonInteractive()
.DisableProcessLogOutput()
);
return true;
}
catch
Expand Down
4 changes: 2 additions & 2 deletions ricaun.Nuke/Extensions/SignExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static bool CreateCerFile(string fileNamePfx, string passwordPfx, string
/// <param name="certPath">The path to the certificate file.</param>
/// <param name="certPassword">The password for the certificate.</param>
/// <param name="filePath">The path to the file to be signed.</param>
/// <remarks>NuGet files use <see cref="NuGetExtension.NugetSign"/>.</remarks>
/// <remarks>NuGet files use <see cref="NuGetExtension.NuGetSign"/>.</remarks>
public static void Sign(string certPath, string certPassword, string filePath)
{
if (NuGetExtension.IsNuGetFile(filePath))
Expand Down Expand Up @@ -155,7 +155,7 @@ public static void SignNuGet(string certPath, string certPassword, string binary

foreach (var timestampServer in timestampServers)
{
if (NuGetExtension.NugetSign(binaryPath, certPath, certPassword, timestampServer))
if (NuGetExtension.NuGetSign(binaryPath, certPath, certPassword, timestampServer))
{
Serilog.Log.Information($"Signing done with {timestampServer}");
return;
Expand Down
6 changes: 3 additions & 3 deletions ricaun.Nuke/IO/HttpAuthTasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static async Task<string> HttpPostFileAsync(
Configure<HttpClient> clientConfigurator = null,
Action<HttpRequestHeaders> headerConfigurator = null)
{
var content = CreateFormDataContent(filePath, formData, fileStreamContentName);
using var content = CreateFormDataContent(filePath, formData, fileStreamContentName);
return await HttpPostAsync(uri, content, authorization, clientConfigurator, headerConfigurator);
}

Expand Down Expand Up @@ -162,7 +162,7 @@ public static async Task<string> HttpPutFileAsync(
Configure<HttpClient> clientConfigurator = null,
Action<HttpRequestHeaders> headerConfigurator = null)
{
var content = CreateFormDataContent(filePath, formData, fileStreamContentName);
using var content = CreateFormDataContent(filePath, formData, fileStreamContentName);
return await HttpPostAsync(uri, content, authorization, clientConfigurator, headerConfigurator);
}

Expand Down Expand Up @@ -286,7 +286,7 @@ public static async Task<string> HttpPatchFileAsync(
Configure<HttpClient> clientConfigurator = null,
Action<HttpRequestHeaders> headerConfigurator = null)
{
var content = CreateFormDataContent(filePath, formData, fileStreamContentName);
using var content = CreateFormDataContent(filePath, formData, fileStreamContentName);
return await HttpPostAsync(uri, content, authorization, clientConfigurator, headerConfigurator);
}

Expand Down
Loading
Loading