-
-
Notifications
You must be signed in to change notification settings - Fork 55
/
stage0.ps1
137 lines (113 loc) · 5.58 KB
/
stage0.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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
Param(
[Parameter(Mandatory=$true)]
[string]$BuildVersion,
[Parameter(Mandatory=$true)]
[string]$Token,
[Parameter(Mandatory=$false)]
[string]$Path = "./artifacts",
[Parameter(Mandatory=$false)]
[Switch]$NoSigning
) #end param
$signTool = "C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64\signtool.exe"
$timestampUrl = "http://timestamp.digicert.com"
$certName = "Nefarius Software Solutions e.U."
function Get-AppVeyorArtifacts
{
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low')]
param(
#The name of the account you wish to download artifacts from
[parameter(Mandatory = $true)]
[string]$Account,
#The name of the project you wish to download artifacts from
[parameter(Mandatory = $true)]
[string]$Project,
#Where to save the downloaded artifacts. Defaults to current directory.
[alias("DownloadDirectory")][string]$Path = '.',
[string]$Token,
#Filter to a specific branch or project directory. You can specify Branch as either branch name ("master") or build version ("0.1.29")
[string]$Branch,
#If you have multiple build jobs, specify which job you wish to retrieve the artifacts from
[string]$JobName,
#Download all files into a single directory, do not preserve any hierarchy that might exist in the artifacts
[switch]$Flat,
[string]$Proxy,
[switch]$ProxyUseDefaultCredentials,
#URL of Appveyor API. You normally shouldn't need to change this.
$apiUrl = 'https://ci.appveyor.com/api'
)
$headers = @{
'Content-type' = 'application/json'
}
if ($Token) {$headers.'Authorization' = "Bearer $token"}
# Prepare proxy args to splat to Invoke-RestMethod
$proxyArgs = @{}
if (-not [string]::IsNullOrEmpty($proxy)) {
$proxyArgs.Add('Proxy', $proxy)
}
if ($proxyUseDefaultCredentials.IsPresent) {
$proxyArgs.Add('ProxyUseDefaultCredentials', $proxyUseDefaultCredentials)
}
$errorActionPreference = 'Stop'
$projectURI = "$apiUrl/projects/$account/$project"
if ($Branch) {$projectURI = $projectURI + "/build/$Branch"}
$projectObject = Invoke-RestMethod -Method Get -Uri $projectURI `
-Headers $headers @proxyArgs
if (-not $projectObject.build.jobs) {throw "No jobs found for this project or the project and/or account name was incorrectly specified"}
if (($projectObject.build.jobs.count -gt 1) -and -not $jobName) {
throw "Multiple Jobs found for the latest build. Please specify the -JobName paramter to select which job you want the artifacts for"
}
if ($JobName) {
$jobid = ($projectObject.build.jobs | Where-Object name -eq "$JobName" | Select-Object -first 1).jobid
if (-not $jobId) {throw "Unable to find a job named $JobName within the latest specified build. Did you spell it correctly?"}
} else {
$jobid = $projectObject.build.jobs[0].jobid
}
$artifacts = Invoke-RestMethod -Method Get -Uri "$apiUrl/buildjobs/$jobId/artifacts" `
-Headers $headers @proxyArgs
$artifacts `
| ? { $psCmdlet.ShouldProcess($_.fileName) } `
| % {
$type = $_.type
$localArtifactPath = $_.fileName -split '/' | % { [Uri]::UnescapeDataString($_) }
if ($flat.IsPresent) {
$localArtifactPath = ($localArtifactPath | select -Last 1)
} else {
$localArtifactPath = $localArtifactPath -join [IO.Path]::DirectorySeparatorChar
}
$localArtifactPath = Join-Path $path $localArtifactPath
$artifactUrl = "$apiUrl/buildjobs/$jobId/artifacts/$($_.fileName)"
Write-Verbose "Downloading $artifactUrl to $localArtifactPath"
New-Item -ItemType Directory -Force -Path (Split-Path -Path $localArtifactPath) | Out-Null
Invoke-RestMethod -Method Get -Uri $artifactUrl -OutFile $localArtifactPath -Headers $headers @proxyArgs
New-Object PSObject -Property @{
'Source' = $artifactUrl
'Type' = $type
'Target' = $localArtifactPath
}
}
}
# Download ARM64 binaries
Get-AppVeyorArtifacts -Account "nefarius" -Project "DsHidMini" -Path $Path -Token $Token -Branch $BuildVersion -JobName "Platform: ARM64"
# Download x64 binaries
Get-AppVeyorArtifacts -Account "nefarius" -Project "DsHidMini" -Path $Path -Token $Token -Branch $BuildVersion -JobName "Platform: x64"
# Download x86 binaries
Get-AppVeyorArtifacts -Account "nefarius" -Project "DsHidMini" -Path $Path -Token $Token -Branch $BuildVersion -JobName "Platform: x86"
# List of files to sign
$files = "`".\artifacts\disk1\*.cab`" " +
"`".\artifacts\bin\*.exe`" " +
"`".\artifacts\bin\ARM64\dshidmini\dshidmini.dll`" " +
"`".\artifacts\bin\x64\dshidmini\dshidmini.dll`" " +
"`".\artifacts\bin\x64\XInput1_3.dll`" " +
"`".\artifacts\bin\ARM64\XInput1_3.dll`" " +
"`".\artifacts\bin\x86\XInput1_3.dll`" "
if ($NoSigning -eq $false) {
# remove existing certificate(s)
Invoke-Expression "& `"$signTool`" remove /s $files"
# sign with only one certificate
Invoke-Expression "& `"$signTool`" sign /v /n `"$certName`" /tr $timestampUrl /fd sha256 /td sha256 $files"
}
#Compress-Archive -Path ".\artifacts\bin\*" -DestinationPath ".\artifacts\dshidmini_v$BuildVersion.zip"
# Print helper job names for sign portal
"DsHidMini ARM64 v$BuildVersion $(Get-Date -Format "dd.MM.yyyy")"
"DsHidMini x64 v$BuildVersion $(Get-Date -Format "dd.MM.yyyy")"
#"DsHidMini x86 v$BuildVersion $(Get-Date -Format "dd.MM.yyyy")"