forked from nanoframework/nf-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-lib-build-only.yml
261 lines (233 loc) · 7.92 KB
/
class-lib-build-only.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
# Copyright (c) .NET Foundation and Contributors
# Portions Copyright (c) Sankarsan Kampa (a.k.a. k3rn31p4nic). All rights reserved.
# See LICENSE file in the project root for full license information.
parameters:
- name: skipNuGetRestore
type: boolean
default: false
- name: skipNuGetCache
type: boolean
default: false
- name: gitUser
type: string
default: nfbot
- name: gitEmail
type: string
default: [email protected]
- name: sonarCloudProject
type: string
default: dummy-key
- name: nugetConfigPath
type: string
default: ''
- name: runUnitTests
type: boolean
default: false
- name: unitTestRunsettings
type: string
default: '$(System.DefaultWorkingDirectory)\.runsettings'
steps:
# need this here in order to persist GitHub credentials
- checkout: self
submodules: true
- script: |
git config --global user.email ${{ parameters.gitEmail }}
git config --global user.name ${{ parameters.gitUser }}
git config --global core.autocrlf true
displayName: Setup git identity
# get commit details
- template: get-commit-details.yml
- template: file-checks.yml
- template: install-nbgv-tool.yml
- template: prepare-release.yml
- task: SonarCloudPrepare@1
condition: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
)
displayName: 'Prepare analysis on SonarCloud'
inputs:
SonarCloud: 'sonarcloud-$(System.TeamProject)'
organization: 'nanoframework'
scannerMode: 'MSBuild'
projectKey: '${{ parameters.sonarCloudProject }}'
extraProperties: |
sonar.exclusions=**/obj/**,**/*.dll
sonar.cs.vscoveragexml.reportsPaths=$(Agent.TempDirectory)/**/**.coverage
sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/**/**.trx
- task: InstallNanoMSBuildComponents@1
condition: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
)
displayName: Install .NET nanoFramework MSBuild components
inputs:
GitHubToken: $(GitHubToken)
- template: install-nuget.yml
- template: cache-nano-nugets.yml
parameters:
skipNuGetCache: ${{ parameters.skipNuGetCache }}
- task: NuGetCommand@2
condition: >-
and(
succeeded(),
not(${{ parameters.skipNuGetRestore }}),
eq(variables['StartReleaseCandidate'], false),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
)
displayName: NuGet restore
retryCountOnTaskFailure: 5
inputs:
restoreSolution: '**/*.sln'
${{ if eq(parameters.nugetConfigPath, '') }}:
feedsToUse: select
${{ else }}:
feedsToUse: config
nugetConfigPath: ${{ parameters.nugetConfigPath }}
- template: versions-check.yml
- task: VSBuild@1
condition: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
)
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
msbuildArgs: '/p:PublicRelease=true'
configuration: '$(buildConfiguration)'
msbuildArchitecture: 'x64'
maximumCpuCount: true
- template: run-unit-tests.yml
parameters:
runUnitTests: '${{ parameters.runUnitTests }}'
unitTestRunsettings: '${{ parameters.unitTestRunsettings }}'
- template: get-assembly-native-version.yml
- powershell: |
# get subject and commit message for commit
$commitMessage = git log --format='%B' -1
# need to flatten message by removing new lines
$commitMessage = $commitMessage -replace "`r`n", " "
if($commitMessage -like "*PUBLISH_RELEASE*")
{
# set variable
Write-Host "$("##vso[task.setvariable variable=RELEASE_DRAFT;isOutput=true]")false"
Write-Host "$("##vso[task.setvariable variable=RELEASE_VERSION;isOutput=true]")true"
Write-Host "Release draft: FALSE"
}
else
{
# set variable
Write-Host "$("##vso[task.setvariable variable=RELEASE_DRAFT;isOutput=true]")true"
Write-Host "$("##vso[task.setvariable variable=RELEASE_VERSION;isOutput=true]")false"
Write-Host "Release draft: TRUE"
}
name: SetReleaseDraftVar
condition: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false)
)
displayName: Set release draft var
- task: SonarCloudAnalyze@1
condition: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
)
displayName: 'Run Code Analysis'
- task: SonarCloudPublish@1
condition: >-
and(
succeeded(),
eq(variables['StartReleaseCandidate'], false),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
)
displayName: 'Publish Quality Gate Result'
inputs:
pollingTimeoutSec: '300'
- task: UseRubyVersion@0
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
eq(variables['StartReleaseCandidate'], false)
)
displayName: Setup Ruby
inputs:
versionSpec: '= 3.0'
addToPath: true
# generate change log
- powershell: |
gem install github_changelog_generator --quiet --no-document
# need to call it passing both cache options with full path otherwise it won't work
github_changelog_generator --token $(GitHubToken) --cache-log $env:AGENT_TEMPDIRECTORY\github-changelog-logger.log --cache-file $env:AGENT_TEMPDIRECTORY\github-changelog-http-cache --pr-wo-labels
condition: >-
and(
succeeded(),
or(
eq(variables['SetReleaseDraftVar.RELEASE_VERSION'], 'True'),
and(
eq(variables['System.PullRequest.PullRequestId'], ''),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')),
startsWith(variables['Build.SourceBranchName'], 'main'),
not(contains(variables['Build.SourceBranchName'], 'update-dependencies'))
)
),
eq(variables['StartReleaseCandidate'], false)
)
displayName: Generate change log
continueOnError: true
# copy change log to artifacts directory
- task: CopyFiles@2
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
not(contains(variables['Build.SourceBranchName'], 'update-dependencies')),
eq(variables['StartReleaseCandidate'], false)
)
displayName: Copy Changelog
continueOnError: true
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)'
Contents: 'CHANGELOG.md'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
# push new changelog to GitHub repo
- task: PowerShell@2
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], ''),
not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')),
not(contains(variables['Build.SourceBranchName'], 'update-dependencies')),
eq(variables['StartReleaseCandidate'], false)
)
displayName: Push changelog to GitHub
continueOnError: true
inputs:
targetType: 'inline'
script: |
git add CHANGELOG.md
git commit -m "Update CHANGELOG for v$(MY_NUGET_VERSION)" -m"***NO_CI***"
git config user.email ${{ parameters.gitEmail }}
git config user.name ${{ parameters.gitUser }}
# 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)"
- task: CopyFiles@1
condition: and(succeeded(), eq(variables['StartReleaseCandidate'], false))
displayName: Collecting CHANGELOG for artifacts
inputs:
sourceFolder: $(Build.SourcesDirectory)
Contents: |
**\CHANGELOG.md
TargetFolder: '$(Build.ArtifactStagingDirectory)'
flattenFolders: true