| 1 |
variables: |
| 2 |
GO111MODULE: 'auto' |
| 3 |
GOPATH: '$(system.defaultWorkingDirectory)/work' |
| 4 |
sdkPath: '$(GOPATH)/src/github.com/$(build.repository.name)' |
| 5 |
|
| 6 |
jobs: |
| 7 |
- job: 'goautorest' |
| 8 |
displayName: 'Run go-autorest CI Checks' |
| 9 |
|
| 10 |
strategy: |
| 11 |
matrix: |
| 12 |
Linux_Go115: |
| 13 |
vm.image: 'ubuntu-18.04' |
| 14 |
go.version: '1.15' |
| 15 |
Linux_Go116: |
| 16 |
vm.image: 'ubuntu-18.04' |
| 17 |
go.version: '1.16' |
| 18 |
Linux_Go117: |
| 19 |
vm.image: 'ubuntu-18.04' |
| 20 |
go.version: '1.17' |
| 21 |
current_go: 'true' |
| 22 |
|
| 23 |
pool: |
| 24 |
vmImage: '$(vm.image)' |
| 25 |
|
| 26 |
steps: |
| 27 |
- task: GoTool@0 |
| 28 |
inputs: |
| 29 |
version: '$(go.version)' |
| 30 |
displayName: "Select Go Version" |
| 31 |
|
| 32 |
- script: | |
| 33 |
set -e |
| 34 |
mkdir -p '$(GOPATH)/bin' |
| 35 |
mkdir -p '$(sdkPath)' |
| 36 |
shopt -s extglob |
| 37 |
mv !(work) '$(sdkPath)' |
| 38 |
echo '##vso[task.prependpath]$(GOPATH)/bin' |
| 39 |
displayName: 'Create Go Workspace' |
| 40 |
|
| 41 |
- script: | |
| 42 |
set -e |
| 43 |
export GO111MODULE=on |
| 44 |
go get golang.org/x/lint/golint@latest |
| 45 |
go get github.com/jstemmer/go-junit-report@latest |
| 46 |
go get github.com/axw/gocov/gocov@latest |
| 47 |
go get github.com/AlekSi/gocov-xml@latest |
| 48 |
go get github.com/matm/gocov-html@latest |
| 49 |
workingDirectory: '$(sdkPath)' |
| 50 |
displayName: 'Install Dependencies' |
| 51 |
|
| 52 |
- script: | |
| 53 |
modules=$(find . -name go.mod) |
| 54 |
for module in $modules; do |
| 55 |
pushd "$(dirname $module)" && go vet ./... && popd; |
| 56 |
done |
| 57 |
workingDirectory: '$(sdkPath)' |
| 58 |
displayName: 'Vet' |
| 59 |
|
| 60 |
- script: | |
| 61 |
modules=$(find . -name go.mod) |
| 62 |
for module in $modules; do |
| 63 |
pushd "$(dirname $module)" && go build -v ./... && popd; |
| 64 |
done |
| 65 |
workingDirectory: '$(sdkPath)' |
| 66 |
displayName: 'Build' |
| 67 |
|
| 68 |
- script: | |
| 69 |
set -e |
| 70 |
modules=$(find . -name go.mod) |
| 71 |
for module in $modules; do |
| 72 |
pushd "$(dirname $module)"; |
| 73 |
go test -race -v -coverprofile=coverage.txt -covermode atomic ./... 2>&1 | go-junit-report > report.xml; |
| 74 |
gocov convert coverage.txt > coverage.json; |
| 75 |
gocov-xml < coverage.json > coverage.xml; |
| 76 |
gocov-html < coverage.json > coverage.html; |
| 77 |
popd; |
| 78 |
done |
| 79 |
workingDirectory: '$(sdkPath)' |
| 80 |
displayName: 'Run Tests' |
| 81 |
|
| 82 |
- script: grep -L -r --include *.go --exclude-dir vendor -P "Copyright (\d{4}|\(c\)) Microsoft" ./ | tee >&2 |
| 83 |
workingDirectory: '$(sdkPath)' |
| 84 |
displayName: 'Copyright Header Check' |
| 85 |
failOnStderr: true |
| 86 |
condition: succeededOrFailed() |
| 87 |
|
| 88 |
- script: | |
| 89 |
gofmt -s -l -w ./autorest/. >&2 |
| 90 |
gofmt -s -l -w ./logger/. >&2 |
| 91 |
gofmt -s -l -w ./tracing/. >&2 |
| 92 |
workingDirectory: '$(sdkPath)' |
| 93 |
displayName: 'Format Check' |
| 94 |
failOnStderr: true |
| 95 |
condition: and(succeededOrFailed(), eq(variables['current_go'], 'true')) |
| 96 |
|
| 97 |
- script: | |
| 98 |
modules=$(find . -name go.mod) |
| 99 |
for module in $modules; do |
| 100 |
pushd "$(dirname $module)" && golint ./... >&2 && popd; |
| 101 |
done |
| 102 |
workingDirectory: '$(sdkPath)' |
| 103 |
displayName: 'Linter Check' |
| 104 |
failOnStderr: true |
| 105 |
condition: succeededOrFailed() |
| 106 |
|
| 107 |
- task: PublishTestResults@2 |
| 108 |
inputs: |
| 109 |
testRunner: JUnit |
| 110 |
testResultsFiles: $(sdkPath)/**/report.xml |
| 111 |
failTaskOnFailedTests: true |
| 112 |
|
| 113 |
- task: PublishCodeCoverageResults@1 |
| 114 |
inputs: |
| 115 |
codeCoverageTool: Cobertura |
| 116 |
summaryFileLocation: $(sdkPath)/autorest/**/coverage.xml |
| 117 |
additionalCodeCoverageFiles: $(sdkPath)/autorest/**/coverage.html |