-
Notifications
You must be signed in to change notification settings - Fork 306
/
azure-pipelines.yml
112 lines (95 loc) · 5.06 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
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
resources:
- repo: self
variables:
versionFileName: 'version.txt'
stages:
- stage: Build_and_publish
jobs:
- job: Version
displayName: Read versions
steps:
- powershell: |
$newVersion = Get-Content "$(Build.SourcesDirectory)/$(versionFileName)" -First 1
$releaseInfo = (Get-Content "$(Build.SourcesDirectory)/$(versionFileName)" | Select-Object -Skip 1).Replace('\r\n', '\n')
echo "##vso[task.setvariable variable=newVersion;isOutput=true]$($newVersion)"
echo "##vso[task.setvariable variable=releaseInfo;isOutput=true]$($releaseInfo)"
name: readNewVersionStep
displayName: Read new version
- powershell: |
$json = Invoke-RestMethod -Method 'GET' -Uri "https://api.github.com/repos/vkhorikov/CSharpFunctionalExtensions/releases"
$currentVersion = $json[0].tag_name.Substring(1)
echo "##vso[task.setvariable variable=currentVersion;isOutput=true]$($currentVersion)"
name: readCurrentVersionStep
displayName: Read current version
- job: BuildAndTest
displayName: Build and test
dependsOn: Version
condition: succeeded('Version')
variables:
newVersion: $[ dependencies.Version.outputs['readNewVersionStep.newVersion'] ]
steps:
- script: docker build . -t build-image -f Dockerfile --build-arg Version=$(newVersion)
displayName: Build image
- script: |
docker create --name build-container build-image
docker cp build-container:./app/CSharpFunctionalExtensions.Tests/TestResults ./testresults
displayName: Extract test results
- task: PublishTestResults@2
inputs:
testRunner: VSTest
testResultsFiles: '**/*.trx'
searchFolder: '$(System.DefaultWorkingDirectory)/testresults'
failTaskOnFailedTests: true
displayName: Publish test results
- script: |
docker create --name build-container build-image
docker cp build-container:./app/out ./out
docker cp build-container:./app/out-sn ./out-sn
displayName: Copy artifacts
- publish: ./out
artifact: NuGetPackage
- publish: ./out-sn
artifact: NuGetPackageStrongName
- job: Publish
dependsOn:
- Version
- BuildAndTest
variables:
releaseInfo: $[ dependencies.Version.outputs['readNewVersionStep.releaseInfo'] ]
newVersion: $[ dependencies.Version.outputs['readNewVersionStep.newVersion'] ]
currentVersion: $[ dependencies.Version.outputs['readCurrentVersionStep.currentVersion'] ]
contentTypeHeader1: 'Content-Type: application/json'
contentTypeHeader2: 'Content-Type: application/octet-stream'
authHeader: 'Authorization: Bearer $(gitHubToken)'
createReleaseRequest: '{ "tag_name": "v$(newVersion)", "target_commitish": "master", "name": "v$(newVersion)", "body": "$(releaseInfo)", "draft": false, "prerelease": false }'
condition: and(succeeded('Version'), succeeded('BuildAndTest'), ne(dependencies.Version.outputs['readNewVersionStep.newVersion'], dependencies.Version.outputs['readCurrentVersionStep.currentVersion']))
steps:
- script: |
echo $(newVersion)
echo $(currentVersion)
echo $(releaseInfo)
displayName: Echo versions
- download: current
artifact: NuGetPackage
- download: current
artifact: NuGetPackageStrongName
- script: |
curl -X POST -s -H '$(contentTypeHeader1)' -H '$(authHeader)' https://api.github.com/repos/vkhorikov/CSharpFunctionalExtensions/releases -d '$(createReleaseRequest)'
$json = Invoke-RestMethod -Method 'GET' -Uri "https://api.github.com/repos/vkhorikov/CSharpFunctionalExtensions/releases/latest"
$releaseId = $json.id
curl -X POST -s -H '$(contentTypeHeader2)' -H '$(authHeader)' --data-binary '$(Pipeline.Workspace)/NuGetPackage/CSharpFunctionalExtensions.$(newVersion).nupkg' 'https://uploads.github.com/repos/vkhorikov/CSharpFunctionalExtensions/releases/$(releaseId)/assets?name=CSharpFunctionalExtensions.$(newVersion).nupkg'
curl -X POST -s -H '$(contentTypeHeader2)' -H '$(authHeader)' --data-binary '$(Pipeline.Workspace)/NuGetPackageStrongName/CSharpFunctionalExtensions.StrongName.$(newVersion).nupkg' 'https://uploads.github.com/repos/vkhorikov/CSharpFunctionalExtensions/releases/$(releaseId)/assets?name=CSharpFunctionalExtensions.StrongName.$(newVersion).nupkg'
displayName: Publish to GitHub
condition: and(succeeded(), ne(variables.gitHubToken, ''))
- script: |
dotnet nuget push $(Pipeline.Workspace)/NuGetPackage/CSharpFunctionalExtensions.$(newVersion).nupkg --source https://api.nuget.org/v3/index.json --api-key $(nugetToken)
displayName: Publish to NuGet
condition: and(succeeded(), ne(variables.nugetToken, ''))
- script: |
dotnet nuget push $(Pipeline.Workspace)/NuGetPackageStrongName/CSharpFunctionalExtensions.StrongName.$(newVersion).nupkg --source https://api.nuget.org/v3/index.json --api-key $(nugetToken)
displayName: Publish strong named package to NuGet
condition: and(succeeded(), ne(variables.nugetToken, ''))