From 684a3dfd8e68495d31a244e085e8a33203ed7acb Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Fri, 15 Nov 2019 14:21:38 -0600 Subject: [PATCH] updated build system (#28) * updated build system * added code-signing --- appsettings.json | 13 +++++++ build.fsx | 95 ++++++++++++++++++++++++++++++++++++++++++------ build.ps1 | 36 +++++++++--------- build.sh | 35 +++++++++++++++++- 4 files changed, 147 insertions(+), 32 deletions(-) create mode 100644 appsettings.json diff --git a/appsettings.json b/appsettings.json new file mode 100644 index 0000000..b5c102c --- /dev/null +++ b/appsettings.json @@ -0,0 +1,13 @@ +{ + "SignClient": { + "AzureAd": { + "AADInstance": "https://login.microsoftonline.com/", + "ClientId": "1e983f21-9ea5-4f21-ab99-28080225efc9", + "TenantId": "2fa36080-af12-4894-a64b-a17d8f29ec52" + }, + "Service": { + "Url": "https://pb-sign.azurewebsites.net/", + "ResourceId": "https://SignService/eef8e2e7-24b1-4a3b-a73b-a84d66f9abee" + } + } +} \ No newline at end of file diff --git a/build.fsx b/build.fsx index b0af3a3..fed8792 100644 --- a/build.fsx +++ b/build.fsx @@ -10,14 +10,19 @@ open Fake.DotNetCli open Fake.DocFxHelper // Information about the project for Nuget and Assembly info files -let product = "OpenTracing.ApplicationInsights" +let product = "Petabridge.Library" let configuration = "Release" +// Metadata used when signing packages and DLLs +let signingName = "Petabridge.Tracing.Zipkin" +let signingDescription = "Zipkin dristributed tracing engine driver, developed by Petabridge®" +let signingUrl = "https://github.com/petabridge/Petabridge.Tracing.Zipkin" + // Read release notes and version let solutionFile = FindFirstMatchingFile "*.sln" __SOURCE_DIRECTORY__ // dynamically look up the solution let buildNumber = environVarOrDefault "BUILD_NUMBER" "0" let hasTeamCity = (not (buildNumber = "0")) // check if we have the TeamCity environment variable for build # set -let preReleaseVersionSuffix = (if (not (buildNumber = "0")) then (buildNumber) else "") + "-beta" +let preReleaseVersionSuffix = "beta" + (if (not (buildNumber = "0")) then (buildNumber) else DateTime.UtcNow.Ticks.ToString()) let versionSuffix = match (getBuildParam "nugetprerelease") with | "dev" -> preReleaseVersionSuffix @@ -40,6 +45,8 @@ let workingDir = output @@ "build" let nugetExe = FullName @"./tools/nuget.exe" Target "Clean" (fun _ -> + ActivateFinalTarget "KillCreatedProcesses" + CleanDir output CleanDir outputTests CleanDir outputPerfTests @@ -94,20 +101,21 @@ Target "RunTests" (fun _ -> let projects = match (isWindows) with | true -> !! "./src/**/*.Tests.csproj" + -- "./src/**/*.Integration.Tests.csproj" // Zipkin containers can't run on Windows VMs | _ -> !! "./src/**/*.Tests.csproj" // if you need to filter specs for Linux vs. Windows, do it here let runSingleProject project = let arguments = match (hasTeamCity) with - | true -> (sprintf "xunit -c Release -nobuild -parallel none -teamcity -xml %s_xunit.xml" (outputTests @@ fileNameWithoutExt project)) - | false -> (sprintf "xunit -c Release -nobuild -parallel none -xml %s_xunit.xml" (outputTests @@ fileNameWithoutExt project)) + | true -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --results-directory %s -- -parallel none -teamcity" (outputTests)) + | false -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --results-directory %s -- -parallel none" (outputTests)) let result = ExecProcess(fun info -> info.FileName <- "dotnet" info.WorkingDirectory <- (Directory.GetParent project).FullName info.Arguments <- arguments) (TimeSpan.FromMinutes 30.0) - ResultHandling.failBuildIfXUnitReportedError TestRunnerErrorLevel.DontFailBuild result + ResultHandling.failBuildIfXUnitReportedError TestRunnerErrorLevel.DontFailBuild result projects |> Seq.iter (log) projects |> Seq.iter (runSingleProject) @@ -136,6 +144,54 @@ Target "NBench" <| fun _ -> projects |> Seq.iter runSingleProject +//-------------------------------------------------------------------------------- +// Code signing targets +//-------------------------------------------------------------------------------- +Target "SignPackages" (fun _ -> + let canSign = hasBuildParam "SignClientSecret" && hasBuildParam "SignClientUser" + if(canSign) then + log "Signing information is available." + + let assemblies = !! (outputNuGet @@ "*.nupkg") + + let signPath = + let globalTool = tryFindFileOnPath "SignClient.exe" + match globalTool with + | Some t -> t + | None -> if isWindows then findToolInSubPath "SignClient.exe" "tools/signclient" + elif isMacOS then findToolInSubPath "SignClient" "tools/signclient" + else findToolInSubPath "SignClient" "tools/signclient" + + let signAssembly assembly = + let args = StringBuilder() + |> append "sign" + |> append "--config" + |> append (__SOURCE_DIRECTORY__ @@ "appsettings.json") + |> append "-i" + |> append assembly + |> append "-r" + |> append (getBuildParam "SignClientUser") + |> append "-s" + |> append (getBuildParam "SignClientSecret") + |> append "-n" + |> append signingName + |> append "-d" + |> append signingDescription + |> append "-u" + |> append signingUrl + |> toText + + let result = ExecProcess(fun info -> + info.FileName <- signPath + info.WorkingDirectory <- __SOURCE_DIRECTORY__ + info.Arguments <- args) (System.TimeSpan.FromMinutes 5.0) (* Reasonably long-running task. *) + if result <> 0 then failwithf "SignClient failed.%s" args + + assemblies |> Seq.iter (signAssembly) + else + log "SignClientSecret not available. Skipping signing" +) + //-------------------------------------------------------------------------------- // Nuget targets //-------------------------------------------------------------------------------- @@ -204,6 +260,19 @@ Target "DocFx" (fun _ -> DocFxJson = docsPath @@ "docfx.json" }) ) +//-------------------------------------------------------------------------------- +// Cleanup +//-------------------------------------------------------------------------------- + +FinalTarget "KillCreatedProcesses" (fun _ -> + log "Shutting down dotnet build-server" + let result = ExecProcess(fun info -> + info.FileName <- "dotnet" + info.WorkingDirectory <- __SOURCE_DIRECTORY__ + info.Arguments <- "build-server shutdown") (System.TimeSpan.FromMinutes 2.0) + if result <> 0 then failwithf "dotnet build-server shutdown failed" +) + //-------------------------------------------------------------------------------- // Help //-------------------------------------------------------------------------------- @@ -214,11 +283,12 @@ Target "Help" <| fun _ -> "./build.ps1 [target]" "" " Targets for building:" - " * Build Builds" - " * Nuget Create and optionally publish nugets packages" - " * RunTests Runs tests" - " * All Builds, run tests, creates and optionally publish nuget packages" - " * DocFx Creates a DocFx-based website for this solution" + " * Build Builds" + " * Nuget Create and optionally publish nugets packages" + " * SignPackages Signs all NuGet packages, provided that the following arguments are passed into the script: SignClientSecret={secret} and SignClientUser={username}" + " * RunTests Runs tests" + " * All Builds, run tests, creates and optionally publish nuget packages" + " * DocFx Creates a DocFx-based website for this solution" "" " Other Targets" " * Help Display this help" @@ -236,13 +306,14 @@ Target "Nuget" DoNothing "Clean" ==> "RestorePackages" ==> "AssemblyInfo" ==> "Build" ==> "BuildRelease" // tests dependencies +"Clean" ==> "RestorePackages" ==> "Build" ==> "RunTests" // nuget dependencies "Clean" ==> "RestorePackages" ==> "Build" ==> "CreateNuget" -"CreateNuget" ==> "PublishNuget" ==> "Nuget" +"CreateNuget" ==> "SignPackages" ==> "PublishNuget" ==> "Nuget" // docs -"BuildRelease" ==> "Docfx" +"Clean" ==> "RestorePackages" ==> "BuildRelease" ==> "Docfx" // all "BuildRelease" ==> "All" diff --git a/build.ps1 b/build.ps1 index ee467ca..2f8f899 100644 --- a/build.ps1 +++ b/build.ps1 @@ -31,12 +31,12 @@ Param( $FakeVersion = "4.61.2" $DotNetChannel = "LTS"; -$DotNetVersion = "2.0.0"; -$DotNetInstallerUri = "https://raw.githubusercontent.com/dotnet/cli/v2.0.0/scripts/obtain/dotnet-install.ps1"; +$DotNetVersion = "2.1.500"; +$DotNetInstallerUri = "https://raw.githubusercontent.com/dotnet/cli/v$DotNetVersion/scripts/obtain/dotnet-install.ps1"; $NugetVersion = "4.1.0"; $NugetUrl = "https://dist.nuget.org/win-x86-commandline/v$NugetVersion/nuget.exe" -$ProtobufVersion = "3.2.0" -$DocfxVersion = "2.36.2" +$ProtobufVersion = "3.4.0" +$DocfxVersion = "2.40.5" # Make sure tools folder exists $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent @@ -114,20 +114,6 @@ if (!(Test-Path $FakeExePath)) { } } -########################################################################### -# INSTALL NBench Runner -########################################################################### - -# Make sure NBench Runner has been installed. -$NBenchDllPath = Join-Path $ToolPath "NBench.Runner/lib/net45/NBench.Runner.exe" -if (!(Test-Path $NBenchDllPath)) { - Write-Host "Installing NBench..." - Invoke-Expression "&`"$NugetPath`" install NBench.Runner -ExcludeVersion -Version $NBenchVersion -OutputDirectory `"$ToolPath`"" | Out-Null; - if ($LASTEXITCODE -ne 0) { - Throw "An error occured while restoring NBench.Runner from NuGet." - } -} - ########################################################################### # Docfx ########################################################################### @@ -142,6 +128,20 @@ if (!(Test-Path $DocfxExePath)) { } } +########################################################################### +# SignTool +########################################################################### + +# Make sure the SignClient has been installed +if (Get-Command signclient -ErrorAction SilentlyContinue) { + Write-Host "Found SignClient. Skipping install." +} +else{ + $SignClientFolder = Join-Path $ToolPath "signclient" + Write-Host "SignClient not found. Installing to ... $SignClientFolder" + dotnet tool install SignClient --version 1.0.82 --tool-path "$SignClientFolder" +} + ########################################################################### # RUN BUILD SCRIPT ########################################################################### diff --git a/build.sh b/build.sh index 5aaf5ef..73752bc 100755 --- a/build.sh +++ b/build.sh @@ -6,13 +6,16 @@ # Define directories. SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) TOOLS_DIR=$SCRIPT_DIR/tools +SIGNCLIENT_DIR=$TOOLS_DIR/signclient NUGET_EXE=$TOOLS_DIR/nuget.exe NUGET_URL=https://dist.nuget.org/win-x86-commandline/v4.0.0/nuget.exe FAKE_VERSION=4.61.2 FAKE_EXE=$TOOLS_DIR/FAKE/tools/FAKE.exe -DOTNET_VERSION=2.0.0 +DOTNET_VERSION=2.1.500 +DOTNET_INSTALLER_URL=https://raw.githubusercontent.com/dotnet/cli/v$DOTNET_VERSION/scripts/obtain/dotnet-install.sh DOTNET_CHANNEL=LTS; -DOTNET_INSTALLER_URL=https://raw.githubusercontent.com/dotnet/cli/v2.0.0/scripts/obtain/dotnet-install.sh +DOCFX_VERSION=2.40.5 +DOCFX_EXE=$TOOLS_DIR/docfx.console/tools/docfx.exe # Define default arguments. TARGET="Default" @@ -88,6 +91,34 @@ if [ ! -f "$FAKE_EXE" ]; then exit 1 fi +########################################################################### +# INSTALL DOCFX +########################################################################### +if [ ! -f "$DOCFX_EXE" ]; then + mono "$NUGET_EXE" install docfx.console -ExcludeVersion -Version $DOCFX_VERSION -OutputDirectory "$TOOLS_DIR" + if [ $? -ne 0 ]; then + echo "An error occured while installing DocFx." + exit 1 + fi +fi + +# Make sure that DocFx has been installed. +if [ ! -f "$DOCFX_EXE" ]; then + echo "Could not find docfx.exe at '$DOCFX_EXE'." + exit 1 +fi + +########################################################################### +# INSTALL SignTool +########################################################################### +if [ ! -f "$SIGNTOOL_EXE" ]; then + "$SCRIPT_DIR/.dotnet/dotnet" tool install SignClient --version 1.0.82 --tool-path "$SIGNCLIENT_DIR" + if [ $? -ne 0 ]; then + echo "SignClient already installed." + fi +fi + + ########################################################################### # WORKAROUND FOR MONO ###########################################################################