[BUG] Adding a PSRuleConvention triggers more tests to run
@ElinoraWhite is already working on this.
Since Jan 20, 2025.
- Dominant language
- C#
- Stars
- 474
- Forks
- 65
- Avg merge
- 22h 25m
- Merged PRs (30d)
- 26
Description
Description of the issue
Hi,
This bug report is a bit strange, and there are probably other ways to reproduce this.
We were debugging why we are somewhat frequently getting the "bicep.exe is missing" error that other issues have been raised regarding.
As part of that process we added this file:
.ps-rule/Debug.Rule.ps1 which has write-host output of PSRULE_AZURE_BICEP_PATH. This works as expected.
However, when we added that file (even if we didn't reference the convention in the ps-rule.yaml file), the following tests triggered, flagging problems with our IaC:
- Azure.VNET.PrivateSubnet
- Azure.LogAnalytics.Replication (This is marked as Preview, so I am confused as to why that is ran, we do not pass the @pre tag)
- CAF.Tag.ResourceGroup
If we delete the Debug.Rule.ps1 file, the those tests no longer fail (e.g. they are not ran).
our .ps-rule.yaml file (at root of repo) has requires for PSRule.Rules.Azure, and PSRule.Rules.CAF, they also include both of these under include.module
Of note: When calling Assert-PSRule we provide InputPath (repo to test), Option (the yaml file in the repo to test), but also the Path property, which is a path to a library-repo containing rules we have written to ensure compliance. These rules are processed both with, and without the .ps-rule/ folder, so works as expected.
For reference, the .ps-rule/Debug.Rule.ps1 file content:
Export-PSRuleConvention 'DebugBicepCLI' -Initialize {
Write-Host "PSRULE_AZURE_BICEP_PATH=$($Env:PSRULE_AZURE_BICEP_PATH)"
if ($null -ne $Env:PSRULE_AZURE_BICEP_PATH) {
Write-Host "Bicep CLI PATH=$((Get-ChildItem -Path $Env:PSRULE_AZURE_BICEP_PATH | Select-Object -First 1).FullName)"
Write-Host "Bicep CLI version=$(& $Env:PSRULE_AZURE_BICEP_PATH --version)"
}
}
How do we ensure the desired tests are ran from third party modules (CAF and Azure), preferably without having to provide a .ps-rule/ folder, as we often do not need it.
I tried to reproduce with adding a .ps-rule/gitkeep file, but that didn't cause the new tests to run, so it appears to be filename or file content dependant.
Error messages
N/A
Reproduction
- Try to run CAF tests without having a .ps-rule/ folder in the repo to test.
Version of PSRule
2.9.0
How are you running PSRule
locally with powershell, reproducible in Azure DevOps pipeline
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.