|
4 | 4 | using System.IO;
|
5 | 5 | using System.Linq;
|
6 | 6 | using System.Security.Cryptography;
|
| 7 | +using System.Text.RegularExpressions; |
7 | 8 | using System.Threading.Tasks;
|
8 | 9 | using DotNetReleaser.Configuration;
|
9 | 10 | using DotNetReleaser.Helpers;
|
@@ -72,7 +73,7 @@ private async Task<List<AppPackageInfo>> BuildAppPackages(BuildInformation build
|
72 | 73 | {
|
73 | 74 | foreach (var rid in pack.RuntimeIdentifiers)
|
74 | 75 | {
|
75 |
| - var list = await PackPlatform(packageInfo, pack.Publish, rid, pack.Kinds.ToArray()); |
| 76 | + var list = await PackPlatform(packageInfo, pack.Publish, rid, pack.Renamers.ToArray(), pack.Kinds.ToArray()); |
76 | 77 | if (HasErrors) goto exitPackOnError; // break on first errors
|
77 | 78 |
|
78 | 79 | if (list is not null && pack.Publish)
|
@@ -100,7 +101,7 @@ private async Task<List<AppPackageInfo>> BuildAppPackages(BuildInformation build
|
100 | 101 | /// <summary>
|
101 | 102 | /// This is the part that handles the packaging for tar, zip, deb, rpm
|
102 | 103 | /// </summary>
|
103 |
| - private async Task<List<AppPackageInfo>?> PackPlatform(ProjectPackageInfo projectPackageInfo, bool publish, string rid, params PackageKind[] kinds) |
| 104 | + private async Task<List<AppPackageInfo>?> PackPlatform(ProjectPackageInfo projectPackageInfo, bool publish, string rid, RegexReplacer[] renamers, PackageKind[] kinds) |
104 | 105 | {
|
105 | 106 | var properties = new Dictionary<string, object>(_config.MSBuild.Properties)
|
106 | 107 | {
|
@@ -249,6 +250,32 @@ private async Task<List<AppPackageInfo>> BuildAppPackages(BuildInformation build
|
249 | 250 | path = CopyToArtifacts(path);
|
250 | 251 | }
|
251 | 252 |
|
| 253 | + // Give a chance to rename the artifact file |
| 254 | + var folder = Path.GetDirectoryName(path)!; |
| 255 | + var oldFilename = Path.GetFileName(path); |
| 256 | + var filename = oldFilename; |
| 257 | + string? newPath = null; |
| 258 | + try |
| 259 | + { |
| 260 | + |
| 261 | + foreach (var renamer in renamers) |
| 262 | + { |
| 263 | + filename = renamer.Run(filename); |
| 264 | + } |
| 265 | + |
| 266 | + if (filename != oldFilename) |
| 267 | + { |
| 268 | + newPath = Path.Combine(folder, filename); |
| 269 | + File.Move(path, newPath); |
| 270 | + path = newPath; |
| 271 | + } |
| 272 | + } |
| 273 | + catch (Exception ex) |
| 274 | + { |
| 275 | + Error($"Error renaming file {path} to {newPath}: {ex.Message}"); |
| 276 | + break; |
| 277 | + } |
| 278 | + |
252 | 279 | var sha256 = string.Join("", SHA256.HashData(await File.ReadAllBytesAsync(path)).Select(x => x.ToString("x2")));
|
253 | 280 |
|
254 | 281 | var entry = new AppPackageInfo(
|
|
0 commit comments