1
1
# Copyright (c) Microsoft Corporation. All rights reserved.
2
2
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
- # Build script for Test Platform.
5
-
6
4
[CmdletBinding ()]
7
5
Param (
8
6
[Parameter (Mandatory = $false )]
9
7
[ValidateSet (" Debug" , " Release" )]
10
8
[Alias (" c" )]
11
- [System.String ] $Configuration = " Debug"
9
+ [string ] $Configuration = " Debug" ,
10
+ [string ] $ArtifactsDirectory = " " ,
11
+ [switch ] $Force
12
12
)
13
13
14
14
. $PSScriptRoot \common.lib.ps1
15
15
16
16
#
17
17
# Variables
18
18
#
19
- $rootDirectory = (Get-Item (Split-Path $MyInvocation.MyCommand.Path )).Parent.FullName
19
+ if (-not [string ]::IsNullOrWhiteSpace($ArtifactsDirectory )) {
20
+ $TF_OUT_DIR = $ArtifactsDirectory
21
+ }
20
22
21
23
#
22
24
# Signing configuration
23
25
#
24
26
Write-Verbose " Setup build configuration."
25
- $TPB_Configuration = $Configuration
26
27
27
- function Verify-NugetPackages
28
+ $TF_Configuration = $Configuration
29
+ $TF_AssembliesPattern = @ (" Microsoft.VisualStudio.TestPlatform.*.dll" , " Microsoft.TestPlatform.*.dll" )
30
+ $script :ErrorCount = 0
31
+
32
+ function Test-Assembly ([string ] $Path )
28
33
{
29
- Write-Log " Verify-NugetPackages: Start "
34
+ $signature = Get-AuthenticodeSignature - FilePath $Path
30
35
31
- $nugetInstallPath = Locate- NuGet
36
+ if ($signature.Status -eq " Valid" ) {
37
+ if ($signature.SignerCertificate.Subject -eq " CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" ) {
38
+ Write-Debug " Valid ($ ( $signature.SignerCertificate.Thumbprint ) ): $Path "
39
+ }
40
+ elseif ($signature.SignerCertificate.Subject -eq " CN=Microsoft 3rd Party Application Component, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" ) {
41
+ Write-Debug " Valid ($ ( $signature.SignerCertificate.Thumbprint ) ): $Path [3rd Party]"
42
+ }
43
+ else {
44
+ # For legacy components
45
+ # CN=Microsoft Corporation, OU=AOC, O=Microsoft Corporation, L=Redmond, S=Washington, C=US
46
+ if ($signature.SignerCertificate.Thumbprint -eq " 49D59D86505D82942A076388693F4FB7B21254EE" ) {
47
+ Write-Debug " Valid ($ ( $signature.SignerCertificate.Thumbprint ) ): $Path [Legacy Prod Signed]"
48
+ }
49
+ else {
50
+ Write-FailLog " Invalid ($ ( $signature.SignerCertificate.Thumbprint ) ). File: $Path . [$ ( $signature.SignerCertificate.Subject ) ]"
51
+ }
52
+ }
53
+ }
54
+ else {
55
+ Write-FailLog " Not signed. File: $Path ."
56
+ }
57
+ }
58
+
59
+ function Test-Assemblies ([string ] $Path )
60
+ {
61
+ foreach ($pattern in $TF_AssembliesPattern ) {
62
+ Get-ChildItem - Recurse - Include $pattern $Path | Where-Object { (! $_.PSIsContainer ) } | ForEach-Object {
63
+ Test-Assembly $_.FullName
64
+ }
65
+ }
66
+ }
67
+
68
+ function Test-NugetPackage ([string ] $Path ) {
69
+ $packageFolder = [System.IO.Path ]::GetDirectoryName($Path )
70
+ $fileName = [System.IO.Path ]::GetFileNameWithoutExtension($Path )
71
+ $out = Join-Path $packageFolder $fileName
72
+
73
+ try {
74
+ Write-ToCI " Verifing assemblies in $Path " - type " group"
75
+ Write-Debug " Extracting..."
76
+ if (Test-Path $out ) {
77
+ if (-not $Force ) {
78
+ Write-FailLog " Folder already exists: $out "
79
+ return
80
+ }
81
+
82
+ Remove-Item $out - Recurse - Force
83
+ }
84
+
85
+ Unzip $Path $out
86
+
87
+ Test-Assemblies $out
88
+ } finally {
89
+ if (Test-Path $out ) {
90
+ Remove-Item $out - Recurse - Force
91
+ }
92
+ Write-ToCI - type " endgroup"
93
+ }
94
+ }
32
95
33
- Write-Log " Using nuget.exe installed at $nugetInstallPath "
96
+ function Test-NugetPackages
97
+ {
98
+ Write-Debug " Test-NugetPackages"
99
+
100
+ $nugetInstallPath = Locate- NuGet
101
+ Write-Debug " Using nuget.exe installed at $nugetInstallPath "
34
102
35
- $artifactsDirectory = Join-Path $rootDirectory " artifacts"
36
- $artifactsConfigDirectory = Join-Path $artifactsDirectory $TPB_Configuration
103
+ $artifactsConfigDirectory = Join-Path $TF_OUT_DIR $TF_Configuration
37
104
$packagesDirectory = Join-Path $artifactsConfigDirectory " MSTestPackages"
105
+
38
106
Get-ChildItem - Filter * .nupkg $packagesDirectory | ForEach-Object {
39
- & $nugetInstallPath verify - signature - CertificateFingerprint " 3F9001EA83C560D712C24CF213C3D312CB3BFF51EE89435D3430BD06B5D0EECE;AA12DA22A49BCE7D5C1AE64CC1F3D892F150DA76140F210ABD2CBFFCA2C18A27;" $_.FullName
107
+ try {
108
+ Write-ToCI " Verifing $ ( $_.FullName ) " - type " group"
109
+ & $nugetInstallPath verify - signature - CertificateFingerprint " 3F9001EA83C560D712C24CF213C3D312CB3BFF51EE89435D3430BD06B5D0EECE;AA12DA22A49BCE7D5C1AE64CC1F3D892F150DA76140F210ABD2CBFFCA2C18A27;" $_.FullName
110
+ Test-NugetPackage - path $_.FullName
111
+ } finally {
112
+ Write-ToCI - type " endgroup"
113
+ }
40
114
}
41
115
42
- Write-Log " Verify -NugetPackages: Complete"
116
+ Write-Debug " Test -NugetPackages: Complete"
43
117
}
44
118
45
- function Write-Log ([string ] $message )
119
+ function Write-FailLog ([string ] $message )
120
+ {
121
+ $script :ErrorCount = $script :ErrorCount + 1
122
+ Write-ToCI - message $message - type " error"
123
+ }
124
+
125
+ function Write-Debug ([string ] $message )
126
+ {
127
+ Write-ToCI - message $message - type " debug"
128
+ }
129
+
130
+ function Write-ToCI ([string ] $message , [string ]$type , [switch ]$vso )
46
131
{
47
132
$currentColor = $Host.UI.RawUI.ForegroundColor
48
- $Host.UI.RawUI.ForegroundColor = " Green"
49
- if ($message )
133
+
134
+ if ($type -eq " error" ) {
135
+ $Host.UI.RawUI.ForegroundColor = " Red"
136
+ }
137
+
138
+ if ($message -or $vso -or $type )
50
139
{
51
- Write-Output " ... $message "
140
+ $prefix = " "
141
+ if ($vso ) {
142
+ $prefix = " vso"
143
+ }
144
+
145
+ Write-Output " ##$prefix [$type ]$message "
52
146
}
53
147
$Host.UI.RawUI.ForegroundColor = $currentColor
54
148
}
55
149
56
- Verify- NugetPackages
150
+ try {
151
+ Write-ToCI " Variables used: " - type " group"
152
+ Get-ChildItem variable:TF_*
153
+ Write-Output " "
154
+ Write-Output " "
155
+ } finally {
156
+ Write-ToCI - type " endgroup"
157
+ }
158
+
159
+ Test-NugetPackages
160
+
161
+ if ($script :ErrorCount -gt 0 ) {
162
+ Write-ToCI - message " Verification failed, $ ( $script :ErrorCount ) errors found!" - type " task.logissue" - vso
163
+ }
0 commit comments