Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
"tf-plan-ci": "SCRIPT_PATH=\"$PWD/scripts/tf-plan-smart.sh\"; ./scripts/tf-walker-parallel.sh \"terraform init && bash \\\"$SCRIPT_PATH\\\"\" \"tf-plan-ci-$(date +%Y%m%d-%H%M%S)\" true 4 ci",
"tf-plan-blueprints": "SCRIPT_PATH=\"$PWD/scripts/tf-plan-smart.sh\"; ./scripts/tf-walker-parallel.sh \"terraform init && bash \\\"$SCRIPT_PATH\\\"\" \"tf-plan-blueprints-$(date +%Y%m%d-%H%M%S)\" true 4 blueprints",
"tf-plan-all": "SCRIPT_PATH=\"$PWD/scripts/tf-plan-smart.sh\"; ./scripts/tf-walker-parallel.sh \"terraform init && bash \\\"$SCRIPT_PATH\\\"\" \"tf-plan-all-$(date +%Y%m%d-%H%M%S)\" true 4",
"go-test": "pwsh -File ./scripts/linting/Invoke-GoTest.ps1",
"go-test:changed": "pwsh -File ./scripts/linting/Invoke-GoTest.ps1 -ChangedOnly",
"go-test:contract:terraform": "cd blueprints/full-single-node-cluster/tests && go test -v -run TestTerraformOutputsContract",
"go-test:contract:bicep": "cd blueprints/full-single-node-cluster/tests && go test -v -run TestBicepOutputsContract",
"go-test:deploy": "npm run go-test:deploy:terraform && npm run go-test:deploy:bicep",
"go-test:deploy:terraform": "cd blueprints/full-single-node-cluster/tests && go test -v -run TestTerraformFullSingleNodeClusterDeploy -timeout 2h",
"go-test:deploy:bicep": "cd blueprints/full-single-node-cluster/tests && go test -v -run TestBicepFullSingleNodeClusterDeploy -timeout 2h",
"format-tables": "pwsh -File ./scripts/linting/Format-Markdown-Tables.ps1",
"format-tables-check": "pwsh -File ./scripts/linting/Format-Markdown-Tables.ps1 -Check",
"checkov-changes": "pwsh -Command \"& $PWD/scripts/build/Detect-Folder-Changes.ps1 -OutputJson | & $PWD/scripts/Run-Checkov.ps1 -OutputFolder './checkov-results' -OutputFile 'code-analysis.xml'\"",
Expand Down
74 changes: 74 additions & 0 deletions scripts/build/Detect-Folder-Changes.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,80 @@ Describe 'Test-RustHasChange' -Tag 'Unit' {
}
}

Describe 'Test-IsGoContractTestChangeFile' -Tag 'Unit' {
Context 'when evaluating Go contract-test trigger paths' {
It 'Detects Go contract-test relevant files' {
Test-IsGoContractTestChangeFile -Path 'blueprints/full-single-node-cluster/tests/go.mod' | Should -BeTrue
Test-IsGoContractTestChangeFile -Path 'blueprints/full-single-node-cluster/tests/output_contract_test.go' | Should -BeTrue
Test-IsGoContractTestChangeFile -Path 'blueprints/full-single-node-cluster/terraform/outputs.tf' | Should -BeTrue
Test-IsGoContractTestChangeFile -Path 'blueprints/full-single-node-cluster/bicep/main.bicep' | Should -BeTrue
Test-IsGoContractTestChangeFile -Path 'scripts/linting/Invoke-GoTest.ps1' | Should -BeTrue
Test-IsGoContractTestChangeFile -Path 'scripts/tests/linting/Invoke-GoTest.Tests.ps1' | Should -BeTrue
Test-IsGoContractTestChangeFile -Path 'src/900-tools-utilities/904-test-utilities/contract.go' | Should -BeTrue
Test-IsGoContractTestChangeFile -Path 'src/900-tools-utilities/904-test-utilities/go.mod' | Should -BeTrue
Test-IsGoContractTestChangeFile -Path 'scripts/install-terraform-docs.sh' | Should -BeTrue
Test-IsGoContractTestChangeFile -Path 'scripts/build/Detect-Folder-Changes.ps1' | Should -BeTrue
Test-IsGoContractTestChangeFile -Path '.github/workflows/go-tests.yml' | Should -BeTrue
Test-IsGoContractTestChangeFile -Path '.github/workflows/matrix-folder-check.yml' | Should -BeTrue
Test-IsGoContractTestChangeFile -Path '.github/workflows/pr-validation.yml' | Should -BeTrue
Test-IsGoContractTestChangeFile -Path 'package.json' | Should -BeTrue
Test-IsGoContractTestChangeFile -Path 'package-lock.json' | Should -BeTrue
}

It 'Ignores unrelated files' {
Test-IsGoContractTestChangeFile -Path 'docs/readme.md' | Should -BeFalse
Test-IsGoContractTestChangeFile -Path 'src/000-cloud/010-security-identity/terraform/main.tf' | Should -BeFalse
Test-IsGoContractTestChangeFile -Path '.github/workflows/rust-tests.yml' | Should -BeFalse
Test-IsGoContractTestChangeFile -Path 'Cargo.toml' | Should -BeFalse
Test-IsGoContractTestChangeFile -Path 'blueprints/full-single-node-cluster/tests/start.sh' | Should -BeFalse
Test-IsGoContractTestChangeFile -Path '' | Should -BeFalse
}
}
}

Describe 'Test-GoContractTestHasChange' -Tag 'Unit' {
Context 'when evaluating changed file collections' {
It 'Returns false for null or empty inputs' {
Test-GoContractTestHasChange -ChangedFiles $null | Should -BeFalse
Test-GoContractTestHasChange -ChangedFiles @() | Should -BeFalse
}

It 'Returns true when any file should trigger Go contract tests' {
Test-GoContractTestHasChange -ChangedFiles @('docs/readme.md', 'blueprints/full-single-node-cluster/tests/go.mod') | Should -BeTrue
Test-GoContractTestHasChange -ChangedFiles @('blueprints/full-single-node-cluster/terraform/outputs.tf') | Should -BeTrue
Test-GoContractTestHasChange -ChangedFiles @('.github/workflows/go-tests.yml') | Should -BeTrue
Test-GoContractTestHasChange -ChangedFiles @('docs/readme.md', 'src/900-tools-utilities/904-test-utilities/contract.go') | Should -BeTrue
Test-GoContractTestHasChange -ChangedFiles @('docs/readme.md', 'scripts/install-terraform-docs.sh') | Should -BeTrue
}

It 'Returns false when no files should trigger Go contract tests' {
Test-GoContractTestHasChange -ChangedFiles @('docs/readme.md', 'src/000-cloud/010-security-identity/terraform/main.tf') | Should -BeFalse
}
}
}

Describe 'Test-IsTerraformInstallChangeFile' -Tag 'Unit' {
Context 'when evaluating Terraform module-test trigger paths' {
It 'Detects Terraform source and variable files' {
Test-IsTerraformInstallChangeFile -Path 'blueprints/full-single-node-cluster/terraform/outputs.tf' | Should -BeTrue
Test-IsTerraformInstallChangeFile -Path 'src/000-cloud/010-security-identity/terraform/main.tf' | Should -BeTrue
Test-IsTerraformInstallChangeFile -Path 'blueprints/full-single-node-cluster/terraform/test.tfvars' | Should -BeTrue
Test-IsTerraformInstallChangeFile -Path 'blueprints/full-single-node-cluster/terraform/backend.hcl' | Should -BeTrue
}

It 'Ignores Go contract-test tooling and non-Terraform files' {
Test-IsTerraformInstallChangeFile -Path 'blueprints/full-single-node-cluster/tests/output_contract_test.go' | Should -BeFalse
Test-IsTerraformInstallChangeFile -Path 'blueprints/full-single-node-cluster/tests/go.mod' | Should -BeFalse
Test-IsTerraformInstallChangeFile -Path 'scripts/linting/Invoke-GoTest.ps1' | Should -BeFalse
Test-IsTerraformInstallChangeFile -Path 'src/900-tools-utilities/904-test-utilities/contract.go' | Should -BeFalse
Test-IsTerraformInstallChangeFile -Path 'scripts/install-terraform-docs.sh' | Should -BeFalse
Test-IsTerraformInstallChangeFile -Path '.github/workflows/go-tests.yml' | Should -BeFalse
Test-IsTerraformInstallChangeFile -Path 'package.json' | Should -BeFalse
Test-IsTerraformInstallChangeFile -Path '' | Should -BeFalse
}
}
}

Describe 'Get-BicepFullValidationReason' -Tag 'Unit' {
It 'returns bicepconfig for root Bicep configuration changes' {
@(Get-BicepFullValidationReason -Files @('bicepconfig.json')) | Should -Contain 'bicepconfig'
Expand Down
65 changes: 64 additions & 1 deletion scripts/build/Detect-Folder-Changes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ $fuzzPythonFolders = [PSCustomObject]@{ folderName = @() }
$fuzzJsHasChanges = $false
$fuzzJsFolders = [PSCustomObject]@{ folderName = @() }
$rustHasChanges = $false
$goContractTestsHasChanges = $false

# Use native PowerShell commands where possible and minimize redundant operations

Expand All @@ -349,6 +350,38 @@ function Test-IsRustChangeFile {
return $Path -match '(\.rs$|(^|/)Cargo\.(toml|lock)$|^\.github/workflows/(rust-tests|pr-validation)\.yml$|^codecov\.yml$)'
}

function Test-IsGoContractTestChangeFile {
<#
.SYNOPSIS
Returns $true when a repo-relative path should trigger the go-tests workflow.
.DESCRIPTION
Matches the full-single-node-cluster Terraform, Bicep, and Go contract test
inputs plus workflow and detector files that influence the static Go contract
test pipeline.
#>
param (
[Parameter(Mandatory = $true)]
[AllowEmptyString()]
[string]$Path
)

return $Path -match '(^blueprints/full-single-node-cluster/(terraform|bicep)/|^blueprints/full-single-node-cluster/tests/([^/]+\.go|go\.(mod|sum))$|^src/900-tools-utilities/904-test-utilities/|^scripts/install-terraform-docs\.sh$|^scripts/linting/Invoke-GoTest\.ps1$|^scripts/tests/linting/Invoke-GoTest\.Tests\.ps1$|^\.github/workflows/(go-tests|matrix-folder-check|pr-validation)\.yml$|^scripts/build/Detect-Folder-Changes\.ps1$|^package(-lock)?\.json$)'
}

function Test-IsTerraformInstallChangeFile {
<#
.SYNOPSIS
Returns $true when a repo-relative path should trigger Terraform module tests.
#>
param (
[Parameter(Mandatory = $true)]
[AllowEmptyString()]
[string]$Path
)

return $Path -match '\.(tf|tfvars|tfstate|hcl)$'
}

function Test-RustHasChange {
<#
.SYNOPSIS
Expand All @@ -373,6 +406,30 @@ function Test-RustHasChange {
return $false
}

function Test-GoContractTestHasChange {
<#
.SYNOPSIS
Returns $true when any path in $ChangedFiles matches the Go contract-test gating ruleset.
#>
param (
[Parameter(Mandatory = $false)]
[AllowNull()]
[string[]]$ChangedFiles
)

if ($null -eq $ChangedFiles -or $ChangedFiles.Count -eq 0) {
return $false
}

foreach ($file in $ChangedFiles) {
if (Test-IsGoContractTestChangeFile -Path $file) {
return $true
}
}

return $false
}

function Get-ChangedFileData {
param (
[switch]$IncludeAll,
Expand Down Expand Up @@ -712,7 +769,7 @@ if ($IncludeAllIaC -and $VerbosePreference -ne 'SilentlyContinue') {
}

# Process IaC changes - ALWAYS scan, switch controls filter
$tfFiles = $changedFiles | Where-Object { $_ -match '\.(tf|tfvars|tfstate|hcl)$' }
$tfFiles = $changedFiles | Where-Object { Test-IsTerraformInstallChangeFile -Path $_ }
$bicepFiles = $changedFiles | Where-Object { $_ -match '\.bicep$' }

# Process paths in single batch operations
Expand Down Expand Up @@ -860,6 +917,12 @@ $jsonOutput | Add-Member -MemberType NoteProperty -Name "rust" -Value ([PSCustom
has_changes = [bool]$rustHasChanges
})

$goContractTestsHasChanges = Test-GoContractTestHasChange -ChangedFiles $changedFiles

$jsonOutput | Add-Member -MemberType NoteProperty -Name "goContractTests" -Value ([PSCustomObject]@{
has_changes = [bool]$goContractTestsHasChanges
})

# Convert to JSON
$jsonString = $jsonOutput | ConvertTo-Json -Depth 10

Expand Down
Loading
Loading