-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathBuildAndTest.cmd
103 lines (81 loc) · 4.08 KB
/
BuildAndTest.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
@echo off
SETLOCAL
@REM Uncomment this line to update nuget.exe
@REM Doing so can break SLN build (which uses nuget.exe to
@REM create a nuget package for binskim) so must opt-in
@REM %~dp0.nuget\NuGet.exe update -self
set Configuration=%1
set Platform=x64
if "%Configuration%" EQU "" (
set Configuration=Release
)
set NightlyTest=%2
@REM Remove existing build data
if exist bld (rd /s /q bld)
set NuGetPackageDir=%~dp0src\packages
set NuGetOutputDirectory=%~dp0bld\bin\nuget\
call SetCurrentVersion.cmd
set VERSION_CONSTANTS=%~dp0src\BinaryParsers\VersionConstants.cs
@REM Rewrite VersionConstants.cs
echo // Copyright (c) Microsoft. All rights reserved. Licensed under the MIT > %VERSION_CONSTANTS%
echo // license. See LICENSE file in the project root for full license information. >> %VERSION_CONSTANTS%
echo namespace Microsoft.CodeAnalysis.IL >> %VERSION_CONSTANTS%
echo { >> %VERSION_CONSTANTS%
echo public static class VersionConstants >> %VERSION_CONSTANTS%
echo { >> %VERSION_CONSTANTS%
echo public const string Prerelease = "%PRERELEASE%"; >> %VERSION_CONSTANTS%
echo public const string AssemblyVersion = "%MAJOR%.%MINOR%.%PATCH%" + ".0"; >> %VERSION_CONSTANTS%
echo public const string FileVersion = "%MAJOR%.%MINOR%.%PATCH%" + ".0"; >> %VERSION_CONSTANTS%
echo public const string Version = AssemblyVersion + Prerelease; >> %VERSION_CONSTANTS%
echo } >> %VERSION_CONSTANTS%
echo } >> %VERSION_CONSTANTS%
::Restore packages
echo Restoring packages...
dotnet restore %~dp0src\BinSkim.sln /p:Configuration=%Configuration% --packages "%NuGetPackageDir%
:: Build the solution
echo Building solution...
dotnet build --no-restore /verbosity:minimal %~dp0src\BinSkim.sln /p:Configuration=%Configuration% /filelogger /fileloggerparameters:Verbosity=detailed || goto :ExitFailed
:nightly
if "%NightlyTest%" EQU "nightly" (
echo Running nightly Tests
dotnet test %~dp0src\BinSkim.sln --no-build --filter TestCategory=NightlyTest
goto :Exit
)
::Run unit tests
echo Run all multitargeting xunit tests
call :RunTestProject BinaryParsers Unit || goto :ExitFailed
call :RunTestProject BinSkim.Rules Unit || goto :ExitFailed
call :RunTestProject BinSkim.Driver Functional || goto :ExitFailed
call :RunTestProject BinSkim.Rules Functional || goto :ExitFailed
::Create the BinSkim platform specific publish packages
echo Creating Platform Specific BinSkim 'Publish' Packages
call :CreatePublishPackage netcoreapp3.1 win-x64 || goto :ExitFailed
call :CreatePublishPackage netcoreapp3.1 linux-x64 || goto :ExitFailed
call :CreatePublishPackage netcoreapp3.1 osx-x64 || goto :ExitFailed
call :CreatePublishPackage net6.0 win-x64 || goto :ExitFailed
call :CreatePublishPackage net6.0 linux-x64 || goto :ExitFailed
call :CreatePublishPackage net6.0 osx-x64 || goto :ExitFailed
::Build NuGet package
echo BuildPackages.cmd
call BuildPackages.cmd || goto :ExitFailed
echo dotnet-format
dotnet tool update --global dotnet-format
::Update BinSkimRules.md to cover any xml changes
echo Exporting any BinSkim rules
.\bld\bin\x64_Release\netcoreapp3.1\BinSkim.exe export-rules .\docs\BinSkimRules.md
goto :Exit
:RunTestProject
set TestProject=%1
set TestType=%2
pushd %~dp0src\Test.%TestType%Tests.%TestProject% && dotnet test --no-build -c %Configuration% && popd
if "%ERRORLEVEL%" NEQ "0" (echo %TestProject% %TestType% tests execution FAILED.)
Exit /B %ERRORLEVEL%
:CreatePublishPackage
set Framework=%~1
set RuntimeArg=%~2
dotnet publish %~dp0src\BinSkim.Driver\BinSkim.Driver.csproj --no-restore -c %Configuration% -f %Framework% --runtime %RuntimeArg% --self-contained
Exit /B %ERRORLEVEL%
:ExitFailed
@echo Build and test did not complete successfully.
Exit /B 1
:Exit