-
Notifications
You must be signed in to change notification settings - Fork 27
/
azure-pipelines.yml
310 lines (279 loc) · 11.9 KB
/
azure-pipelines.yml
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# .NET Desktop
# Build and run tests for .NET Desktop or Windows classic desktop solutions.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/windows/dot-net
# Trigger on all branches. Only some branches however will run certain steps
#trigger:
#- *
pool:
vmImage: 'windows-latest'
variables:
solution: 'LegendaryExplorer\LegendaryExplorer.sln'
buildPlatform: 'x64'
buildConfiguration: 'WinAzureRelease'
appMajorMin: '6.5'
appMajor: '6'
appMinor: '5'
appPatch: '0'
netVersion: '8'
disable.coverage.autogenerate: 'true'
doxygenUrl: "https://www.doxygen.nl/files/doxygen-1.9.5.windows.x64.bin.zip"
doxygenWorkingDir: '$(Pipeline.Workspace)\Documentation\Doxygen'
doxygenOutputDir: '$(Pipeline.Workspace)\Documentation\Output'
steps:
- checkout: self
clean: true
persistCredentials: true
submodules: recursive
# DEBUG for Find Text Transform
#- task: CmdLine@2
# inputs:
# script: 'tree "C:\Program Files (x86)\Microsoft Visual Studio" /F /A'
# Change artifact name when the version major/minor changes
- task: PowerShell@2
displayName: 'Prepare for pipeline build'
inputs:
targetType: 'inline'
script: |
$artifactname = "legendaryexplorernightly_$(appMajorMin).$(appPatch).$(Build.BuildId)"
# Date--------------------------------------------
$date=$(Get-Date -Format s);
Write-Host "##vso[task.setvariable variable=time]$date"
# Commit Message (Multiliner)-----------------------
$commitMessageFull = git log -1 --pretty=%B
$numlines = $($commitMessageFull | measure).Count
if ($numlines > 0) {
$commitMessageFull=[system.String]::Join(" ", $commitMessageFull)
}
Write-Host "##vso[task.setvariable variable=commitMessageFull]$commitMessageFull"
# Author-------------------------------------------
$author = git log -1 --pretty=format:'%an'
Write-Host "##vso[task.setvariable variable=author]$author"
Write-Host "Author: $($author)"
# Set version var
$ver = New-Object System.Version($appMajor, $appMinor, $appPatch, [int]$(Build.BuildId))
Write-Host "Version: $($ver)"
echo "##vso[task.setvariable variable=VER]$($ver)"
# Get report generator
dotnet tool install -g dotnet-reportgenerator-globaltool
# API keys for telemety (does not trigger on PR)
- task: PowerShell@2
displayName: 'Set telemetry key'
condition: and(succeeded(), ne(variables['Build.SourceBranchName'], 'merge'))
inputs:
targetType: 'inline'
script: |
# API Keys for telemetry--------------------------
$apikeysprivatefile = "namespace LegendaryExplorer.Misc.Telemetry`n{`n public static partial class APIKeys`n {`n public static string Private_AppCenter {get;} = `"$(AppCenterKey)`";`n }`n}"
Set-Content -Path "$(Build.Repository.LocalPath)\LegendaryExplorer\LegendaryExplorer\Misc\Telemetry\APIKeysPrivate.cs" -Value $apikeysprivatefile
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
displayName: 'Restore Nuget packages'
inputs:
restoreSolution: '$(solution)'
# Test LegendaryExplorerCore
- task: DotNetCoreCLI@2
displayName: 'Test LEC'
inputs:
command: 'test'
projects: 'LegendaryExplorer/LegendaryExplorerCore.Tests/LegendaryExplorerCore.Tests.csproj'
arguments: '--configuration WinAzureTest /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:DebugType=pdbonly -v normal'
publishTestResults: true
- task: PowerShell@2
displayName: 'Generate code coverage HTML'
inputs:
targetType: 'inline'
script: 'reportgenerator -reports:/**/coverage.cobertura.xml -targetdir:CoverageReport -reporttypes:"HtmlInline_AzurePipelines;Cobertura" -classfilters:"-*Gammtek*;-*.SharpDX.*" -verbosity:Verbose'
workingDirectory: '$(Build.SourcesDirectory)'
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage'
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '**/coverage.cobertura.xml'
reportDirectory: 'CoverageReport'
failIfCoverageEmpty: true
# Build TexConverter in Release mode
- task: MSBuild@1
displayName: 'Build TexConverter'
inputs:
solution: 'LegendaryExplorer\TexConverter\TexConverter.vcxproj'
msbuildArchitecture: 'x64'
platform: 'x64'
configuration: 'WinRelease'
clean: true
createLogFile: true
# Build Legendary Explorer UI Application
- task: VSBuild@1
displayName: 'Build LEX'
inputs:
solution: '$(solution)'
msbuildArgs: '/p:Version=$(appMajor).$(appMinor).$(appPatch).$(Build.BuildId)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
# Cleanup garbage from SQLite
- task: PowerShell@2
displayName: 'Cleanup build'
inputs:
filePath: '$(Build.SourcesDirectory)/LegendaryExplorer/LegendaryExplorer/BuildTools/PostBuildCleanup.ps1'
arguments: '"$(Build.SourcesDirectory)/LegendaryExplorer/LegendaryExplorer/bin/x64/$(buildConfiguration)/net$(netVersion).0-windows"'
errorActionPreference: continue
- task: ArchiveFiles@2
displayName: '7z LEX'
inputs:
rootFolderOrFile: '$(Build.SourcesDirectory)/LegendaryExplorer/LegendaryExplorer/bin/x64/$(buildConfiguration)/net$(netVersion).0-windows'
includeRootFolder: false
archiveType: '7z'
archiveFile: '$(Build.ArtifactStagingDirectory)/legendaryexplorer_nightly_cibuild_$(appMajorMin).$(appPatch).$(Build.BuildId).7z'
replaceExistingArchive: true
sevenZipCompression: maximum
- task: PublishBuildArtifacts@1
displayName: 'Publish LEX'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'legendaryexplorernightly_$(appMajorMin).$(appPatch).$(Build.BuildId)'
publishLocation: 'Container'
# Virus Total Scan - Since we send this to M3 and users can directly download it
#- task: PowerShell@2
# displayName: 'VirusTotal Scan'
# condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'Beta'))
# env:
# virusTotalApiKey: $(virusTotalApiKey)
# inputs:
# targetType: 'inline'
# script: |
# $apikey = ${env:virusTotalApiKey}
# $headers=@{}
# $headers.Add("Accept", "application/json")
# $headers.Add("x-apikey", $apikey)
# # Step 1: Get special upload endpoint
# Write-Host "Getting upload URL"
# $response = Invoke-RestMethod -Uri 'https://www.virustotal.com/api/v3/files/upload_url' -Method GET -Headers $headers
# $endpoint = $response.data
# # Step 2: Upload to special endpoint
# $artifactPath = "$(Build.ArtifactStagingDirectory)/legendaryexplorer_nightly_cibuild_$(appMajorMin).$(appPatch).$(Build.BuildId).7z"
# Write-Host "Uploading artifact to VirusTotal: $artifactPath"
# $body=@{
# file = Get-Item $artifactPath
# }
# $response = Invoke-RestMethod -Uri $endpoint -Method POST -Form $body -Headers $headers
# # Step 3: Wait for result to check it
# if ($response.data.type -eq "analysis") {
# # Give virustotal a minute to analyze before we check and waste our api calls
# Start-Sleep -Seconds 60
# $id = $response.data.id
# $i = 8 # Max 8 attempts
# while ($i -gt 0) {
# Write-Host "Checking if VirusTotal scan has completed..."
# $i = $i - 1
# $result = Invoke-RestMethod -Uri "https://www.virustotal.com/api/v3/analyses/$id" -Method GET -Headers $headers
# $attributes = $result.data.attributes
# if ($attributes.status -eq "completed"){
# $sha256 = Get-FileHash -Algorithm SHA256 -Path $artifactPath
# Write-Host "VirusTotal result: https://www.virustotal.com/gui/file/$($sha256.Hash)"
# if ($attributes.stats.malicious -ge 2 -or $attributes.stats.suspicious -ge 5) {
# # We got a problem
# Write-Host "##vso[task.LogIssue type=error;]VirusTotal scan returned multiple malicious/suspicious detections! Suspicious: $($attributes.stats.suspicious) Malicious: $($attributes.stats.malicious)"
# exit 1
# } else {
# Write-Host "VirusTotal scan returned OK"
# exit 0
# }
# }
# Write-Host "Scan not complete, waiting another 45 seconds for another $i tries"
# Start-Sleep -Seconds 45
# }
# }
# pwsh: true
- task: Cache@2
displayName: "Cache Doxygen install"
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'Beta'))
inputs:
key: '"$(doxygenUrl)"'
path: $(doxygenWorkingDir)
cacheHitVar: 'doxygenCacheRestored'
- task: PowerShell@2
displayName: "Download Doxygen"
condition: and(succeeded(), and(eq(variables['Build.SourceBranchName'], 'Beta'), ne(variables.doxygenCacheRestored, 'true')))
inputs:
targetType: 'inline'
script: |
$doxygenUrl = ${env:doxygenUrl}
$outpath = ${env:doxygenWorkingDir}
if(!(Test-Path $outpath))
{
Write-Host "Creating $outpath";
New-Item -ItemType Directory -Force -Path $outpath
}
$zipDownloadPath = "$outpath\" + $(Split-Path -Path $doxygenUrl -Leaf)
Write-Host "Downloading from $doxygenUrl to $zipDownloadPath"
Invoke-WebRequest -Uri $doxygenUrl -OutFile $zipDownloadPath
Expand-Archive -LiteralPath $zipDownloadPath -DestinationPath $outpath
Remove-Item $zipDownloadPath
- task: PowerShell@2
displayName: "Build documentation, commit to GitHub Pages"
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'Beta'))
inputs:
targetType: 'inline'
script: |
git config user.email "[email protected]"
git config user.name "ME3Tweaks-LEC-Documentation"
$(doxygenWorkingDir)\doxygen.exe $(Build.SourcesDirectory)\Documentation\DoxygenConfigAzurePipelines
git restore $(Build.SourcesDirectory)\LegendaryExplorer\LegendaryExplorerCore\Libraries\Windows\TexConverter.dll
git checkout gh-pages
if(Test-Path .\nightly\)
{
Remove-Item .\nightly\* -Recurse
}
Copy-Item -Path "$(doxygenOutputDir)\html\*" -Destination .\nightly -Recurse
git add .\nightly\*
git add .\nightly\**\*
git commit -m "Update documentation [skip ci]"
git push origin gh-pages
# Notify ME3Tweaks that a new beta build has been built
- task: PowerShell@2
displayName: 'Notify ME3Tweaks'
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'Beta'))
inputs:
targetType: 'inline'
script: |
# Webrequest using powershell since invokerestapi doesn't work on anything but server jobs
Invoke-WebRequest -Uri $(legendaryExplorerApiEndpoint)
errorActionPreference: 'continue'
# NOT PULL REQUEST DISCORD WEBHOOK
- task: ado-discord-webhook@1
displayName: 'Discord - New official nightly'
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'Beta'))
inputs:
channelId: '$(discord_channel_id)'
webhookKey: '$(discord_webhook_key)'
name: 'Azure DevOps CI'
avatar: 'https://i.imgur.com/mUtPj2S.png'
messageType: 'embeds'
embeds: |
[{
"title": "Legendary Explorer Build Complete",
"description": "A new nightly build of Legendary Explorer has been built. You can manually download this build through this link. Nightly builds may be unstable and have bugs.",
"thumbnail": {
"url": "https://i.imgur.com/mUtPj2S.png",
"height": 64,
"width": 64
},
"fields": [{
"name": "Triggering commit",
"value": "$(commitMessageFull)"
},
{
"name": "Author",
"value": "$(author)"
},
{
"name": "Branch",
"value": "$(Build.SourceBranchName)"
},
{
"name": "Version",
"value": "$(appMajorMin).$(appPatch).$(Build.BuildId)"
}],
"url": "https://dev.azure.com/ME3Tweaks/LegendaryExplorer/_build/results?buildId=$(Build.BuildId)&view=artifacts",
"timestamp": "$(time)"
}]