diff --git a/BuildAndTest.cmd b/BuildAndTest.cmd new file mode 100644 index 0000000..b4020a7 --- /dev/null +++ b/BuildAndTest.cmd @@ -0,0 +1,15 @@ +@echo off +time /T + +pushd .\src\security_utilities_rust_ffi\ +call cargo build --release +popd +xcopy /Y .\src\security_utilities_rust_ffi\target\release\microsoft_security_utilities_core.dll .\refs +xcopy /Y .\src\security_utilities_rust_ffi\target\release\microsoft_security_utilities_core.pdb .\refs + +powershell -ExecutionPolicy RemoteSigned -File %~dp0\scripts\BuildAndTest.ps1 %* +set result=%ERRORLEVEL% +time /T +echo %RESULT% + +exit /b %RESULT% \ No newline at end of file diff --git a/BuildPackages.cmd b/BuildPackages.cmd new file mode 100644 index 0000000..b814b15 --- /dev/null +++ b/BuildPackages.cmd @@ -0,0 +1,2 @@ +@echo off +powershell -ExecutionPolicy RemoteSigned -File %~dp0\scripts\BuildPackages.ps1 %* diff --git a/refs/microsoft_security_utilities_core.dll b/refs/microsoft_security_utilities_core.dll index f68c3c7..421726a 100644 Binary files a/refs/microsoft_security_utilities_core.dll and b/refs/microsoft_security_utilities_core.dll differ diff --git a/refs/microsoft_security_utilities_core.pdb b/refs/microsoft_security_utilities_core.pdb index b090ddb..7b2cef9 100644 Binary files a/refs/microsoft_security_utilities_core.pdb and b/refs/microsoft_security_utilities_core.pdb differ diff --git a/scripts/BuildAndTest.ps1 b/scripts/BuildAndTest.ps1 new file mode 100644 index 0000000..2683844 --- /dev/null +++ b/scripts/BuildAndTest.ps1 @@ -0,0 +1,87 @@ +<# +.SYNOPSIS + Build, test, and package the Microsoft.Security.Tools.Internal code base +.DESCRIPTION + Builds the Microsoft.Security.Tools.Internal solution for multiple target frameworks, runs tests, and creates + NuGet packages. +.PARAMETER Configuration + The build configuration: Release or Debug. Default=Release +.PARAMETER NoBuild + Do not build. +.PARAMETER NoTest + Do not run tests. +.PARAMETER NoFormat + Do not format files based on dotnet-format tool. +.PARAMETER EnableCoverage + Enable CodeCoverage. +#> + +[CmdletBinding()] +param( + [string] + [ValidateSet("Debug", "Release")] + $Configuration="Release", + + [switch] + $NoBuild, + + [switch] + $NoTest, + + [switch] + $NoFormat, + + [switch] + $EnableCoverage, + + [switch] + $NoDiffCheck +) + +Set-StrictMode -Version Latest +$ErrorActionPreference = "Stop" +$InformationPreference = "Continue" + +$ScriptName = $([io.Path]::GetFileNameWithoutExtension($PSCommandPath)) +$RepoRoot = $(Resolve-Path $PSScriptRoot\..).Path + +function Exit-WithFailureMessage($scriptName, $message) { + Write-Information "${scriptName}: $message" + Write-Information "$scriptName FAILED." + exit 1 +} + +If (Test-Path "..\bld") { + Write-Information "Deleting old build..." + rd /s /q ..\bld +} + +if (-not $NoBuild) { + Write-Information "Building Microsoft.Security.Utilities.sln (dotnet)..." + dotnet build $RepoRoot\src\Microsoft.Security.Utilities.sln -c $Configuration -p:Deterministic=true -p:WarningsAsErrors="MSB3277" + if ($LASTEXITCODE -ne 0) { + Exit-WithFailureMessage $ScriptName "Build of \Microsoft.Security.Utilities failed." + } +} + +if (-not $NoTest) { + Write-Information "Running tests..." + + $CodeCoverageCommand = '--collect:"Code Coverage"' + if (-not $EnableCoverage) { + $CodeCoverageCommand = "" + } + + dotnet test $RepoRoot\src\Microsoft.Security.Utilities.sln -c $Configuration --logger trx --no-build $CodeCoverageCommand /p:IncludeTestAssembly=false + if ($LASTEXITCODE -ne 0) { + Exit-WithFailureMessage $ScriptName "Test of \Microsoft.Security.Utilities failed." + } +} + +Write-Information "Creating packages.." +cmd.exe /c 'BuildPackages.cmd' +if ($LASTEXITCODE -ne 0) { + Exit-WithFailureMessage $ScriptName "Package build failed." +} + +Write-Information "$ScriptName SUCCEEDED." diff --git a/scripts/BuildPackages.ps1 b/scripts/BuildPackages.ps1 new file mode 100644 index 0000000..500c409 --- /dev/null +++ b/scripts/BuildPackages.ps1 @@ -0,0 +1,41 @@ +<# +.SYNOPSIS + Build packages from compiled dlls. +.PARAMETER Configuration + The build configuration: Release or Debug. Default=Release +#> + +[CmdletBinding()] +param( + [string] + [ValidateSet("Debug", "Release")] + $Configuration="Release" +) + +Set-StrictMode -Version Latest +$ErrorActionPreference = "Stop" +$InformationPreference = "Continue" + +$ScriptName = $([io.Path]::GetFileNameWithoutExtension($PSCommandPath)) +$RepoRoot = $(Resolve-Path $PSScriptRoot\..).Path + +function Exit-WithFailureMessage($scriptName, $message) { + Write-Information "${scriptName}: $message" + Write-Information "$scriptName FAILED." + exit 1 +} + +dotnet tool update --global nbgv --version 3.3.37 +$tag = nbgv get-version --variable NugetPackageVersion + +if ($env:MsuiNugetPackageVersion) { + Write-Information "Overriding Nerdbank.GitVersioning assigned PackageVersion: $tag -> $env:MsuiNugetPackageVersion." + $tag = $env:MsuiNugetPackageVersion +} + +dotnet pack src\Microsoft.Security.Utilities.Packages.sln -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg /p:Version=$tag -o "$RepoRoot\bld\nupkg\AnyCPU_$Configuration" +if ($LASTEXITCODE -ne 0) { + Exit-WithFailureMessage $ScriptName "Pack of Microsoft.Security.Utilities.Packages.sln failed." +} + +Write-Information "$ScriptName SUCCEEDED." diff --git a/src/Benchmarks/Microsoft.Security.Utilities.Benchmarks.csproj b/src/Benchmarks/Microsoft.Security.Utilities.Benchmarks.csproj index 2e0b018..46fd394 100644 --- a/src/Benchmarks/Microsoft.Security.Utilities.Benchmarks.csproj +++ b/src/Benchmarks/Microsoft.Security.Utilities.Benchmarks.csproj @@ -8,6 +8,8 @@ latest + + @@ -17,13 +19,4 @@ - - - CopyIfNewer - - - CopyIfNewer - - - diff --git a/src/Build.props b/src/Build.props index 2041901..d09524a 100644 --- a/src/Build.props +++ b/src/Build.props @@ -59,4 +59,13 @@ true + + + PreserveNewest + + + PreserveNewest + + + diff --git a/src/Microsoft.Security.Utilities.Cli/Microsoft.Security.Utilities.Cli.csproj b/src/Microsoft.Security.Utilities.Cli/Microsoft.Security.Utilities.Cli.csproj index 79c8264..047543d 100644 --- a/src/Microsoft.Security.Utilities.Cli/Microsoft.Security.Utilities.Cli.csproj +++ b/src/Microsoft.Security.Utilities.Cli/Microsoft.Security.Utilities.Cli.csproj @@ -7,7 +7,7 @@ enable - + @@ -21,16 +21,7 @@ - - - - CopyIfNewer - - - CopyIfNewer - - - + all diff --git a/src/Microsoft.Security.Utilities.Core/Microsoft.Security.Utilities.Core.csproj b/src/Microsoft.Security.Utilities.Core/Microsoft.Security.Utilities.Core.csproj index 5db67b1..7204a0c 100644 --- a/src/Microsoft.Security.Utilities.Core/Microsoft.Security.Utilities.Core.csproj +++ b/src/Microsoft.Security.Utilities.Core/Microsoft.Security.Utilities.Core.csproj @@ -7,7 +7,7 @@ true - + $(RootNamespace) @@ -40,15 +40,6 @@ - - - CopyIfNewer - - - CopyIfNewer - - - all diff --git a/src/Tests.Microsoft.Security.Utilities.Core/IdentifiableScanTests.cs b/src/Tests.Microsoft.Security.Utilities.Core/IdentifiableScanTests.cs index 46bed2a..448bed2 100644 --- a/src/Tests.Microsoft.Security.Utilities.Core/IdentifiableScanTests.cs +++ b/src/Tests.Microsoft.Security.Utilities.Core/IdentifiableScanTests.cs @@ -1,12 +1,14 @@ // Copyright(c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using FluentAssertions; using FluentAssertions.Execution; using Microsoft.Security.Utilities; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; +using System.Linq; namespace Tests.Microsoft.Security.Utilities.Core { @@ -37,7 +39,11 @@ namespace Tests.Microsoft.Security.Utilities.Core identifiable.Signature, identifiable.EncodeForUrl); + string moniker = pattern.GetMatchMoniker(key); + moniker.Should().NotBeNull(because: $"{pattern.Name} should produce a moniker using '{key}'"); + int found = masker.DetectSecrets(key).Count(); + found.Should().Be(1, because: $"{moniker} should match against '{key}' a single time, not {found} time(s)"); } } } diff --git a/src/Tests.Microsoft.Security.Utilities.Core/Tests.Microsoft.Security.Utilities.Core.csproj b/src/Tests.Microsoft.Security.Utilities.Core/Tests.Microsoft.Security.Utilities.Core.csproj index f1f976a..7356ca0 100644 --- a/src/Tests.Microsoft.Security.Utilities.Core/Tests.Microsoft.Security.Utilities.Core.csproj +++ b/src/Tests.Microsoft.Security.Utilities.Core/Tests.Microsoft.Security.Utilities.Core.csproj @@ -1,12 +1,12 @@  - + true net462 false - + x64 @@ -25,4 +25,5 @@ + diff --git a/version.json b/version.json index fa687fd..490ac5e 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.4.19", + "version": "1.4.20", "publicReleaseRefSpec": [ "^refs/heads/main$", "^refs/heads/release/v\\d+\\.\\d+\\.\\d+$"