From 7226c5aa74013fa685e3bf4ce8c777f0c5ef9fb3 Mon Sep 17 00:00:00 2001 From: Brad Wilson Date: Sat, 3 Feb 2024 15:33:30 -0800 Subject: [PATCH] Updated build process --- .github/workflows/push-main.yaml | 7 +--- .../xunit.runner.visualstudio.csproj | 3 ++ .../xunit.runner.visualstudio.nuspec | 11 +++++- .../xunit.runner.visualstudio.sign-file-list | 2 - tools/builder/common | 2 +- tools/builder/targets/Packages.cs | 22 +++++++---- tools/builder/targets/SignAssemblies.cs | 38 +++++++++++++++++++ 7 files changed, 68 insertions(+), 17 deletions(-) delete mode 100644 src/xunit.runner.visualstudio/xunit.runner.visualstudio.sign-file-list create mode 100644 tools/builder/targets/SignAssemblies.cs diff --git a/.github/workflows/push-main.yaml b/.github/workflows/push-main.yaml index 8c1b63c..713c893 100644 --- a/.github/workflows/push-main.yaml +++ b/.github/workflows/push-main.yaml @@ -36,10 +36,7 @@ jobs: - name: Get .NET information run: dotnet --info - - name: "Build target: BuildAll" - run: dotnet run --project tools/builder --no-launch-profile -- BuildAll --timing - - - name: "Build target: PublishPackages" + - name: "Build target: BuildAll & PublishPackages" env: PUSH_APIKEY: ${{ secrets.PUSH_APIKEY }} PUSH_URI: ${{ secrets.PUSH_URI }} @@ -50,7 +47,7 @@ jobs: SIGN_TENANT: ${{ secrets.SIGN_TENANT }} SIGN_TIMESTAMP_URI: ${{ secrets.SIGN_TIMESTAMP_URI }} SIGN_VAULT_URI: ${{ secrets.SIGN_VAULT_URI }} - run: dotnet run --project tools/builder --no-launch-profile -- PublishPackages --timing + run: dotnet run --project tools/builder --no-launch-profile -- BuildAll PublishPackages --timing - name: "Upload artifact: test" uses: actions/upload-artifact@v3 diff --git a/src/xunit.runner.visualstudio/xunit.runner.visualstudio.csproj b/src/xunit.runner.visualstudio/xunit.runner.visualstudio.csproj index 5e032a5..16acff3 100644 --- a/src/xunit.runner.visualstudio/xunit.runner.visualstudio.csproj +++ b/src/xunit.runner.visualstudio/xunit.runner.visualstudio.csproj @@ -46,6 +46,8 @@ + + signed\ $(BuildVersionSimple)$(PrereleaseVersion) @@ -54,6 +56,7 @@ GitCommitId=$(GitCommitId); MicrosoftTestPlatformObjectModelVersion=$(MicrosoftTestPlatformObjectModelVersion); PackageVersion=$(PackageVersion); + SignedPath=$(SignedPath); diff --git a/src/xunit.runner.visualstudio/xunit.runner.visualstudio.nuspec b/src/xunit.runner.visualstudio/xunit.runner.visualstudio.nuspec index 6549723..d6c897b 100644 --- a/src/xunit.runner.visualstudio/xunit.runner.visualstudio.nuspec +++ b/src/xunit.runner.visualstudio/xunit.runner.visualstudio.nuspec @@ -25,14 +25,21 @@ + - + + + + - + + + + diff --git a/src/xunit.runner.visualstudio/xunit.runner.visualstudio.sign-file-list b/src/xunit.runner.visualstudio/xunit.runner.visualstudio.sign-file-list deleted file mode 100644 index 5c2c097..0000000 --- a/src/xunit.runner.visualstudio/xunit.runner.visualstudio.sign-file-list +++ /dev/null @@ -1,2 +0,0 @@ -build\net462\xunit.runner.visualstudio.testadapter.dll -build\net6.0\xunit.runner.visualstudio.testadapter.dll diff --git a/tools/builder/common b/tools/builder/common index ad8cf65..f14b9b2 160000 --- a/tools/builder/common +++ b/tools/builder/common @@ -1 +1 @@ -Subproject commit ad8cf655e07ef0dfbf8c0d1f44c2157f4b165572 +Subproject commit f14b9b23dc65a5eaa94b5c9a90cf4f107f64d46b diff --git a/tools/builder/targets/Packages.cs b/tools/builder/targets/Packages.cs index 1b96b05..ca32564 100644 --- a/tools/builder/targets/Packages.cs +++ b/tools/builder/targets/Packages.cs @@ -1,4 +1,5 @@ using System.IO; +using System.Linq; using System.Threading.Tasks; using Xunit.BuildTools.Models; @@ -10,13 +11,20 @@ public static async Task OnExecute(BuildContext context) { context.BuildStep("Creating NuGet packages"); - var packArgs = $"pack --nologo --no-build --configuration {context.ConfigurationText} --output {context.PackageOutputFolder} --verbosity {context.Verbosity} src/xunit.runner.visualstudio -p:NuspecFile=xunit.runner.visualstudio.nuspec"; - await context.Exec("dotnet", packArgs); + // Clean up any existing packages to force re-packing + var packageFiles = Directory.GetFiles(context.PackageOutputFolder, "*.nupkg"); + foreach (var packageFile in packageFiles) + File.Delete(packageFile); - File.Copy( - Path.Join(context.BaseFolder, "src", "xunit.runner.visualstudio", "xunit.runner.visualstudio.sign-file-list"), - Path.Join(context.PackageOutputFolder, "xunit.runner.visualstudio.sign-file-list"), - overwrite: true - ); + // Enumerate the .nuspec files and pack those + var srcFolder = Path.Join(context.BaseFolder, "src"); + var nuspecFiles = + Directory + .GetFiles(srcFolder, "*.nuspec", SearchOption.AllDirectories) + .ToList(); + + // Pack the .nuspec file(s) + foreach (var nuspecFile in nuspecFiles.OrderBy(x => x)) + await context.Exec("dotnet", $"pack --nologo --no-build --configuration {context.ConfigurationText} --output {context.PackageOutputFolder} --verbosity {context.Verbosity} \"{Path.GetDirectoryName(nuspecFile)}\" -p:NuspecFile={Path.GetFileName(nuspecFile)}"); } } diff --git a/tools/builder/targets/SignAssemblies.cs b/tools/builder/targets/SignAssemblies.cs new file mode 100644 index 0000000..b540209 --- /dev/null +++ b/tools/builder/targets/SignAssemblies.cs @@ -0,0 +1,38 @@ +using System; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Xunit.BuildTools.Models; + +namespace Xunit.BuildTools.Targets; + +public static partial class SignAssemblies +{ + public static Task OnExecute(BuildContext context) + { + // Check early because we don't need to make copies or show the banner for non-signed scenarios + if (!context.CanSign) + return Task.CompletedTask; + + context.BuildStep("Signing binaries"); + + // Note that any changes to .nuspec files means this list needs to be updated + var binaries = + new[] { + Path.Combine(context.BaseFolder, "src", "xunit.runner.visualstudio", "bin", context.ConfigurationText, "net462", "xunit.runner.visualstudio.testadapter.dll"), + Path.Combine(context.BaseFolder, "src", "xunit.runner.visualstudio", "bin", context.ConfigurationText, "net6.0", "xunit.runner.visualstudio.testadapter.dll"), + }.Select(unsignedPath => + { + var unsignedFolder = Path.GetDirectoryName(unsignedPath) ?? throw new InvalidOperationException($"Path '{unsignedPath}' did not have a folder"); + var signedFolder = Path.Combine(unsignedFolder, "signed"); + Directory.CreateDirectory(signedFolder); + + var signedPath = Path.Combine(signedFolder, Path.GetFileName(unsignedPath)); + File.Copy(unsignedPath, signedPath, overwrite: true); + + return signedPath; + }).ToArray(); + + return context.SignFiles(context.BaseFolder, binaries); + } +}