Update .NET SDK. Use last commit timestamp for output files

This commit is contained in:
Alex Barney 2022-11-12 16:11:40 -07:00
parent b954c129cf
commit 766e0d6461
4 changed files with 25 additions and 16 deletions

View file

@ -1 +1 @@
6.0.201 6.0.403

View file

@ -1,6 +1,7 @@
mode: ContinuousDeployment mode: ContinuousDeployment
increment: Patch increment: Patch
next-version: 0.16.1 next-version: 0.17.0
commit-date-format: yyyy-MM-dd HH:mm:ss
branches: branches:
master: master:
tag: alpha tag: alpha

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Security.Cryptography; using System.Security.Cryptography;
@ -62,6 +63,7 @@ partial class Build : NukeBuild
private string HostOsName { get; set; } private string HostOsName { get; set; }
private string NativeProgramExtension { get; set; } private string NativeProgramExtension { get; set; }
private DateTimeOffset CommitTime { get; set; } = DateTimeOffset.Now;
string VersionString { get; set; } string VersionString { get; set; }
Dictionary<string, object> VersionProps { get; set; } = new Dictionary<string, object>(); Dictionary<string, object> VersionProps { get; set; } = new Dictionary<string, object>();
@ -124,6 +126,12 @@ partial class Build : NukeBuild
HasGitDir = true; HasGitDir = true;
if (DateTimeOffset.TryParseExact(gitVersion.CommitDate, "yyyy-MM-dd HH:mm:ss",
CultureInfo.InvariantCulture.DateTimeFormat, DateTimeStyles.AssumeUniversal, out DateTimeOffset commitTime))
{
CommitTime = commitTime.LocalDateTime;
}
VersionString = $"{gitVersion.MajorMinorPatch}"; VersionString = $"{gitVersion.MajorMinorPatch}";
if (!string.IsNullOrWhiteSpace(gitVersion.PreReleaseTag)) if (!string.IsNullOrWhiteSpace(gitVersion.PreReleaseTag))
{ {
@ -287,7 +295,7 @@ partial class Build : NukeBuild
EnsureExistingDirectory(ArtifactsDirectory); EnsureExistingDirectory(ArtifactsDirectory);
ZipFiles(CliCoreZip, namesCore); ZipFiles(CliCoreZip, namesCore, CommitTime);
Serilog.Log.Debug($"Created {CliCoreZip}"); Serilog.Log.Debug($"Created {CliCoreZip}");
PushArtifact(CliCoreZip); PushArtifact(CliCoreZip);
@ -390,14 +398,14 @@ partial class Build : NukeBuild
EnsureExistingDirectory(ArtifactsDirectory); EnsureExistingDirectory(ArtifactsDirectory);
ZipFile(CliNativeZip, CliNativeExe, $"hactoolnet{NativeProgramExtension}"); ZipFile(CliNativeZip, CliNativeExe, $"hactoolnet{NativeProgramExtension}", CommitTime);
Serilog.Log.Debug($"Created {CliNativeZip}"); Serilog.Log.Debug($"Created {CliNativeZip}");
Serilog.Log.Debug($"Created {CliNativeZip}"); Serilog.Log.Debug($"Created {CliNativeZip}");
PushArtifact(CliNativeZip); PushArtifact(CliNativeZip);
} }
public static void ZipFiles(string outFile, IEnumerable<string> files) public static void ZipFiles(string outFile, IEnumerable<string> files, DateTimeOffset fileDateTime)
{ {
using (var s = new ZipOutputStream(File.Create(outFile))) using (var s = new ZipOutputStream(File.Create(outFile)))
{ {
@ -406,7 +414,7 @@ partial class Build : NukeBuild
foreach (string file in files) foreach (string file in files)
{ {
var entry = new ZipEntry(Path.GetFileName(file)); var entry = new ZipEntry(Path.GetFileName(file));
entry.DateTime = DateTime.UnixEpoch; entry.DateTime = fileDateTime.DateTime;
using (FileStream fs = File.OpenRead(file)) using (FileStream fs = File.OpenRead(file))
{ {
@ -418,14 +426,14 @@ partial class Build : NukeBuild
} }
} }
public static void ZipFile(string outFile, string file, string nameInsideZip) public static void ZipFile(string outFile, string file, string nameInsideZip, DateTimeOffset fileDateTime)
{ {
using (var s = new ZipOutputStream(File.Create(outFile))) using (var s = new ZipOutputStream(File.Create(outFile)))
{ {
s.SetLevel(9); s.SetLevel(9);
var entry = new ZipEntry(nameInsideZip); var entry = new ZipEntry(nameInsideZip);
entry.DateTime = DateTime.UnixEpoch; entry.DateTime = fileDateTime.DateTime;
using (FileStream fs = File.OpenRead(file)) using (FileStream fs = File.OpenRead(file))
{ {
@ -436,7 +444,7 @@ partial class Build : NukeBuild
} }
} }
public static void ZipDirectory(string outFile, string directory) public static void ZipDirectory(string outFile, string directory, DateTimeOffset fileDateTime)
{ {
using (var s = new ZipOutputStream(File.Create(outFile))) using (var s = new ZipOutputStream(File.Create(outFile)))
{ {
@ -447,7 +455,7 @@ partial class Build : NukeBuild
string relativePath = Path.GetRelativePath(directory, filePath); string relativePath = Path.GetRelativePath(directory, filePath);
var entry = new ZipEntry(relativePath); var entry = new ZipEntry(relativePath);
entry.DateTime = DateTime.UnixEpoch; entry.DateTime = fileDateTime.DateTime;
using (FileStream fs = File.OpenRead(filePath)) using (FileStream fs = File.OpenRead(filePath))
{ {
@ -459,7 +467,7 @@ partial class Build : NukeBuild
} }
} }
public static void ZipDirectory(string outFile, string directory, IEnumerable<string> files) public static void ZipDirectory(string outFile, string directory, IEnumerable<string> files, DateTimeOffset fileDateTime)
{ {
using (var s = new ZipOutputStream(File.Create(outFile))) using (var s = new ZipOutputStream(File.Create(outFile)))
{ {
@ -470,7 +478,7 @@ partial class Build : NukeBuild
string absolutePath = Path.Combine(directory, filePath); string absolutePath = Path.Combine(directory, filePath);
var entry = new ZipEntry(filePath); var entry = new ZipEntry(filePath);
entry.DateTime = DateTime.UnixEpoch; entry.DateTime = fileDateTime.DateTime;
using (FileStream fs = File.OpenRead(absolutePath)) using (FileStream fs = File.OpenRead(absolutePath))
{ {
@ -590,12 +598,12 @@ partial class Build : NukeBuild
// Avoid having multiple signed versions of the same file // Avoid having multiple signed versions of the same file
File.Copy(nupkgDir / "lib" / "net6.0" / "LibHac.dll", coreFxDir / "LibHac.dll", true); File.Copy(nupkgDir / "lib" / "net6.0" / "LibHac.dll", coreFxDir / "LibHac.dll", true);
ZipDirectory(SignedArtifactsDirectory / Path.GetFileName(nupkgFile), nupkgDir, pkgFileList); ZipDirectory(SignedArtifactsDirectory / Path.GetFileName(nupkgFile), nupkgDir, pkgFileList, CommitTime);
ZipDirectory(SignedArtifactsDirectory / Path.GetFileName(CliCoreZip), coreFxDir); ZipDirectory(SignedArtifactsDirectory / Path.GetFileName(CliCoreZip), coreFxDir, CommitTime);
if (signNative) if (signNative)
{ {
ZipDirectory(SignedArtifactsDirectory / Path.GetFileName(CliNativeZip), nativeZipDir); ZipDirectory(SignedArtifactsDirectory / Path.GetFileName(CliNativeZip), nativeZipDir, CommitTime);
} }
File.Copy(snupkgFile, SignedArtifactsDirectory / Path.GetFileName(snupkgFile)); File.Copy(snupkgFile, SignedArtifactsDirectory / Path.GetFileName(snupkgFile));

View file

@ -45,7 +45,7 @@ public partial class Build
ReplaceLineEndings(filename); ReplaceLineEndings(filename);
} }
ZipDirectory(path, tempDir, fileList); ZipDirectory(path, tempDir, fileList, CommitTime);
} }
finally finally
{ {