forked from HangfireIO/Hangfire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coverity-scan.ps1
65 lines (57 loc) · 2.1 KB
/
coverity-scan.ps1
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
cov-configure --cs
cov-build.exe --dir cov-int build.bat compile
# Compress results.
"Compressing Coverity results..."
$zipEncoderDef = @'
namespace AnalyseCode {
public class PortableFileNameEncoder: System.Text.UTF8Encoding {
public PortableFileNameEncoder() {}
public override byte[] GetBytes(string entry) {
return base.GetBytes(entry.Replace("\\", "/"));
}
}
}
'@
Add-Type -TypeDefinition $zipEncoderDef
[IO.Compression.ZipFile]::CreateFromDirectory(
"$env:APPVEYOR_BUILD_FOLDER\cov-int",
"$env:APPVEYOR_BUILD_FOLDER\$env:APPVEYOR_PROJECT_NAME.zip",
[IO.Compression.CompressionLevel]::Optimal,
$true, # include root directory
(New-Object AnalyseCode.PortableFileNameEncoder))
# Upload results to Coverity server.
"Uploading Coverity results..."
Add-Type -AssemblyName "System.Net.Http"
$client = New-Object Net.Http.HttpClient
$client.Timeout = [TimeSpan]::FromMinutes(20)
$form = New-Object Net.Http.MultipartFormDataContent
# Fill token field.
[Net.Http.HttpContent]$formField =
New-Object Net.Http.StringContent($env:COVERITY_TOKEN)
$form.Add($formField, '"token"')
# Fill email field.
$formField = New-Object Net.Http.StringContent($env:COVERITY_EMAIL)
$form.Add($formField, '"email"')
# Fill file field.
$fs = New-Object IO.FileStream(
"$env:APPVEYOR_BUILD_FOLDER\$env:APPVEYOR_PROJECT_NAME.zip",
[IO.FileMode]::Open,
[IO.FileAccess]::Read)
$formField = New-Object Net.Http.StreamContent($fs)
$form.Add($formField, '"file"', "$env:APPVEYOR_PROJECT_NAME.zip")
# Fill version field.
$formField = New-Object Net.Http.StringContent($env:APPVEYOR_BUILD_VERSION)
$form.Add($formField, '"version"')
# Fill description field.
$formField = New-Object Net.Http.StringContent("AppVeyor scheduled build.")
$form.Add($formField, '"description"')
# Submit form.
$url = "https://scan.coverity.com/builds?project=$env:APPVEYOR_REPO_NAME"
$task = $client.PostAsync($url, $form)
try {
$task.Wait() # throws AggregateException on timeout
} catch [AggregateException] {
throw $_.Exception.InnerException
}
$task.Result
$fs.Close()