1# This builds only track 1 SDKs. See eng\pipelines\templates\steps\build.yml for track 2.
2
3trigger:
4  paths:
5    exclude:
6    - sdk/
7    - tools/
8
9pr:
10  paths:
11    exclude:
12    - sdk/
13    - tools/
14
15jobs:
16  - job: Build_Test
17    strategy:
18      matrix:
19        Linux_Go116:
20          pool.name: azsdk-pool-mms-ubuntu-1804-general
21          go.version: '1.16.7'
22        Linux_Go117:
23          pool.name: azsdk-pool-mms-ubuntu-1804-general
24          go.version: '1.17'
25
26    pool:
27      name: $(pool.name)
28
29    variables:
30      GOPATH: '$(system.defaultWorkingDirectory)/work'
31      sdkPath: '$(GOPATH)/src/github.com/$(build.repository.name)'
32      GO111MODULE: 'off'
33      IGNORE_BREAKING_CHANGES: true
34      go.list.filter: '| grep -v vendor | grep -v azure-sdk-for-go/sdk | grep -v azure-sdk-for-go/tools'
35      go.test.filter: '-path ./vendor -prune -o -path ./sdk -prune -o -path ./tools -prune'
36
37    steps:
38    - task: GoTool@0
39      inputs:
40        version: '$(go.version)'
41      displayName: "Select Go Version"
42
43    - script: |
44        set -e
45        mkdir -p '$(GOPATH)/bin'
46        mkdir -p '$(sdkPath)'
47        shopt -s dotglob extglob
48        mv !(work) '$(sdkPath)'
49        echo '##vso[task.prependpath]$(GOROOT)/bin'
50        echo '##vso[task.prependpath]$(GOPATH)/bin'
51      displayName: 'Create Go Workspace'
52
53    - script: |
54        set -e
55        go version
56        curl -sSL https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
57        dep ensure -v
58        go get -u golang.org/x/lint/golint
59      workingDirectory: '$(sdkPath)'
60      displayName: 'Install Dependencies'
61
62    - script: go vet -v $(go list ./... $(go.list.filter))
63      workingDirectory: '$(sdkPath)'
64      displayName: 'Vet'
65
66    - script: go build -v $(go list ./... $(go.list.filter))
67      workingDirectory: '$(sdkPath)'
68      displayName: 'Build'
69
70    - script: go test $(dirname $(find . $(go.test.filter) -name '*_test.go' -print) | sort -u)
71      workingDirectory: '$(sdkPath)'
72      displayName: 'Run Tests'
73
74    - template: /eng/common/pipelines/templates/steps/verify-links.yml
75      parameters:
76        Directory: '.'
77        ScriptDirectory: '$(sdkPath)/eng/common/scripts'
78        WorkingDirectory: '$(sdkPath)'
79        Urls: $(Get-ChildItem -Path '$(sdkPath)/*.md' -Recurse | Where {$_.FullName -notlike "*/vendor/*" -and $_.FullName -notlike "*/sdk/*"})
80
81    - script: go run ./tools/apidiff/main.go packages ./services FETCH_HEAD~1 FETCH_HEAD --copyrepo --breakingchanges || $IGNORE_BREAKING_CHANGES
82      workingDirectory: '$(sdkPath)'
83      displayName: 'Display Breaking Changes'
84
85    - script: go run ./tools/pkgchk/main.go ./services --exceptions ./tools/pkgchk/exceptions.txt
86      workingDirectory: '$(sdkPath)'
87      displayName: 'Verify Package Directory'
88
89    - script: grep -L -r --include *.go --exclude-dir vendor -P "Copyright (\d{4}|\(c\)) Microsoft" ./ | tee >&2
90      workingDirectory: '$(sdkPath)'
91      displayName: 'Copyright Header Check'
92      failOnStderr: true
93      condition: succeededOrFailed()
94
95    - script: gofmt -s -l -d $(find . -path ./vendor -prune -o -name '*.go' -print) >&2
96      workingDirectory: '$(sdkPath)'
97      displayName: 'Format Check'
98      failOnStderr: true
99      condition: and(succeededOrFailed(), startsWith(variables['go.version'], '1.16'))
100
101    - script: |
102        golint ./storage/... >&2
103      workingDirectory: '$(sdkPath)'
104      displayName: 'Linter Check'
105      failOnStderr: true
106      condition: succeededOrFailed()
107