Skip to content

Update DevOps.ServiceConnections.ps1 with fix for issue #106 #181

Update DevOps.ServiceConnections.ps1 with fix for issue #106

Update DevOps.ServiceConnections.ps1 with fix for issue #106 #181

Workflow file for this run

# GitHub workflow for running pester unit tests on pull requests
on:
pull_request:
paths:
- 'src/PSRule.Rules.AzureDevOps/Functions/**'
- 'src/PSRule.Rules.AzureDevOps/Classes/**'
- 'src/PSRule.Rules.AzureDevOps/rules/**'
- 'src/PSRule.Rules.AzureDevOps/PSRule.Rules.AzureDevOps.psm1'
- 'tests/**'
- '.github/workflows/module-ci.yml'
branches:
- main
push:
paths:
- 'src/PSRule.Rules.AzureDevOps/Functions/**'
- 'src/PSRule.Rules.AzureDevOps/PSRule.Rules.AzureDevOps.psm1'
- 'tests/**'
branches:
- main
name: PS Module CI
permissions:
checks: write
pull-requests: write
jobs:
run-pester:
runs-on: self-hosted
steps:
- uses: actions/checkout@v3
- name: Install PSRule and Pester
run: |
Install-Module -Name PSRule -Force -SkipPublisherCheck
Install-Module -Name Pester -Force -SkipPublisherCheck
shell: pwsh
# Temporarily disabled until PSScriptAnalyzer is updated to support PowerShell 7
# - name: Run PSScriptAnalyzer
# run: |
# Invoke-ScriptAnalyzer -Path .\src -Recurse -Verbose
# shell: pwsh
- name: Run Pester Tests
run: |
# Set Pester configuration for detailed output with code coverage and Nunit test results
Import-Module Pester -Force
# Create ADO export directory
New-Item -Path $env:ADO_EXPORT_DIR -ItemType Directory -Force
# Set Pester configuration for detailed output with code coverage and Nunit test results
$config = New-PesterConfiguration
$config.CodeCoverage.Enabled = $true
$config.CodeCoverage.OutputPath = "$($env:GITHUB_WORKSPACE)\coverage.xml"
$config.CodeCoverage.OutputFormat = 'JaCoCo'
$config.CodeCoverage.Path = "$($env:GITHUB_WORKSPACE)\src\PSRule.Rules.AzureDevOps\Functions","$($env:GITHUB_WORKSPACE)\src\PSRule.Rules.AzureDevOps\Classes"
$config.Output.Verbosity = 'Detailed'
$config.TestResult.Enabled = $true
$config.TestResult.OutputFormat = 'NUnitXml'
$config.TestResult.OutputPath = "$($env:GITHUB_WORKSPACE)\testresults.xml"
$config.Output.CIFormat = 'GitHubActions'
# Run Pester tests
Invoke-Pester -Configuration $config
shell: pwsh
env:
ADO_EXPORT_DIR: "${{ github.workspace }}/tmp"
ADO_PAT: ${{ secrets.ADO_PAT }}
ADO_ORGANIZATION: ${{ secrets.ADO_ORGANIZATION }}
ADO_PROJECT: ${{ secrets.ADO_PROJECT }}
ADO_PAT_FINEGRAINED: ${{ secrets.ADO_PAT_FINEGRAINED }}
ADO_PAT_READONLY: ${{ secrets.ADO_PAT_READONLY }}
ADO_CLIENT_ID: ${{ secrets.ADO_CLIENT_ID }}
ADO_CLIENT_SECRET: ${{ secrets.ADO_CLIENT_SECRET }}
ADO_TENANT_ID: ${{ secrets.ADO_TENANT_ID }}
ADO_MSI_CLIENT_ID: ${{ secrets.ADO_MSI_CLIENT_ID }}
- name: Upload Test Results
uses: EnricoMi/publish-unit-test-result-action/composite@v2
with:
files: |
**/testresults.xml
- name: Upload Code Coverage
uses: codecov/codecov-action@v1
with:
file: coverage.xml
flags: unittests
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
sonarcloud:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}