This repository has been archived by the owner on Aug 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathazure-pipelines.yml
122 lines (116 loc) · 3.93 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
# Go
# Build your Go project.
# Add steps that test, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/go
trigger:
branches:
include:
- master
- refs/tags/*
tags:
include:
- v*
stages:
- stage: build
displayName: BuildExecutable
variables:
GOBIN: '$(GOPATH)/bin' # Go binaries path
GOROOT: '/usr/local/go1.11' # Go installation path
GOPATH: '$(system.defaultWorkingDirectory)/gopath' # Go workspace path
GO111MODULE: 'on'
modulePath: '$(GOPATH)/src/github.com/$(build.repository.name)' # Path to the module's code
jobs:
- job: Build
pool:
vmImage: 'ubuntu-latest'
strategy:
matrix:
Linux:
os.platform: 'linux'
Darwin:
os.platform: 'darwin'
Windows:
os.platform: 'windows'
extension: '.exe'
steps:
- script: |
mkdir -p '$(GOBIN)'
mkdir -p '$(GOPATH)/pkg'
mkdir -p '$(modulePath)'
shopt -s extglob
shopt -s dotglob
mv !(gopath) '$(modulePath)'
echo '##vso[task.prependpath]$(GOBIN)'
echo '##vso[task.prependpath]$(GOROOT)/bin'
displayName: 'Set up the Go workspace'
- script: |
go version
GOOS=$(os.platform) go get -v -t -d ./...
workingDirectory: '$(modulePath)'
displayName: 'Get dependencies'
- script: |
go get github.com/jstemmer/go-junit-report
go get github.com/axw/gocov/gocov
go get github.com/AlekSi/gocov-xml
go get -u github.com/matm/gocov-html
go test -v ./... -coverprofile=coverage.txt -covermode count 2>&1 | go-junit-report > report.xml
gocov convert coverage.txt > coverage.json
gocov-xml < coverage.json > coverage.xml
mkdir coverage
gocov-html < coverage.json > coverage/index.html
workingDirectory: '$(modulePath)'
displayName: 'Run Go test'
- task: PublishTestResults@2
inputs:
testRunner: JUnit
testResultsFiles: $(System.DefaultWorkingDirectory)/**/report.xml
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(System.DefaultWorkingDirectory)/**/coverage.xml
reportDirectory: $(System.DefaultWorkingDirectory)/**/coverage
- script: |
GOOS=$(os.platform) GOARCH=amd64 go build -v -o build/barometer-amd64-$(os.platform)$(extension) .
workingDirectory: '$(modulePath)'
displayName: 'Build executable'
- task: CopyFiles@2
inputs:
sourceFolder: $(modulePath)/build/
contents: '*'
targetFolder: $(Build.ArtifactStagingDirectory)
displayName: 'Copy files to Artifact Staging Directory'
- task: PublishPipelineArtifact@0
inputs:
artifactName: barometer-$(os.platform)
targetPath: $(Build.ArtifactStagingDirectory)
displayName: 'Publish pipeline artifact'
- stage: publish
displayName: PublishArtifacts
jobs:
- job: Publish
steps:
- task: DownloadPipelineArtifact@2
- script: |
mkdir artifacts
cp '$(Pipeline.Workspace)'/barometer-*/* artifacts
ls artifacts/*
displayName: Copy all artifacts
- task: GithubRelease@0
condition: startsWith(variables['Build.SourceBranch'], 'refs/tags/')
inputs:
gitHubConnection: barometer-release
repositoryName: '$(build.Repository.Name)'
assets: artifacts/*
addChangeLog: true
compareWith: 'lastRelease'
displayName: 'Create Github release'
- task: Docker@2
condition: startsWith(variables['Build.SourceBranch'], 'refs/tags/')
inputs:
command: buildAndPush
repository: burnout-barometer
containerRegistry: acrServiceConnection
tags: |
latest
$(Build.SourceBranchName)
displayName: 'Build Docker image and push'