This repository has been archived by the owner on Mar 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathazure-pipelines.yml
124 lines (110 loc) · 4.67 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
123
124
# Runs for every merge request on MASTER
# Sets up a Go environment
# Runs all unit tests on hwsc-user-svc
# Displays unit test results and code coverages
# Tests main.go executable build
# Tests docker image build (Dockerfile)
# Pushes built docker image to docker hub account
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
# runs tests/builds on merge to master
trigger:
- master
# runs tests/builds on PULL REQUEST master
pr: none
# determine your virtual machine image
# each time pipeline is ran, you get a fresh Linux virtual machine
# this vm is discarded after each build
# a Microsoft-hosted Linux agent in Azure pipelines have Docker pre-installed on them
pool:
vmImage: 'Ubuntu-16.04'
# variables group
# Referencing from Azure DevOps > Pipelines > Library > "Variable Groups" tab
# these group variables can be accessed as $(variable_name)
variables:
- group: hwsc-dev-container-vars # name of variable group file that contains docker hub user/email/image-names
- group: hwsc-user-svc-env-vars
- name: GOBIN # Go binaries path
value: '$(GOPATH)/bin'
- name: GOPATH # Go workspace path
value: '$(system.defaultWorkingDirectory)/gopath'
- name: modulePath # Path to the module's code
value: '$(GOPATH)/$(build.repository.name)'
# task: DownloadSecureFile@1
# download a Secure File to a temporary location on build or release agent
# Secure Files is referenced from Azure DevOps > Pipelines > Library > "Secure Files" tab
# once downloaded, the Secure File is located in $(Agent.TempDirectory) directory of Azure Pipelines Agent
# selected secure files are deleted after the build or release is finished
steps:
- script: printenv
displayName: 'Print Environment Variables'
- script: |
go version
mkdir -p '$(GOBIN)'
mkdir -p '$(GOPATH)/pkg'
mkdir -p '$(modulePath)'
shopt -s extglob
mv !(gopath) '$(modulePath)'
echo '##vso[task.prependpath]$(GOBIN)'
echo '##vso[task.prependpath]$(GOROOT)/bin'
displayName: 'Set up the Go workspace'
- script: go get -v -t -d ./...
workingDirectory: '$(modulePath)'
displayName: 'Go Get Dependencies'
- task: DownloadSecureFile@1
inputs:
secureFile: hwsctestgmail_pw.txt # contains info for test gmail
- script: go build -v .
workingDirectory: '$(modulePath)'
displayName: 'Go Executable Build Test'
- script: |
PASSWORD=$(cat $(Agent.TempDirectory)/hwsctestgmail_pw.txt)
export hosts_postgres_host="localhost"
export hosts_postgres_db="test_user_svc"
export hosts_postgres_user="postgres"
export hosts_postgres_password="secret"
export hosts_postgres_sslmode="disable"
export hosts_postgres_port="5432"
export hosts_smtp_host=$(testGmailHost)
export hosts_smtp_port=$(testGmailPort)
export hosts_smtp_username=$(testGmailUser)
export hosts_smtp_password=$PASSWORD
export hosts_dummy_email=$(testDummyEmail)
export hosts_dummy_password=$(testDummyPassword)
go test -v -cover -race ./...
go get github.com/jstemmer/go-junit-report
go get github.com/axw/gocov/gocov
go get github.com/AlekSi/gocov-xml
go test -coverprofile=coverage.out -v -race -covermode atomic ./... 2>&1 | go-junit-report > report.xml
gocov convert coverage.out | gocov-xml > coverage.xml
mkdir -p coverage/official-tool
go tool cover -html=coverage.out -o coverage/official-tool/coverage.html
go get -u github.com/matm/gocov-html
gocov convert coverage.out > coverage.json
gocov-html < coverage.json > coverage/index.html
workingDirectory: '$(modulePath)'
displayName: 'Run Unit Tests'
- task: PublishTestResults@2
inputs:
testRunner: JUnit
testResultsFiles: $(System.DefaultWorkingDirectory)/**/report.xml
failTaskOnFailedTests: 'true'
failOnStandardError: 'true'
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(System.DefaultWorkingDirectory)/**/coverage.xml
reportDirectory: $(System.DefaultWorkingDirectory)/**/coverage
failIfCoverageEmpty: 'true'
failOnStandardError: 'true'
- task: DownloadSecureFile@1
inputs:
secureFile: hwscdevcontainer_pw.txt # contains password for hwsc docker hub
- script: |
cat $(Agent.TempDirectory)/hwscdevcontainer_pw.txt | docker login -u "$(hwscDevContainerUser)" --password-stdin
docker build --no-cache -f Dockerfile -t hwsc/hwsc-user-svc:int .
workingDirectory: '$(modulePath)'
displayName: 'Build Docker Image Internal Release'
- script: |
docker push hwsc/hwsc-user-svc:int
workingDirectory: '$(modulePath)'
displayName: 'Push Docker Image Internal Release'