forked from Azure/azure-notificationhubs-xamarin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines.yml
200 lines (196 loc) · 8.42 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
variables:
# job parameters
mainBranchName: 'main'
submodules: false
# job software version parameters
macosImage: 'macos-latest'
netcoreVersion: '3.1.100'
apiToolsVersion: '1.3.1'
monoVersion: 'Latest'
xcodeVersion: '11.6'
cake: '0.38.4'
# build parameters
cakeTarget: 'ci'
cakeFile: 'src/bindings/build.cake'
cakeExtraArgs: ''
artifactsPath: 'src/bindings/output'
# build parameters
buildType: 'basic'
verbosity: 'normal'
configuration: 'Release'
RunPoliCheck: 'false'
resources:
repositories:
- repository: xamarin-templates
type: github
name: xamarin/yaml-templates
endpoint: xamarin
jobs:
- job: build_native
displayName: Build Azure Notification Hubs Native Bindings
pool:
vmImage: $(macosImage)
steps:
- checkout: self
submodules: $(submodules)
# before the build starts, make sure the tooling is as expected
- bash: 'sudo $AGENT_HOMEDIRECTORY/scripts/select-xamarin-sdk.sh $(monoVersion)'
displayName: 'Switch to the latest Xamarin SDK'
- bash: echo '##vso[task.setvariable variable=MD_APPLE_SDK_ROOT;]'/Applications/Xcode_$(xcodeVersion).app;sudo xcode-select --switch /Applications/Xcode_$(xcodeVersion).app/Contents/Developer
displayName: 'Switch to the latest Xcode'
- bash: echo '##vso[task.setvariable variable=PATH;]'$PATH:$HOME/.dotnet/tools
displayName: 'Add ~/.dotnet/tools to the PATH environment variable'
- task: UseDotNet@2
displayName: 'Switch to the correct version of the .NET Core SDK'
inputs:
version: $(netcoreVersion)
includePreviewVersions: false
- pwsh: |
dotnet tool install -g api-tools --version $(apiToolsVersion)
dotnet tool install -g cake.tool --version $(cake)
displayName: 'Install required .NET Core global tools'
- task: NuGetToolInstaller@1
inputs:
checkLatest: true
displayName: 'Download the latest nuget.exe'
# determine the last successful build for "main" branch
- pwsh: |
# determine the "main" branch
$mainBranch = "$(mainBranchName)"
$encodedBranch = [Uri]::EscapeDataString("refs/heads/$mainBranch")
Write-Host "Main branch: $mainBranch"
# determine the "current" branch
$branch = "$(Build.SourceBranch)"
if ("$env:SYSTEM_PULLREQUEST_TARGETBRANCH") {
$branch = "$env:SYSTEM_PULLREQUEST_TARGETBRANCH"
}
if ($branch.StartsWith("refs/heads/")) {
$branch = $branch.Substring(11)
Write-Host "Current branch: $branch"
}
if ($branch.StartsWith("refs/tags/")) {
$branch = $branch.Substring(10)
Write-Host "Current tag: $branch"
}
if (($branch -eq $mainBranch) -and ("$(System.PullRequest.IsFork)" -eq "False")) {
Write-Host "Branch is main, fetching last successful build commit..."
$url = "$(System.TeamFoundationCollectionUri)$(System.TeamProjectId)/_apis/build/builds/?definitions=$(System.DefinitionId)&branchName=$encodedBranch&statusFilter=completed&resultFilter=succeeded&api-version=5.0"
Write-Host "URL for last successful main build: $url"
$json = Invoke-RestMethod -Uri $url -Headers @{
Authorization = "Bearer $(System.AccessToken)"
}
Write-Host "JSON response:"
Write-Host "$json"
$lastSuccessfulBuildCommit = try { $json.value[0].sourceVersion; } catch { $null }
}
if ($lastSuccessfulBuildCommit) {
Write-Host "Last successful commit found: $lastSuccessfulBuildCommit"
} else {
$lastSuccessfulBuildCommit = "origin/$mainBranch"
Write-Host "No previously successful build found, using $lastSuccessfulBuildCommit."
}
Write-Host "##vso[task.setvariable variable=GitLastSuccessfulCommit]$lastSuccessfulBuildCommit"
displayName: 'Find the last successful commit'
- pwsh: |
dotnet cake $(cakeFile) $(cakeExtraArgs)`
--gitpreviouscommit="$(GitLastSuccessfulCommit)" `
--gitcommit="$(Build.SourceVersion)" `
--gitbranch="$(Build.SourceBranch)" `
--target="$(cakeTarget)" `
--configuration="$(configuration)" `
--verbosity="$(verbosity)"
displayName: 'Run build'
env:
JavaSdkDirectory: $(JAVA_HOME)
RepositoryCommit: $(Build.SourceVersion)
RepositoryBranch: $(Build.SourceBranchName)
RepositoryUrl: $(Build.Repository.Uri)
RepositoryType: "git"
# after the build is complete
- task: PublishBuildArtifacts@1
displayName: 'Publish artifacts'
inputs:
PathToPublish: $(artifactsPath)
ArtifactName: nuget
- task: PublishBuildArtifacts@1
displayName: 'Publish platform artifacts'
condition: always()
inputs:
PathToPublish: $(artifactsPath)
ArtifactName: output-$(System.JobName)
# run any required checks
- ${{ if eq(variables['System.TeamProject'], 'devdiv') }}:
- task: ComponentGovernanceComponentDetection@0
displayName: 'Run component detection'
condition: and(always(), eq('refs/heads/$(mainBranchName)', variables['Build.SourceBranch']))
inputs:
scanType: 'Register'
verbosity: 'Verbose'
alertWarningLevel: 'High'
- job: build_xamarin_forms
displayName: Build Azure Notification Hubs Xamarn Forms SDK
pool:
vmImage: windows-2019
steps:
- checkout: self
submodules: $(submodules)
- task: UseDotNet@2
displayName: 'Use .Net Core sdk'
inputs:
version: $(netcoreVersion)
includePreviewVersions: false
- task: MSBuild@1
displayName: Build Solution
inputs:
solution: src/Microsoft.Azure.NotificationHubs.Client/Microsoft.Azure.NotificationHubs.Client.csproj
configuration: Release
msbuildArguments: '/restore /t:Build /p:ContinuousIntegrationBuild=true /p:Deterministic=false'
- task: MSBuild@1
displayName: Pack NuGets
inputs:
solution: src/Microsoft.Azure.NotificationHubs.Client/Microsoft.Azure.NotificationHubs.Client.csproj
configuration: Release
msbuildArguments: '/t:Pack /p:PackageOutputPath="$(Build.ArtifactStagingDirectory)/nuget"'
# publish the packages
- task: PublishBuildArtifacts@1
displayName: 'Publish Unsigned NuGets'
inputs:
artifactName: nuget
pathToPublish: '$(Build.ArtifactStagingDirectory)/nuget'
# make sure we are following the rules, but only on the main build
- ${{ if eq(variables['System.TeamProject'], 'devdiv') }}:
- task: ms.vss-governance-buildtask.governance-build-task-component-detection.ComponentGovernanceComponentDetection@0
condition: not(startsWith(variables['Build.SourceBranch'], 'refs/tags/'))
displayName: Component Detection - Log
inputs:
scanType: LogOnly
- task: ms.vss-governance-buildtask.governance-build-task-component-detection.ComponentGovernanceComponentDetection@0
condition: startsWith(variables['Build.SourceBranch'], 'refs/tags/')
displayName: Component Detection - Report
- task: securedevelopmentteam.vss-secure-development-tools.build-task-policheck.PoliCheck@1
condition: eq(variables['RunPoliCheck'], 'true')
displayName: 'PoliCheck'
inputs:
targetType: F
# only sign the packages when running on Windows, and using the private server which has the certificates
- ${{ if eq(variables['System.TeamProject'], 'devdiv') }}:
- job: signing
displayName: Signing NuGets
dependsOn: [ build_xamarin_forms, build_native ]
pool:
name: VSEng-XamarinCustom
demands:
- corpnet
condition: succeeded()
steps:
# don't checkout code and sign the packages
- checkout: none
- template: sign-artifacts.yml@xamarin-templates
parameters:
targetFolder: '$(Build.ArtifactStagingDirectory)/signed'
# publish the signed packages
- task: PublishBuildArtifacts@1
displayName: 'Publish Signed NuGets'
inputs:
artifactName: nuget-signed
pathToPublish: '$(Build.ArtifactStagingDirectory)/signed'