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

Sync eng/common directory with azure-sdk-tools for PR 5040 #19774

Merged
merged 1 commit into from
Jan 9, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
parameters:
- name: TargetDirectory
type: string
- name: CustomTestSteps
type: object
default: []
- name: EnvVars
type: object
default: {}
- name: TargetTags
type: string
default: ''

variables:
- template: /eng/pipelines/templates/variables/globals.yml

stages:
- stage: 'eng_script_tests'
jobs:
- job: 'Test'
strategy:
matrix:
Windows:
Pool: 'azsdk-pool-mms-win-2022-general'
Image: 'MMS2022'
Linux:
Pool: azsdk-pool-mms-ubuntu-2204-general
Image: MMSUbuntu22.04
Mac:
Pool: 'Azure Pipelines'
Image: 'macos-11'

pool:
name: $(Pool)
vmImage: $(Image)

steps:
- template: /eng/common/pipelines/templates/steps/run-pester-tests.yml
parameters:
TargetDirectory: ${{ parameters.TargetDirectory }}
CustomTestSteps: ${{ parameters.CustomTestSteps }}
EnvVars: ${{ parameters.EnvVars }}
TargetTags: ${{ parameters.TargetTags }}
55 changes: 55 additions & 0 deletions eng/common/pipelines/templates/steps/run-pester-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
parameters:
- name: TargetDirectory
type: string
- name: CustomTestSteps
type: object
default: []
- name: EnvVars
type: object
default: {}
- name: TargetTags
type: string
default: ''

steps:
- pwsh: |
Install-Module -Name Pester -Force
displayName: Install Pester

# default test steps
- ${{ if eq(length(parameters.CustomTestSteps), 0) }}:
- pwsh: |
$tags = "${{ parameters.TargetTags }}" -Split "," | ForEach-Object { return $_.Trim() }

$config = New-PesterConfiguration
$config.CodeCoverage.Enabled = $true
$config.TestResult.Enabled = $true
$config.Run.PassThru = $true

if ($tags) {
$config.Filter.Tag = $tags
}

Invoke-Pester -Configuration $config
displayName: Run Tests
env: ${{ parameters.EnvVars }}
workingDirectory: $(Build.SourcesDirectory)/${{ parameters.TargetDirectory }}

- ${{ if not(eq(length(parameters.CustomTestSteps), 0)) }}:
- ${{ parameters.CustomTestSteps }}

- task: PublishTestResults@2
displayName: 'Publish Test Results'
condition: succeededOrFailed()
inputs:
testResultsFormat: 'NUnit'
testResultsFiles: $(Build.SourcesDirectory)/${{ parameters.TargetDirectory }}/testResults.xml
testRunTitle: '$(System.StageName)_$(Agent.JobName)_Tests'

- task: PublishCodeCoverageResults@1
displayName: 'Publish Code Coverage to Azure DevOps'
condition: succeededOrFailed()
inputs:
codeCoverageTool: 'JaCoCo'
summaryFileLocation: '$(Build.SourcesDirectory)/${{ parameters.TargetDirectory }}/coverage.xml'
pathToSources: '$(Build.SourcesDirectory)/${{ parameters.TargetDirectory }}'