Repository navigation
ci: run every suite through one shuffled runner and rehearse releases #81
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5249951
ci: run every suite through one shuffled runner and rehearse releases
fadwen 6f9d4f2
Merge branch 'test/agent-log-event-order' into ci/standards-gates
fadwen d65d978
fix(test): fail a run in which no test passed or failed
fadwen 6f2d0ea
ci: drop the security step that repeated the default rules
fadwen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,20 @@ | ||
| # Quality gates for IntuneScriptLab. | ||
| # | ||
| # Four jobs, because the module makes claims that can only fail on different hosts: | ||
| # Five jobs, because the module makes claims that can only fail on different hosts: | ||
| # | ||
| # tests Windows, PowerShell 7. PSScriptAnalyzer at Error and Warning over the module, the | ||
| # kit and the tests, the 115-character line limit, then the whole Pester suite (the | ||
| # module's unit and integration suites and the validation kit's unit suite) shuffled, | ||
| # with an 80% coverage gate over Public/ and Private/. Nothing here reaches a tenant: | ||
| # every Graph call in the suites goes through the mocked Invoke-IslGraphRequest seam, | ||
| # and the suites that need an elevated session, a lab account or a Graph connection | ||
| # skip themselves. | ||
| # module's unit and integration suites and the validation kit's unit suite) with an | ||
| # 80% coverage gate over Public/ and Private/. Nothing here | ||
| # reaches a tenant: every Graph call in the suites goes through the mocked | ||
| # Invoke-IslGraphRequest seam, and the suites that need an elevated session, a lab | ||
| # account or a Graph connection skip themselves. | ||
| # | ||
| # Every Pester run goes through Tests/Invoke-Tests.ps1, the script a developer runs as well. It | ||
| # shuffles the order, so a test that only passes because of what ran before it fails here | ||
| # rather than on somebody's machine, and it fails when Pester's result is not Passed, which | ||
| # covers a failed BeforeAll or AfterAll and a file that failed discovery, or when no tests ran. | ||
| # The seed is in the failure message and in the job summary; -ShuffleSeed repeats that order. | ||
| # | ||
| # desktop Windows PowerShell 5.1. The scripts the module analyzes run under 5.1 on the | ||
| # device, and so does the module: the manifest declares CompatiblePSEditions Desktop | ||
|
|
@@ -32,6 +38,11 @@ | |
| # reference matches the rules, and Get-Help serves every command's full help on a | ||
| # case-sensitive filesystem - the only place the -Help.xml capital H can fail. | ||
| # | ||
| # rehearsal Windows. The release as far as the upload: Build/Publish-Module.ps1 -WhatIf builds | ||
| # the help, measures the manifest against the Gallery's limits, stages the allowlist | ||
| # and imports the staged copy in a new process. A release that would fail at the tag | ||
| # fails at the pull request instead. | ||
| # | ||
| # There is no Linux test job on purpose: the harness launches Windows PowerShell hosts, reads | ||
| # the registry and registers scheduled tasks, and the rules are about what happens on a Windows | ||
| # device. The module imports on Linux, which the help job proves. | ||
|
|
@@ -45,6 +56,11 @@ on: | |
| branches: [main] | ||
| workflow_dispatch: | ||
|
|
||
| # Nightly, so that a change outside the repository shows up within a day: a new runner image, | ||
| # a Windows update that adds an in-box module, a Gallery that stops serving a pinned tool. | ||
| schedule: | ||
| - cron: '30 4 * * *' | ||
|
|
||
| # Callable so release.yml can run these exact gates before publishing. A tag can be pushed | ||
| # at any commit, including one that never passed a pull request, so the release re-runs the | ||
| # gates rather than trusting that they ran at some point. | ||
|
|
@@ -54,7 +70,7 @@ permissions: | |
| contents: read | ||
|
|
||
| env: | ||
| # Style limit from .github/instructions/style-enforcement.instructions.md | ||
| # Style limit, STY-03 in .github/instructions/powershell-style.instructions.md | ||
| MAX_LINE_LENGTH: '115' | ||
|
|
||
| jobs: | ||
|
|
@@ -69,15 +85,21 @@ jobs: | |
| - name: Install build modules | ||
| shell: pwsh | ||
| run: | | ||
| # Runners ship Pester 5.x. Pester 6 must be installed explicitly, and the version | ||
| # range keeps a future Pester 7 from silently changing the assertion surface. The | ||
| # floor is 6.2 to match the #Requires line every suite carries. | ||
| Install-PSResource -Name Pester -Version '[6.2.0,7.0.0)' -Scope CurrentUser -TrustRepository | ||
| Install-PSResource -Name PSScriptAnalyzer -Scope CurrentUser -TrustRepository | ||
| $ErrorActionPreference = 'Stop' | ||
| # Runners ship Pester 5.x. Both tools are installed at one fixed version: a newer | ||
| # release can change what an assertion or a rule means, and with it what a passing | ||
| # build means. 6.2.0 is the version the #Requires line of every suite names. | ||
| Install-PSResource -Name Pester -Version 6.2.0 -Scope CurrentUser -TrustRepository | ||
| Install-PSResource -Name PSScriptAnalyzer -Version 1.25.0 -Scope CurrentUser -TrustRepository | ||
| $PSVersionTable | ConvertTo-Json -Depth 3 | ||
|
|
||
| # The mirrored standards folder holds examples that are not this module's code; the | ||
| # module, the kit, the build scripts and the tests are what is gated. | ||
| # The module, the kit, the build scripts and the tests are what is gated. The default | ||
| # rules at Error and Warning include the five of PSScriptAnalyzer's ScriptSecurity preset | ||
| # (plain-text passwords, user name and password parameters, ConvertTo-SecureString | ||
| # -AsPlainText, hard-coded computer names and PSCredential parameters), so this step is | ||
| # also the static analysis of a security gate. There is no credential scan and no | ||
| # dependency scan in this workflow: the module has no dependency, secret scanning is a | ||
| # repository setting, and whether a scanner belongs here is an open decision (#74). | ||
| - name: PSScriptAnalyzer and line length | ||
| shell: pwsh | ||
| run: | | ||
|
|
@@ -103,58 +125,20 @@ jobs: | |
| } | ||
| Write-Host "PSScriptAnalyzer clean, no line over $env:MAX_LINE_LENGTH characters, in $($files.Count) files." | ||
|
|
||
| # Every suite, shuffled, with the 80% coverage gate. The reports are written before the | ||
| # checks run, so a failed run still leaves both files to upload. | ||
| - name: Pester with coverage | ||
| shell: pwsh | ||
| run: | | ||
| $ErrorActionPreference = 'Stop' | ||
| Import-Module Pester -MinimumVersion 6.2.0 | ||
| $cfg = New-PesterConfiguration | ||
| $cfg.Run.Path = './Tests', './Validation/Tests' | ||
| $cfg.Run.PassThru = $true | ||
| $cfg.Output.Verbosity = 'Detailed' | ||
| $cfg.Should.DisableV5 = $true | ||
| # Shuffled, so a test that only passes because of what ran before it fails here rather | ||
| # than on somebody's machine. The seed is printed so a failing order can be replayed | ||
| # locally with $cfg.Run.ShuffleSeed. | ||
| $seed = Get-Random -Minimum 1 -Maximum 2147483647 | ||
| $cfg.Run.Shuffle = $true | ||
| $cfg.Run.ShuffleSeed = $seed | ||
| Write-Host "Pester shuffle seed: $seed" | ||
|
|
||
| $cfg.CodeCoverage.Enabled = $true | ||
| $cfg.CodeCoverage.Path = './Public/*.ps1', './Private/*.ps1', './Private/Rules/*.ps1' | ||
| # CoveragePercentTarget only reports; the gate below is what enforces it. | ||
| $cfg.CodeCoverage.CoveragePercentTarget = 80 | ||
| # Written before the gates below run, so a failed run still leaves both files to upload | ||
| $cfg.CodeCoverage.OutputPath = 'coverage.xml' | ||
| $cfg.TestResult.Enabled = $true | ||
| $cfg.TestResult.OutputPath = 'testResults.xml' | ||
|
|
||
| $result = Invoke-Pester -Configuration $cfg | ||
|
|
||
| # A file that fails discovery contributes nothing to FailedCount, so both are checked. | ||
| if ($result.FailedCount -gt 0 -or $result.FailedContainersCount -gt 0) { | ||
| throw ("$($result.FailedCount) test(s) and $($result.FailedContainersCount) " + | ||
| "container(s) failed under shuffle seed $seed.") | ||
| } | ||
|
|
||
| $coverage = [math]::Round($result.CodeCoverage.CoveragePercent, 2) | ||
| Write-Host "Code coverage: $coverage%" | ||
| "## Pester`n`nPassed $($result.PassedCount), failed $($result.FailedCount), skipped " + | ||
| "$($result.SkippedCount); coverage $coverage% (seed $seed)." | | ||
| Out-File -Append -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 | ||
| if ($coverage -lt 80) { | ||
| throw "Code coverage $coverage% is below the 80% gate." | ||
| } | ||
| ./Tests/Invoke-Tests.ps1 -CodeCoverage -OutputPath ./reports -Output Detailed -SummaryPath $env:GITHUB_STEP_SUMMARY | ||
|
|
||
| - name: Upload test results and coverage | ||
| if: always() | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: tests-and-analysis | ||
| path: | | ||
| testResults.xml | ||
| coverage.xml | ||
| path: reports/ | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The artifact names are unchanged. The files inside are now |
||
| if-no-files-found: warn | ||
|
|
||
| desktop: | ||
|
|
@@ -190,44 +174,31 @@ jobs: | |
| if ($noHelp) { throw "Commands serving no help under 5.1: $($noHelp -join ', ')" } | ||
| Write-Host "All $($actual.Count) commands exported with help under Windows PowerShell 5.1." | ||
|
|
||
| # Pester 6 declares PowerShellVersion 5.1 and runs the suite unchanged. | ||
| # Pester 6 declares PowerShellVersion 5.1 and runs the suite unchanged. Windows PowerShell | ||
| # has no PSResourceGet, so PowerShellGet installs the same fixed version the other jobs use. | ||
| - name: Install Pester | ||
| shell: powershell | ||
| run: | | ||
| $ErrorActionPreference = 'Stop' | ||
| Install-Module -Name Pester -MinimumVersion 6.2.0 -MaximumVersion 6.99.99 -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber | ||
| Import-Module Pester -MinimumVersion 6.2.0 | ||
| Install-Module -Name Pester -RequiredVersion 6.2.0 -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber | ||
| Import-Module Pester -RequiredVersion 6.2.0 | ||
| "Pester $((Get-Module Pester).Version) on PowerShell $($PSVersionTable.PSVersion)" | Write-Host | ||
|
|
||
| # The integration suite as well: it launches the 5.1 hosts the harness uses on a device. | ||
| # The hosted runner's token is not elevated (IsInRole Administrator is false), so the | ||
| # SYSTEM-context tests skip here as they do under pwsh; they run on the lab devices | ||
| - name: Pester under Windows PowerShell 5.1 | ||
| shell: powershell | ||
| run: | | ||
| $ErrorActionPreference = 'Stop' | ||
| Import-Module Pester -MinimumVersion 6.2.0 | ||
| $cfg = New-PesterConfiguration | ||
| # The integration suite as well: it launches the 5.1 hosts the harness uses on a device. | ||
| # The hosted runner's token is not elevated (IsInRole Administrator is false), so the | ||
| # SYSTEM-context tests skip here as they do under pwsh; they run on the lab devices | ||
| $cfg.Run.Path = './Tests/Unit', './Tests/Integration', './Validation/Tests/Unit' | ||
| $cfg.Run.PassThru = $true | ||
| $cfg.Output.Verbosity = 'Normal' | ||
| $cfg.Should.DisableV5 = $true | ||
| $cfg.TestResult.Enabled = $true | ||
| $cfg.TestResult.OutputPath = 'testResults-desktop.xml' | ||
| $result = Invoke-Pester -Configuration $cfg | ||
| "## Pester under Windows PowerShell 5.1`n`nPassed $($result.PassedCount), failed $($result.FailedCount), " + | ||
| "skipped $($result.SkippedCount)." | Out-File -Append -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 | ||
| if ($result.FailedCount -gt 0 -or $result.FailedContainersCount -gt 0) { | ||
| throw "$($result.FailedCount) test(s) and $($result.FailedContainersCount) container(s) failed under Windows PowerShell 5.1." | ||
| } | ||
| Write-Host "Passed $($result.PassedCount), skipped $($result.SkippedCount) under Windows PowerShell 5.1." | ||
| ./Tests/Invoke-Tests.ps1 -OutputPath ./reports -SummaryPath $env:GITHUB_STEP_SUMMARY | ||
|
|
||
| - name: Upload test results | ||
| if: always() | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: windows-powershell-5-1 | ||
| path: testResults-desktop.xml | ||
| path: reports/ | ||
| if-no-files-found: warn | ||
|
|
||
| arm64: | ||
|
|
@@ -241,36 +212,24 @@ jobs: | |
| - name: Install Pester | ||
| shell: pwsh | ||
| run: | | ||
| Install-PSResource -Name Pester -Version '[6.2.0,7.0.0)' -Scope CurrentUser -TrustRepository | ||
| Import-Module Pester -MinimumVersion 6.2.0 | ||
| $ErrorActionPreference = 'Stop' | ||
| Install-PSResource -Name Pester -Version 6.2.0 -Scope CurrentUser -TrustRepository | ||
| Import-Module Pester -RequiredVersion 6.2.0 | ||
| "Pester $((Get-Module Pester).Version) on $([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)" | | ||
| Write-Host | ||
|
|
||
| - name: Pester on ARM64 | ||
| shell: pwsh | ||
| run: | | ||
| $ErrorActionPreference = 'Stop' | ||
| Import-Module Pester -MinimumVersion 6.2.0 | ||
| $cfg = New-PesterConfiguration | ||
| $cfg.Run.Path = './Tests/Unit', './Validation/Tests/Unit' | ||
| $cfg.Run.PassThru = $true | ||
| $cfg.Output.Verbosity = 'Normal' | ||
| $cfg.Should.DisableV5 = $true | ||
| $cfg.TestResult.Enabled = $true | ||
| $cfg.TestResult.OutputPath = 'testResults-arm64.xml' | ||
| $result = Invoke-Pester -Configuration $cfg | ||
| "## Pester on Windows on ARM`n`nPassed $($result.PassedCount), failed $($result.FailedCount), " + | ||
| "skipped $($result.SkippedCount)." | Out-File -Append -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 | ||
| if ($result.FailedCount -gt 0 -or $result.FailedContainersCount -gt 0) { | ||
| throw "$($result.FailedCount) test(s) and $($result.FailedContainersCount) container(s) failed on ARM64." | ||
| } | ||
| ./Tests/Invoke-Tests.ps1 -TestType Unit -OutputPath ./reports -SummaryPath $env:GITHUB_STEP_SUMMARY | ||
|
|
||
| - name: Upload test results | ||
| if: always() | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: windows-on-arm | ||
| path: testResults-arm64.xml | ||
| path: reports/ | ||
| if-no-files-found: warn | ||
|
|
||
| help: | ||
|
|
@@ -288,6 +247,7 @@ jobs: | |
| - name: Install PlatyPS | ||
| shell: pwsh | ||
| run: | | ||
| $ErrorActionPreference = 'Stop' | ||
| Install-PSResource -Name Microsoft.PowerShell.PlatyPS -Version '1.0.3' -Scope CurrentUser -TrustRepository | ||
| $PSVersionTable | ConvertTo-Json -Depth 3 | ||
|
|
||
|
|
@@ -399,3 +359,27 @@ jobs: | |
| throw 'Test-IntuneScript did not analyze the fixtures on Linux.' | ||
| } | ||
| Write-Host 'Test-IntuneScript analyzed both fixtures on Linux with the expected findings.' | ||
|
|
||
| rehearsal: | ||
| name: 'Release rehearsal' | ||
| runs-on: windows-latest | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v7 | ||
|
|
||
| # The same pin as the help job: the rehearsal rebuilds the MAML, and a different PlatyPS | ||
| # version would emit different XML than the committed help. | ||
| - name: Install PlatyPS | ||
| shell: pwsh | ||
| run: | | ||
| $ErrorActionPreference = 'Stop' | ||
| Install-PSResource -Name Microsoft.PowerShell.PlatyPS -Version '1.0.3' -Scope CurrentUser -TrustRepository | ||
|
|
||
| # Everything the release does except the upload, which -WhatIf holds back. No API key is | ||
| # read under -WhatIf, so the job needs no secret. | ||
| - name: Stage and verify the package | ||
| shell: pwsh | ||
| run: | | ||
| $ErrorActionPreference = 'Stop' | ||
| ./Build/Publish-Module.ps1 -WhatIf | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The time is a free choice. 04:30 UTC is off the top of the hour, when scheduled workflows queue longest, and well before the downloads badge job at 06:17.