|
| 1 | +name: Pester Tests |
| 2 | + |
| 3 | +permissions: |
| 4 | + contents: read |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: [main, dev, master] |
| 9 | + pull_request: |
| 10 | + branches: [main, dev, master] |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +jobs: |
| 14 | + test: |
| 15 | + runs-on: ${{ matrix.os }} |
| 16 | + strategy: |
| 17 | + fail-fast: false |
| 18 | + matrix: |
| 19 | + os: [windows-latest, ubuntu-latest, macos-latest] |
| 20 | + psversion: [pwsh, powershell] |
| 21 | + exclude: |
| 22 | + # PowerShell 5.1 (powershell) is only available on Windows |
| 23 | + - os: ubuntu-latest |
| 24 | + psversion: powershell |
| 25 | + - os: macos-latest |
| 26 | + psversion: powershell |
| 27 | + |
| 28 | + name: Test on ${{ matrix.os }} with ${{ matrix.psversion == 'pwsh' && 'PowerShell 7.x' || 'PowerShell 5.1' }} |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Checkout code |
| 32 | + uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Install required modules (PowerShell 7.x) |
| 35 | + if: matrix.psversion == 'pwsh' |
| 36 | + shell: pwsh |
| 37 | + run: | |
| 38 | + Set-PSRepository -Name PSGallery -InstallationPolicy Trusted |
| 39 | + Install-Module -Name Pester -MinimumVersion 5.0.0 -Force -SkipPublisherCheck |
| 40 | + Install-Module -Name PScribo -MinimumVersion 0.11.1 -Force |
| 41 | +
|
| 42 | + - name: Install required modules (PowerShell 5.1) |
| 43 | + if: matrix.psversion == 'powershell' |
| 44 | + shell: powershell |
| 45 | + run: | |
| 46 | + Set-PSRepository -Name PSGallery -InstallationPolicy Trusted |
| 47 | + Install-Module -Name Pester -MinimumVersion 5.0.0 -Force -SkipPublisherCheck |
| 48 | + Install-Module -Name PScribo -MinimumVersion 0.11.1 -Force |
| 49 | +
|
| 50 | + - name: Run Pester tests (PowerShell 7.x) |
| 51 | + if: matrix.psversion == 'pwsh' |
| 52 | + shell: pwsh |
| 53 | + run: | |
| 54 | + .\Tests\Invoke-Tests.ps1 -CodeCoverage -OutputFormat NUnitXml |
| 55 | +
|
| 56 | + - name: Run Pester tests (PowerShell 5.1) |
| 57 | + if: matrix.psversion == 'powershell' |
| 58 | + shell: powershell |
| 59 | + run: | |
| 60 | + .\Tests\Invoke-Tests.ps1 -CodeCoverage -OutputFormat NUnitXml |
| 61 | +
|
| 62 | + - name: Upload test results |
| 63 | + if: always() |
| 64 | + uses: actions/upload-artifact@v4 |
| 65 | + with: |
| 66 | + name: test-results-${{ matrix.os }}-${{ matrix.psversion }} |
| 67 | + path: testResults.xml |
| 68 | + |
| 69 | + - name: Upload code coverage |
| 70 | + if: always() && matrix.os == 'windows-latest' && matrix.psversion == 'pwsh' |
| 71 | + uses: actions/upload-artifact@v4 |
| 72 | + with: |
| 73 | + name: code-coverage |
| 74 | + path: coverage.xml |
| 75 | + |
| 76 | + - name: Upload coverage reports to Codecov |
| 77 | + if: always() && matrix.os == 'windows-latest' && matrix.psversion == 'pwsh' |
| 78 | + uses: codecov/codecov-action@v5 |
| 79 | + with: |
| 80 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 81 | + slug: AsBuiltReport/AsBuiltReport.Core |
| 82 | + files: ./coverage.xml |
| 83 | + flags: unittests |
| 84 | + fail_ci_if_error: false |
0 commit comments