|
| 1 | +name: Run Tests |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + ref: |
| 7 | + description: ref on which to run the end-2-end tests (default is head_sha on the current branch) |
| 8 | + required: false |
| 9 | + default: '' |
| 10 | + testPatterns: |
| 11 | + description: Commaseparated list of patterns to match against test names (default is * for all tests) |
| 12 | + required: false |
| 13 | + default: '' |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: read |
| 17 | + actions: read |
| 18 | + pull-requests: write |
| 19 | + checks: write |
| 20 | + |
| 21 | +concurrency: |
| 22 | + group: 'runTests-${{ github.ref }}' |
| 23 | + cancel-in-progress: true |
| 24 | + |
| 25 | +defaults: |
| 26 | + run: |
| 27 | + shell: powershell |
| 28 | + |
| 29 | +jobs: |
| 30 | + AnalyzeTests: |
| 31 | + runs-on: [ windows-latest ] |
| 32 | + outputs: |
| 33 | + tests: ${{ steps.Analyze.outputs.tests }} |
| 34 | + linuxtests: ${{ steps.Analyze.outputs.linuxtests }} |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v3 |
| 37 | + with: |
| 38 | + ref: ${{ github.event.inputs.ref }} |
| 39 | + lfs: true |
| 40 | + |
| 41 | + - name: Analyze |
| 42 | + id: Analyze |
| 43 | + env: |
| 44 | + testPatterns: ${{ github.event.inputs.testPatterns }} |
| 45 | + run: | |
| 46 | + $errorActionPreference = "stop" |
| 47 | + $testPatterns = $ENV:TESTPATTERNS |
| 48 | + if (!$testPatterns) { $testPatterns = '*' } |
| 49 | + $testPatternArr = $testPatterns.Split(',') |
| 50 | + Write-Host "Running test matching patterns:" |
| 51 | + $testPatternArr | ForEach-Object { Write-Host "- $_" } |
| 52 | + $tests = ConvertTo-Json -compress -InputObject @(Get-ChildItem -Path (Join-Path $ENV:GITHUB_WORKSPACE 'Tests\*.Tests.ps1') | Where-Object { $name = $_.Basename; $testPatternArr | Where-Object { $name -like "$($_).Tests" } } | ForEach-Object { $_.BaseName }) |
| 53 | + Add-Content -Path $env:GITHUB_OUTPUT -Value "tests=$tests" |
| 54 | + Write-Host "tests=$tests" |
| 55 | + $linuxtests = ConvertTo-Json -compress -InputObject @(Get-ChildItem -Path (Join-Path $ENV:GITHUB_WORKSPACE 'LinuxTests\*.Tests.ps1') | Where-Object { $name = $_.Basename; $testPatternArr | Where-Object { $name -like "$($_).Tests" } } | ForEach-Object { $_.BaseName }) |
| 56 | + Add-Content -Path $env:GITHUB_OUTPUT -Value "linuxtests=$linuxtests" |
| 57 | + Write-Host "linuxtests=$linuxtests" |
| 58 | +
|
| 59 | + PS5: |
| 60 | + runs-on: [ windows-latest ] |
| 61 | + needs: [ AnalyzeTests ] |
| 62 | + if: needs.AnalyzeTests.outputs.tests != '[]' |
| 63 | + strategy: |
| 64 | + matrix: |
| 65 | + test: ${{fromJson(needs.AnalyzeTests.outputs.tests)}} |
| 66 | + fail-fast: false |
| 67 | + steps: |
| 68 | + - uses: actions/checkout@v3 |
| 69 | + with: |
| 70 | + ref: ${{ github.event.inputs.ref }} |
| 71 | + lfs: true |
| 72 | + |
| 73 | + - name: Run Tests |
| 74 | + run: | |
| 75 | + try { |
| 76 | + $errorActionPreference = "stop" |
| 77 | + Set-StrictMode -version 2.0 |
| 78 | + $pesterContainer = New-PesterContainer -Path (Join-Path $ENV:GITHUB_WORKSPACE 'Tests\${{ matrix.test }}.ps1') -Data @{ "licenseFile" = '${{ secrets.licensefile }}'; "buildLicenseFile" = '${{ secrets.buildLicenseFile }}' } |
| 79 | + $result = Invoke-Pester -Container $pesterContainer -passthru |
| 80 | + if ($result.FailedCount -gt 0) { |
| 81 | + Write-Host "::Error::$($result.FailedCount) tests are failing" |
| 82 | + $host.SetShouldExit(1) |
| 83 | + } |
| 84 | + } |
| 85 | + catch { |
| 86 | + Write-Host "::Error::Exception when running tests. The Error was $($_.Exception.Message)" |
| 87 | + $host.SetShouldExit(1) |
| 88 | + } |
| 89 | +
|
| 90 | + PS7: |
| 91 | + runs-on: [ windows-latest ] |
| 92 | + needs: [ AnalyzeTests ] |
| 93 | + if: needs.AnalyzeTests.outputs.tests != '[]' |
| 94 | + strategy: |
| 95 | + matrix: |
| 96 | + test: ${{fromJson(needs.AnalyzeTests.outputs.tests)}} |
| 97 | + fail-fast: false |
| 98 | + defaults: |
| 99 | + run: |
| 100 | + shell: pwsh |
| 101 | + steps: |
| 102 | + - name: Checkout |
| 103 | + uses: actions/checkout@v3 |
| 104 | + with: |
| 105 | + ref: ${{ github.event.inputs.ref }} |
| 106 | + lfs: true |
| 107 | + |
| 108 | + - name: Run Tests |
| 109 | + run: | |
| 110 | + try { |
| 111 | + $errorActionPreference = "stop" |
| 112 | + Set-StrictMode -version 2.0 |
| 113 | + $pesterContainer = New-PesterContainer -Path (Join-Path $ENV:GITHUB_WORKSPACE 'Tests\${{ matrix.test }}.ps1') -Data @{ "licenseFile" = '${{ secrets.licensefile }}'; "buildLicenseFile" = '${{ secrets.buildLicenseFile }}' } |
| 114 | + $result = Invoke-Pester -Container $pesterContainer -passthru |
| 115 | + if ($result.FailedCount -gt 0) { |
| 116 | + Write-Host "::Error::$($result.FailedCount) tests are failing" |
| 117 | + $host.SetShouldExit(1) |
| 118 | + } |
| 119 | + } |
| 120 | + catch { |
| 121 | + Write-Host "::Error::Exception when running tests. The Error was $($_.Exception.Message)" |
| 122 | + $host.SetShouldExit(1) |
| 123 | + } |
| 124 | +
|
| 125 | + Linux: |
| 126 | + runs-on: [ ubuntu-latest ] |
| 127 | + needs: [ AnalyzeTests ] |
| 128 | + if: needs.AnalyzeTests.outputs.linuxtests != '[]' |
| 129 | + strategy: |
| 130 | + matrix: |
| 131 | + test: ${{fromJson(needs.AnalyzeTests.outputs.linuxtests)}} |
| 132 | + fail-fast: false |
| 133 | + defaults: |
| 134 | + run: |
| 135 | + shell: pwsh |
| 136 | + steps: |
| 137 | + - name: Checkout |
| 138 | + uses: actions/checkout@v3 |
| 139 | + with: |
| 140 | + ref: ${{ github.event.inputs.ref }} |
| 141 | + lfs: true |
| 142 | + |
| 143 | + - name: Run Tests |
| 144 | + run: | |
| 145 | + try { |
| 146 | + $errorActionPreference = "stop" |
| 147 | + Set-StrictMode -version 2.0 |
| 148 | + $pesterContainer = New-PesterContainer -Path (Join-Path $ENV:GITHUB_WORKSPACE 'LinuxTests\${{ matrix.test }}.ps1') -Data @{ "licenseFile" = '${{ secrets.licensefile }}'; "buildLicenseFile" = '${{ secrets.buildLicenseFile }}' } |
| 149 | + $result = Invoke-Pester -Container $pesterContainer -passthru |
| 150 | + if ($result.FailedCount -gt 0) { |
| 151 | + Write-Host "::Error::$($result.FailedCount) tests are failing" |
| 152 | + $host.SetShouldExit(1) |
| 153 | + } |
| 154 | + } |
| 155 | + catch { |
| 156 | + Write-Host "::Error::Exception when running tests. The Error was $($_.Exception.Message)" |
| 157 | + $host.SetShouldExit(1) |
| 158 | + } |
0 commit comments