forked from vkhorikov/CSharpFunctionalExtensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathazure-pipelines.yml
More file actions
75 lines (70 loc) · 3.76 KB
/
azure-pipelines.yml
File metadata and controls
75 lines (70 loc) · 3.76 KB
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
trigger:
branches:
include:
- master
resources:
- repo: self
variables:
tag: '$(Build.BuildId)'
stages:
- stage: Build_and_publish
jobs:
- job: Version
pool:
vmImage: 'ubuntu-16.04'
steps:
- script: echo "##vso[task.setvariable variable=versionVar;isOutput=true]$(curl -s https://raw.githubusercontent.com/vkhorikov/CSharpFunctionalExtensions/master/version.txt | head -1)"
name: setVersionStep
displayName: Set version
- script: echo $(setVersionStep.versionVar)
displayName: Echo version
- script: echo "##vso[task.setvariable variable=releaseInfoVar;isOutput=true]$(curl -s https://raw.githubusercontent.com/vkhorikov/CSharpFunctionalExtensions/master/version.txt | tail -n +2 | sed 's/$/\\r\\n/' | tr -d '\n')"
name: setReleaseInfoStep
displayName: Set release info
- script: echo $(setReleaseInfoStep.releaseInfoVar)
displayName: Echo release info
- script: echo "##vso[task.setvariable variable=currentVersionVar;isOutput=true]$(curl -s https://api.github.com/repos/vkhorikov/CSharpFunctionalExtensions/releases | python -c 'import json,sys;obj=json.load(sys.stdin);print obj[0]["tag_name"] if len(obj) > 0 else ""' | cut -c 2-100)"
name: setCurrentVersionStep
displayName: Set current version
- script: echo $(setCurrentVersionStep.currentVersionVar)
displayName: Echo current version
- job: Build
dependsOn: Version
pool:
vmImage: 'ubuntu-16.04'
variables:
version: $[ dependencies.Version.outputs['setVersionStep.versionVar'] ]
steps:
- script: docker build . -t build-image -f Dockerfile --build-arg Version=$(version)
displayName: Build an image
- script: docker create --name build-container build-image
displayName: Create a container
- script: docker cp build-container:./app/out ./out
displayName: Copy artifacts
- publish: ./out
artifact: NuGetPackage
- job: Publish
dependsOn:
- Version
- Build
pool:
vmImage: 'ubuntu-16.04'
variables:
releaseInfo: $[ dependencies.Version.outputs['setReleaseInfoStep.releaseInfoVar'] ]
version: $[ dependencies.Version.outputs['setVersionStep.versionVar'] ]
contentTypeHeader1: 'Content-Type: application/json'
contentTypeHeader2: 'Content-Type: application/octet-stream'
authHeader: 'Authorization: token $(gitHubToken)'
createReleaseRequest: '{ "tag_name": "v$(version)", "target_commitish": "master", "name": "v$(version)", "body": "$(releaseInfo)", "draft": false, "prerelease": false }'
condition: ne(dependencies.Version.outputs['setVersionStep.versionVar'], dependencies.Version.outputs['setCurrentVersionStep.currentVersionVar'])
steps:
- download: current
artifact: NuGetPackage
- script: curl -X POST -s -H '$(contentTypeHeader1)' -H '$(authHeader)' https://api.github.com/repos/vkhorikov/CSharpFunctionalExtensions/releases -d '$(createReleaseRequest)'
displayName: Create release
- script: echo "##vso[task.setvariable variable=releaseId]$(curl -s https://api.github.com/repos/vkhorikov/CSharpFunctionalExtensions/releases/latest | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["id"]')"
displayName: Get release id
- script: curl -X POST -s -H '$(contentTypeHeader2)' -H '$(authHeader)' -F 'data=@$(Pipeline.Workspace)/NuGetPackage/CSharpFunctionalExtensions.$(version).nupkg' https://uploads.github.com/repos/vkhorikov/CSharpFunctionalExtensions/releases/$(releaseId)/assets?name=CSharpFunctionalExtensions.$(version).nupkg
displayName: Upload release artifact
- script: dotnet nuget push $(Pipeline.Workspace)/NuGetPackage/CSharpFunctionalExtensions.$(version).nupkg --source https://api.nuget.org/v3/index.json --api-key $(nugetToken)
displayName: NuGet push