forked from nanoframework/nanoFramework.IoT.Device
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines.yml
249 lines (220 loc) · 7.18 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
# Copyright (c) .NET Foundation and Contributors
# See LICENSE file in the project root for full license information.
trigger:
branches:
include:
- main
- develop
- release-*
- refs/tags/*
paths:
exclude:
- src/*
- tests/*
- devices/README.md
- devices/key.snk
- .gitignore
- LICENSE.md
- README.md
- tips-trick.md
- assets/*
- config/*
- .github/*
- StyleCop/*
# PR always trigger build
pr:
autoCancel: true
# add nf-tools repo to resources (for Azure Pipelines templates)
resources:
repositories:
- repository: templates
type: github
name: nanoframework/nf-tools
endpoint: nanoframework
pool:
vmImage: 'windows-latest'
variables:
DOTNET_NOLOGO: true
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
# need this here in order to persist GitHub credentials
- checkout: self
submodules: true
- checkout: templates
fetchDepth: 1
- script: |
git config --global user.email "[email protected]"
git config --global user.name "nfbot"
git config --global core.autocrlf true
displayName: Setup git identity
- template: azure-pipelines-templates/install-nuget.yml@templates
- task: Cache@2
displayName: Cache NuGet packages
condition: succeeded()
continueOnError: true
inputs:
key: 'nuget | **/packages.lock.json'
path: $(UserProfile)/.nuget/packages
- task: DotNetCoreCLI@2
displayName: Install nanovc tool
condition: succeeded()
inputs:
command: custom
custom: tool
arguments: install -g nanovc --add-source https://pkgs.dev.azure.com/nanoframework/feed/_packaging/sandbox/nuget/v3/index.json
- task: InstallNanoMSBuildComponents@1
condition: succeeded()
displayName: Install nanoFramework MSBuild components
env:
GITHUB_TOKEN: $(GitHubToken)
# build solutions that need to be build
- task: PowerShell@2
displayName: Build and pack solutions
inputs:
workingDirectory: 'nanoFramework.IoT.Device\devices'
targetType: 'filePath'
filePath: '$(Build.Repository.LocalPath)\nanoFramework.IoT.Device\.pipeline-assets\pipeline-build-solutions.PS1'
env:
MY_GITHUBTOKEN: $(GitHubToken)
- task: CopyFiles@1
condition: succeeded()
displayName: Collecting deployable artifacts
inputs:
sourceFolder: $(Agent.TempDirectory)
Contents: |
*.nupkg
*.snupkg
TargetFolder: '$(Build.ArtifactStagingDirectory)'
flattenFolders: true
# find if there are NuGet artifacts
- task: PowerShell@2
displayName: Count artifacts
name: Count_Artifacts
inputs:
workingDirectory: '$(Build.ArtifactStagingDirectory)'
targetType: inline
script: |
$count = (Get-ChildItem -Path '.' -Filter '*.nupkg' -Recurse).Count
Write-Host $count ' NuGet packages found'
# set variable to forward
echo "##vso[task.setvariable variable=NUGET_COUNT;isOutput=true]$count"
- task: DotNetCoreCLI@2
displayName: Install SignTool tool
condition: >-
and(
succeeded(),
gt(variables['Count_Artifacts.NUGET_COUNT'], 0),
eq(variables['System.PullRequest.PullRequestId'], '')
)
inputs:
command: custom
custom: tool
arguments: install --tool-path . SignClient
- pwsh: |
.\SignClient "Sign" `
--baseDirectory "$(Build.ArtifactStagingDirectory)" `
--input "**/*.nupkg" `
--config "$(Build.Repository.LocalPath)\nanoFramework.IoT.Device\config\SignClient.json" `
--filelist "$(Build.Repository.LocalPath)\nanoFramework.IoT.Device\config\filelist.txt" `
--user "$(SignClientUser)" `
--secret '$(SignClientSecret)' `
--name "IoT.Device" `
--description "IoT.Device" `
--descriptionUrl "https://github.com/$env:Build_Repository_Name"
displayName: Sign packages
continueOnError: true
condition: >-
and(
succeeded(),
gt(variables['Count_Artifacts.NUGET_COUNT'], 0),
eq(variables['System.PullRequest.PullRequestId'], '')
)
# publish artifacts
- task: PublishBuildArtifacts@1
condition: succeeded()
displayName: Publish deployables artifacts
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: deployables
ArtifactType: Container
# push NuGet class lib package to Azure Artifacts (always happens except on PR builds)
- task: NuGetAuthenticate@0
inputs:
nuGetServiceConnections: 'AzureArtifacts-$(System.TeamProject)'
- script: nuget push -ApiKey AzureArtifacts -Source https://pkgs.dev.azure.com/nanoframework/feed/_packaging/sandbox/nuget/v3/index.json *.nupkg -NonInteractive -SkipDuplicate
workingDirectory: '$(Build.ArtifactStagingDirectory)'
condition: >-
and(
succeeded(),
gt(variables['Count_Artifacts.NUGET_COUNT'], 0),
eq(variables['System.PullRequest.PullRequestId'], '')
)
continueOnError: false
displayName: Push NuGet packages to NuGet
# push NuGet class lib package to NuGet (always happens except on PR builds)
- script: nuget push -ApiKey $(NUGETAPIKEY) -Source https://api.nuget.org/v3/index.json *.nupkg -NonInteractive -SkipDuplicate -NoSymbols
workingDirectory: '$(Build.ArtifactStagingDirectory)'
condition: >-
and(
succeeded(),
gt(variables['Count_Artifacts.NUGET_COUNT'], 0),
eq(variables['System.PullRequest.PullRequestId'], '')
)
continueOnError: false
displayName: Push NuGet packages to NuGet
- task: DotNetCoreCLI@2
displayName: Adjust READMEs
condition: >-
and(
succeeded(),
gt(variables['Count_Artifacts.NUGET_COUNT'], 0),
eq(variables['System.PullRequest.PullRequestId'], '')
)
inputs:
command: custom
custom: run
projects: '**/device-listing.csproj'
workingDirectory: 'nanoFramework.IoT.Device'
- task: PowerShell@2
displayName: Push READMEs to GitHub
condition: >-
and(
succeeded(),
gt(variables['Count_Artifacts.NUGET_COUNT'], 0),
eq(variables['System.PullRequest.PullRequestId'], '')
)
continueOnError: true
inputs:
workingDirectory: 'nanoFramework.IoT.Device'
targetType: 'inline'
script: |
git config user.email '[email protected]'
git config user.name 'nfbot'
# check if anything was changed
$repoStatus = "$(git status --short --porcelain)"
if ($repoStatus -ne "")
{
Write-Host "There are changes in README files, changes will be pushed to GitHub"
}
else
{
Write-Host "Repository is clean, no changes to push to GitHub"
exit 0
}
git add README.md
git add devices/README.md
git commit -m "Update device lists" -m"***NO_CI***"
git rebase origin/develop
# compute authorization header in format "AUTHORIZATION: basic 'encoded token'"
# 'encoded token' is the Base64 of the string "nfbot:personal-token"
$auth = "basic $([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("nfbot:$(GitHubToken)")))"
git -c http.extraheader="AUTHORIZATION: $auth" push origin "HEAD:$(Build.SourceBranchName)"
# step from template @ nf-tools repo
# report error
- template: azure-pipelines-templates/discord-webhook-task.yml@templates
parameters:
workingDirectory: 'nanoFramework.IoT.Device'
status: 'failure'
webhookUrl: '$(DiscordWebhook)'
message: ''