Skip to content

Commit 0bc7859

Browse files
Freddy Kristiansenfreddydk
andauthored
Run tests (#3238)
Add a new workflow to be able to run selected tests on a given REF, like: ![image](https://github.com/microsoft/navcontainerhelper/assets/10775043/f89a0ff8-fd5d-40fd-b74f-0eedbcc3dc6c) --------- Co-authored-by: freddydk <freddydk@users.noreply.github.com>
1 parent 8f56e2c commit 0bc7859

39 files changed

Lines changed: 208 additions & 83 deletions

.github/workflows/CI.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ defaults:
2424

2525
jobs:
2626
AnalyzeTests:
27+
if: github.repository == 'Microsoft/NavContainerHelper'
2728
runs-on: [ windows-latest ]
2829
outputs:
2930
tests: ${{ steps.Analyze.outputs.tests }}
@@ -37,6 +38,7 @@ jobs:
3738
- name: Analyze
3839
id: Analyze
3940
run: |
41+
$errorActionPreference = "stop"
4042
$tests = @(Get-ChildItem -Path (Join-Path $ENV:GITHUB_WORKSPACE 'Tests\*.Tests.ps1') | ForEach-Object { $_.BaseName }) | ConvertTo-Json -compress
4143
Add-Content -Path $env:GITHUB_OUTPUT -Value "tests=$tests"
4244
Write-Host "tests=$tests"
@@ -62,7 +64,7 @@ jobs:
6264
try {
6365
$errorActionPreference = "stop"
6466
Set-StrictMode -version 2.0
65-
$pesterContainer = New-PesterContainer -Path (Join-Path $ENV:GITHUB_WORKSPACE 'Tests\${{ matrix.test }}.ps1') -Data @{ "licenseFile" = '${{ secrets.licensefile }}'; "buildLicenseFile" = '${{ secrets.buildLicenseFile }}'; "insiderSasToken" = '${{ secrets.insiderSasToken }}' }
67+
$pesterContainer = New-PesterContainer -Path (Join-Path $ENV:GITHUB_WORKSPACE 'Tests\${{ matrix.test }}.ps1') -Data @{ "licenseFile" = '${{ secrets.licensefile }}'; "buildLicenseFile" = '${{ secrets.buildLicenseFile }}' }
6668
$result = Invoke-Pester -Container $pesterContainer -passthru
6769
if ($result.FailedCount -gt 0) {
6870
Write-Host "::Error::$($result.FailedCount) tests are failing"
@@ -95,7 +97,7 @@ jobs:
9597
try {
9698
$errorActionPreference = "stop"
9799
Set-StrictMode -version 2.0
98-
$pesterContainer = New-PesterContainer -Path (Join-Path $ENV:GITHUB_WORKSPACE 'Tests\${{ matrix.test }}.ps1') -Data @{ "licenseFile" = '${{ secrets.licensefile }}'; "buildLicenseFile" = '${{ secrets.buildLicenseFile }}'; "insiderSasToken" = '${{ secrets.insiderSasToken }}' }
100+
$pesterContainer = New-PesterContainer -Path (Join-Path $ENV:GITHUB_WORKSPACE 'Tests\${{ matrix.test }}.ps1') -Data @{ "licenseFile" = '${{ secrets.licensefile }}'; "buildLicenseFile" = '${{ secrets.buildLicenseFile }}' }
99101
$result = Invoke-Pester -Container $pesterContainer -passthru
100102
if ($result.FailedCount -gt 0) {
101103
Write-Host "::Error::$($result.FailedCount) tests are failing"
@@ -128,7 +130,7 @@ jobs:
128130
try {
129131
$errorActionPreference = "stop"
130132
Set-StrictMode -version 2.0
131-
$pesterContainer = New-PesterContainer -Path (Join-Path $ENV:GITHUB_WORKSPACE 'LinuxTests\${{ matrix.test }}.ps1') -Data @{ "licenseFile" = '${{ secrets.licensefile }}'; "buildLicenseFile" = '${{ secrets.buildLicenseFile }}'; "insiderSasToken" = '${{ secrets.insiderSasToken }}' }
133+
$pesterContainer = New-PesterContainer -Path (Join-Path $ENV:GITHUB_WORKSPACE 'LinuxTests\${{ matrix.test }}.ps1') -Data @{ "licenseFile" = '${{ secrets.licensefile }}'; "buildLicenseFile" = '${{ secrets.buildLicenseFile }}' }
132134
$result = Invoke-Pester -Container $pesterContainer -passthru
133135
if ($result.FailedCount -gt 0) {
134136
Write-Host "::Error::$($result.FailedCount) tests are failing"

.github/workflows/Release.yaml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ defaults:
1414

1515
jobs:
1616
Deploy:
17+
if: github.repository == 'Microsoft/NavContainerHelper'
1718
runs-on: [ windows-latest ]
1819
steps:
1920
- name: Checkout
2021
uses: actions/checkout@v3
2122

2223
- name: Deploy
2324
run: |
25+
$errorActionPreference = "stop"
2426
try {
2527
$path = Join-Path ([System.IO.Path]::GetTempPath()) "BcContainerHelper"
2628
New-Item -path $path -itemType Directory | Out-Null
@@ -56,7 +58,7 @@ jobs:
5658
5759
Write-Host "Release Notes:"
5860
Write-Host $VersionReleaseNotes
59-
61+
6062
Write-Host "Update Module Manifest"
6163
Update-ModuleManifest -Path (Join-Path $path "BcContainerHelper.psd1") `
6264
-RootModule "BcContainerHelper.psm1" `
@@ -67,28 +69,27 @@ jobs:
6769
-CompanyName "Microsoft" `
6870
-ReleaseNotes $versionReleaseNotes
6971
70-
7172
$certFileName = Join-Path ([System.IO.Path]::GetTempPath()) "$([GUID]::NewGuid().ToString()).pfx"
7273
Download-File -sourceUrl '${{ secrets.CodeSignCertificateUrl }}' -destinationFile $certFileName
73-
74+
7475
Remove-Module BcContainerHelper
75-
76+
7677
Write-Host $path
77-
78+
7879
Write-Host "Signing scripts"
7980
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($certFileName, '${{ secrets.CodeSignCertificatePassword }}')
8081
$filesToSign = @((Get-ChildItem $path -Filter "*.ps1" -Recurse -Depth 99).FullName)+
8182
@((Get-ChildItem $path -Filter "*.psm1" -Recurse -Depth 99).FullName)
8283
Set-AuthenticodeSignature -Certificate $cert -HashAlgorithm SHA256 -TimestampServer "http://timestamp.digicert.com" -FilePath $filesToSign
83-
84+
8485
Write-Host "Upload to storage (preview)"
8586
$storageContext = New-AzureStorageContext -ConnectionString '${{ secrets.BchStorageConnectionString }}'
8687
New-AzureStorageContainer -Name 'public' -Context $storageContext -Permission 'Container' -ErrorAction Ignore | Out-Null
87-
88+
8889
Compress-Archive -path $path -DestinationPath "$($path).zip"
8990
Set-AzureStorageBlobContent -File "$($path).zip" -Context $storageContext -Container 'public' -Blob "$version.zip" -Force | Out-Null
9091
Set-AzureStorageBlobContent -File "$($path).zip" -Context $storageContext -Container 'public' -Blob "latest.zip" -Force | Out-Null
91-
92+
9293
Write-Host "Publishing Module"
9394
Publish-Module -Path $path -NuGetApiKey '${{ secrets.NugetKey }}' -SkipAutomaticTags
9495
}

.github/workflows/RunTests.yaml

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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+
}

LinuxTests/Auth.Tests.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Param(
22
[string] $licenseFile,
3-
[string] $buildlicenseFile,
4-
[string] $insiderSasToken
3+
[string] $buildlicenseFile
54
)
65

76
BeforeAll {

LinuxTests/Saas.Tests.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Param(
22
[string] $licenseFile,
3-
[string] $buildlicenseFile,
4-
[string] $insiderSasToken
3+
[string] $buildlicenseFile
54
)
65

76
BeforeAll {

Tests/Api.Tests.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Param(
22
[string] $licenseFile,
3-
[string] $buildlicenseFile,
4-
[string] $insiderSasToken
3+
[string] $buildlicenseFile
54
)
65

76
BeforeAll {

Tests/AppHandling (NAV).Tests.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Param(
22
[string] $licenseFile,
3-
[string] $buildlicenseFile,
4-
[string] $insiderSasToken
3+
[string] $buildlicenseFile
54
)
65

76
BeforeAll {

Tests/AppHandling.Tests.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Param(
22
[string] $licenseFile,
3-
[string] $buildlicenseFile,
4-
[string] $insiderSasToken
3+
[string] $buildlicenseFile
54
)
65

76
BeforeAll {

Tests/AzureAD.Tests.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Param(
22
[string] $licenseFile,
3-
[string] $buildlicenseFile,
4-
[string] $insiderSasToken
3+
[string] $buildlicenseFile
54
)
65

76
BeforeAll {

Tests/AzureVM.Tests.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Param(
22
[string] $licenseFile,
3-
[string] $buildlicenseFile,
4-
[string] $insiderSasToken
3+
[string] $buildlicenseFile
54
)
65

76
BeforeAll {

0 commit comments

Comments
 (0)