Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EngSys] Combine Build Build and Build Test pipelines #15085

Merged
merged 19 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ stages:
- template: ../steps/create-go-workspace.yml

- template: ../steps/set-scope.yml
parameters:
parameters:
ServiceDirectory: ${{ parameters.ServiceDirectory }}
GoWorkspace: $(GO_WORKSPACE_PATH)

- template: ../steps/build.yml
parameters:
- template: ../steps/build-test.yml
parameters:
ServiceDirectory: ${{ parameters.ServiceDirectory }}
GoWorkspace: $(GO_WORKSPACE_PATH)
Scope: $(SCOPE)
Expand All @@ -70,18 +70,18 @@ stages:
- template: ../steps/create-go-workspace.yml

- template: ../steps/set-scope.yml
parameters:
parameters:
ServiceDirectory: ${{ parameters.ServiceDirectory }}
GoWorkspace: $(GO_WORKSPACE_PATH)

- template: ../steps/analyze.yml
parameters:
parameters:
ServiceDirectory: ${{ parameters.ServiceDirectory }}
GoWorkspace: $(GO_WORKSPACE_PATH)
Scope: $(SCOPE)
LintVersion: $(GoLintCLIVersion)

# Below stage won't work until the release stage is added/necessary.
# Below stage won't work until the release stage is added/necessary.
# "Releasing" is just the package in the repository on github, but there may be some other metadata related
# tasks that become necessary later on.

Expand Down
12 changes: 7 additions & 5 deletions eng/pipelines/templates/jobs/archetype-sdk-client.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
parameters:
ServiceDirectory: ''
RunTests: false

stages:
- stage: Build
Expand Down Expand Up @@ -42,17 +43,18 @@ stages:
- template: ../steps/create-go-workspace.yml

- template: ../steps/set-scope.yml
parameters:
parameters:
ServiceDirectory: ${{ parameters.ServiceDirectory }}
GoWorkspace: $(GO_WORKSPACE_PATH)

- template: ../steps/build-test.yml
parameters:
parameters:
ServiceDirectory: ${{ parameters.ServiceDirectory }}
GoWorkspace: $(GO_WORKSPACE_PATH)
Scope: $(SCOPE)
Image: $(vm.image)
GoVersion: $(go.version)
RunTests: ${{ parameters.RunTests }}

- job: Analyze
displayName: Analyze
Expand All @@ -70,18 +72,18 @@ stages:
- template: ../steps/create-go-workspace.yml

- template: ../steps/set-scope.yml
parameters:
parameters:
ServiceDirectory: ${{ parameters.ServiceDirectory }}
GoWorkspace: $(GO_WORKSPACE_PATH)

- template: ../steps/analyze.yml
parameters:
parameters:
ServiceDirectory: ${{ parameters.ServiceDirectory }}
GoWorkspace: $(GO_WORKSPACE_PATH)
Scope: $(SCOPE)
LintVersion: $(GoLintCLIVersion)

# Below stage won't work until the release stage is added/necessary.
# Below stage won't work until the release stage is added/necessary.
# "Releasing" is just the package in the repository on github, but there may be some other metadata related
# tasks that become necessary later on.

Expand Down
6 changes: 3 additions & 3 deletions eng/pipelines/templates/steps/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ steps:
failOnStderr: true
workingDirectory: 'sdk/${{parameters.ServiceDirectory}}'

- script: |
echo check source file formatting in $(pwd)
gofmt -s -l -d $(find . -name '*.go' -print) >&2
- pwsh: |
Write-Host "##[command]Check source file formatting in $(pwd)"
gofmt -s -l -d .
displayName: 'Format Check'
condition: succeededOrFailed()
failOnStderr: true
Expand Down
122 changes: 56 additions & 66 deletions eng/pipelines/templates/steps/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,86 +4,76 @@ parameters:
Scope: 'sdk/...'
Image: ''
GoVersion: ''
RunTests: false

steps:

- pwsh: |
go get github.com/jstemmer/go-junit-report
go get github.com/axw/gocov/gocov
go get github.com/AlekSi/gocov-xml
go get github.com/matm/gocov-html
go get -u github.com/wadey/gocovmerge
displayName: "Install Coverage and Junit Dependencies"
workingDirectory: '${{parameters.GoWorkspace}}'

- pwsh: |
$modDirs = (./eng/scripts/get_module_dirs.ps1 -serviceDir $(SCOPE))
foreach ($md in $modDirs) {
pushd $md
Write-Host "##[command]Executing go build -v ./... in $md"
go build -v ./...
}
- pwsh: ./eng/scripts/build.ps1
displayName: 'Build'
workingDirectory: '${{parameters.GoWorkspace}}'
env:
GO111MODULE: 'on'

- pwsh: |
$modDirs = (./eng/scripts/get_module_dirs.ps1 -serviceDir $(SCOPE))
foreach ($md in $modDirs) {
pushd $md
Write-Host "##[command]Executing go vet ./... in $md"
go vet ./...
}
- pwsh: ./eng/scripts/build.ps1 -vet -skipBuild
displayName: 'Vet'
workingDirectory: '${{parameters.GoWorkspace}}'
env:
GO111MODULE: 'on'

- pwsh: |
$testDirs = (./eng/scripts/get_test_dirs.ps1 -serviceDir $(SCOPE))
foreach ($td in $testDirs) {
pushd $td
Write-Host "##[command]Executing go test -run "^Test" -race -v -coverprofile coverage.txt -covermode atomic $td | go-junit-report -set-exit-code > report.xml"
go test -run "^Test" -race -v -coverprofile coverage.txt -covermode atomic . | go-junit-report -set-exit-code > report.xml
# if no tests were actually run (e.g. examples) delete the coverage file so it's omitted from the coverage report
if (Select-String -path ./report.xml -pattern '<testsuites></testsuites>' -simplematch -quiet) {
Write-Host "##[command]Deleting empty coverage file"
rm coverage.txt
- ${{ if eq(parameters.RunTests, 'true') }}:
- pwsh: |
go get github.com/jstemmer/go-junit-report
go get github.com/axw/gocov/gocov
go get github.com/AlekSi/gocov-xml
go get github.com/matm/gocov-html
go get -u github.com/wadey/gocovmerge
displayName: "Install Coverage and Junit Dependencies"
workingDirectory: '${{parameters.GoWorkspace}}'

- pwsh: |
$testDirs = (./eng/scripts/get_test_dirs.ps1 -serviceDir $(SCOPE))
foreach ($td in $testDirs) {
pushd $td
Write-Host "##[command]Executing go test -run "^Test" -race -v -coverprofile coverage.txt -covermode atomic $td | go-junit-report -set-exit-code > report.xml"
go test -run "^Test" -race -v -coverprofile coverage.txt -covermode atomic . | go-junit-report -set-exit-code > report.xml
# if no tests were actually run (e.g. examples) delete the coverage file so it's omitted from the coverage report
if (Select-String -path ./report.xml -pattern '<testsuites></testsuites>' -simplematch -quiet) {
Write-Host "##[command]Deleting empty coverage file"
rm coverage.txt
}
}
}
displayName: 'Run Tests'
workingDirectory: '${{parameters.GoWorkspace}}'
env:
GO111MODULE: 'on'
displayName: 'Run Tests'
workingDirectory: '${{parameters.GoWorkspace}}'
env:
GO111MODULE: 'on'

- pwsh: |
$coverageFiles = [Collections.Generic.List[String]]@()
Get-Childitem -recurse -path $(SCOPE) -filter coverage.txt | foreach-object {
$covFile = $_.FullName
Write-Host "Adding $covFile to the list of code coverage files"
$coverageFiles.Add($covFile)
}
gocovmerge $coverageFiles > mergedCoverage.txt
gocov convert ./mergedCoverage.txt > ./coverage.json
# gocov converts rely on standard input
Get-Content ./coverage.json | gocov-xml > ./coverage.xml
Get-Content ./coverage.json | gocov-html > ./coverage.html
displayName: 'Generate Coverage XML'
workingDirectory: '${{parameters.GoWorkspace}}sdk'
- pwsh: |
seankane-msft marked this conversation as resolved.
Show resolved Hide resolved
$coverageFiles = [Collections.Generic.List[String]]@()
Get-Childitem -recurse -path $(SCOPE) -filter coverage.txt | foreach-object {
$covFile = $_.FullName
Write-Host "Adding $covFile to the list of code coverage files"
$coverageFiles.Add($covFile)
}
gocovmerge $coverageFiles > mergedCoverage.txt
gocov convert ./mergedCoverage.txt > ./coverage.json
# gocov converts rely on standard input
Get-Content ./coverage.json | gocov-xml > ./coverage.xml
Get-Content ./coverage.json | gocov-html > ./coverage.html
displayName: 'Generate Coverage XML'
workingDirectory: '${{parameters.GoWorkspace}}sdk'

- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testRunner: JUnit
testResultsFiles: '${{parameters.GoWorkspace}}sdk/**/report.xml'
testRunTitle: 'Go ${{ parameters.GoVersion }} on ${{ parameters.Image }}'
failTaskOnFailedTests: true
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testRunner: JUnit
testResultsFiles: '${{parameters.GoWorkspace}}sdk/**/report.xml'
testRunTitle: 'Go ${{ parameters.GoVersion }} on ${{ parameters.Image }}'
failTaskOnFailedTests: true

- task: PublishCodeCoverageResults@1
condition: succeededOrFailed()
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '${{parameters.GoWorkspace}}sdk/coverage.xml'
additionalCodeCoverageFiles: '${{parameters.GoWorkspace}}sdk/coverage.html'
failIfCoverageEmpty: true
- task: PublishCodeCoverageResults@1
condition: succeededOrFailed()
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '${{parameters.GoWorkspace}}sdk/coverage.xml'
additionalCodeCoverageFiles: '${{parameters.GoWorkspace}}sdk/coverage.html'
failIfCoverageEmpty: true
22 changes: 0 additions & 22 deletions eng/pipelines/templates/steps/build.yml

This file was deleted.

4 changes: 2 additions & 2 deletions eng/scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ foreach ($sdk in (./eng/scripts/get_module_dirs.ps1 -serviceDir 'sdk/...')) {
}

$keys = $sdks.Keys | Sort-Object;
if (![string]::IsNullOrWhiteSpace($filter)) {
if (![string]::IsNullOrWhiteSpace($filter)) {
Write-Host "Using filter: $filter"
$keys = $keys.Where( { $_ -match $filter })
$keys = $keys.Where( { $_ -match $filter })
}

$keys | ForEach-Object { $sdks[$_] } | ForEach-Object {
Expand Down
10 changes: 7 additions & 3 deletions eng/scripts/get_test_dirs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ $testDirs = [Collections.Generic.List[String]]@()
# find each directory under $serviceDir that contains Go test files
Get-Childitem -recurse -path $serviceDir -filter *_test.go | foreach-object {
$cdir = $_.Directory
if (!$testDirs.Contains($cdir)) {
Write-Host "Adding $cdir to list of test directories"
$testDirs.Add($cdir)
$tests = Select-String -Path $_ 'Test' -AllMatches

if ($tests.Count -gt 0) {
if (!$testDirs.Contains($cdir)) {
Write-Host "Adding $cdir to list of test directories"
$testDirs.Add($cdir)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/agfood/armagfood/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ pr:
- sdk/agfood/armagfood/

stages:
- template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml
- template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: 'agfood/armagfood'
2 changes: 1 addition & 1 deletion sdk/agrifood/armagrifood/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ pr:
- sdk/agrifood/armagrifood

stages:
- template: /eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml
- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: 'agrifood/armagrifood'
2 changes: 1 addition & 1 deletion sdk/authorization/armauthorization/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ pr:
- sdk/authorization/armauthorization

stages:
- template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml
- template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: 'authorization/armauthorization'
5 changes: 3 additions & 2 deletions sdk/azcore/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ pr:
paths:
include:
- sdk/azcore/


stages:
- template: ../../eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: 'azcore'
RunTests: true
1 change: 1 addition & 0 deletions sdk/azidentity/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ stages:
- template: ../../eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: 'azidentity'
RunTests: true
2 changes: 1 addition & 1 deletion sdk/compute/armcompute/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ pr:
- sdk/compute/armcompute/

stages:
- template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml
- template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: 'compute/armcompute'
2 changes: 1 addition & 1 deletion sdk/containerregistry/armcontainerregistry/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ pr:
- sdk/containerregistry/armcontainerregistry/

stages:
- template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml
- template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: 'containerregistry/armcontainerregistry'
2 changes: 1 addition & 1 deletion sdk/containerservice/armcontainerservice/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ pr:
- sdk/containerservice/armcontainerservice

stages:
- template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml
- template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: 'containerservice/armcontainerservice'
2 changes: 1 addition & 1 deletion sdk/keyvault/armkeyvault/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ pr:
- sdk/keyvault/armkeyvault

stages:
- template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml
- template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: 'keyvault/armkeyvault'
2 changes: 1 addition & 1 deletion sdk/monitor/armmonitor/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ pr:
- sdk/monitor/armmonitor

stages:
- template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml
- template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: 'monitor/armmonitor'
2 changes: 1 addition & 1 deletion sdk/network/armnetwork/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ pr:
- sdk/network/armnetwork/

stages:
- template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml
- template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: 'network/armnetwork'
2 changes: 1 addition & 1 deletion sdk/privatedns/armprivatedns/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ pr:
- sdk/privatedns/armprivatedns

stages:
- template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml
- template: ../../../eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: 'privatedns/armprivatedns'
Loading