-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-nuget.yaml
121 lines (108 loc) · 3.66 KB
/
build-nuget.yaml
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
parameters:
- name: repo
type: string
default:
- name: project
type: string
default:
- name: sonarcloud
type: boolean
default: true
variables:
- group: SonarCloud
- name: releaseExists
value: false
- name: version
value:
- name: targetFramework
value:
- name: sonarImageVersion
value:
jobs:
- job:
pool:
vmImage: ubuntu-latest
workspace:
clean: all
steps:
- task: PowerShell@2
displayName: Set version
inputs:
targetType: 'inline'
script: |
$csprojVersion = ([xml](Get-Content '${{ parameters.project }}/${{ parameters.project }}.csproj')).Project.PropertyGroup.Version
Write-Host "##vso[task.setvariable variable=version;]$csprojVersion"
- task: PowerShell@2
displayName: Set target framework
inputs:
targetType: 'inline'
script: |
$csprojVersion = ([xml](Get-Content '${{ parameters.project }}/${{ parameters.project }}.csproj')).Project.PropertyGroup.TargetFramework
Write-Host "##vso[task.setvariable variable=targetFramework;]$csprojVersion"
- task: DotNetCoreCLI@2
displayName: Restore
inputs:
command: restore
arguments: '--configuration Release'
restoreSolution: '**/*.sln'
- task: DotNetCoreCLI@2
displayName: Build
inputs:
command: build
arguments: '--configuration Release'
projects: '**/*.sln'
- task: PowerShell@2
displayName: Set Sonar image version
inputs:
targetType: 'inline'
script: |
switch ("$(targetFramework)")
{
"netcoreapp3.1" { $tag = "1.2.3-dotnet3.1"; Break }
"net6.0" { $tag = "1.5.0-dotnet6.0"; Break }
"net8.0" { $tag = "1.6.0-dotnet8.0"; Break }
}
Write-Host "##vso[task.setvariable variable=sonarImageVersion;]$tag"
- script: |
cd $(Agent.BuildDirectory)/s/${{ parameters.repo }}
docker run \
-v $(pwd)/:/home/dotnet/project \
-e SONAR_PROJECT_KEY=johnwatson484_${{ parameters.repo }} \
-e SONAR_TOKEN=$(token) \
-e SONAR_ORGANIZATION_KEY=johnwatson484 \
defradigital/ffc-dotnet-core-sonar:$(sonarImageVersion)
displayName: SonarCloud analysis (.NET)
condition: and(succeeded(), eq('${{ parameters.sonarcloud }}', true))
- script: |
dotnet pack -c Release --no-build -o $(Build.ArtifactStagingDirectory)
displayName: NuGet pack
- task: NuGetCommand@2
displayName: 'NuGet push'
inputs:
command: push
nuGetFeedType: external
publishFeedCredentials: NuGet
allowPackageConflicts: true
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg'
- task: PowerShell@2
displayName: Check GitHub release
inputs:
targetType: 'inline'
script: |
$releaseExists = (Invoke-RestMethod -SkipHttpErrorCheck -Uri 'https://api.github.com/repos/johnwatson484/${{ parameters.repo }}/releases/tags/$(version)').tag_name -eq '$(version)'
Write-Host "##vso[task.setvariable variable=releaseExists;]$releaseExists"
- task: GitHubRelease@1
displayName: GitHub release
inputs:
gitHubConnection: 'John D Watson PAT'
repositoryName: '$(Build.Repository.Name)'
action: 'create'
target: '$(Build.SourceVersion)'
tagSource: 'userSpecifiedTag'
tag: '$(version)'
title: '$(version)'
releaseNotesSource: 'inline'
changeLogCompareToRelease: 'lastFullRelease'
changeLogType: 'commitBased'
continueOnError: true
condition: and(succeeded(), eq(variables.releaseExists, false))