diff --git a/scripts/PSCodingStandards/Get-RuleForPath.ps1 b/scripts/PSCodingStandards/Get-RuleForPath.ps1 index bcb056a1f8..34e927e854 100644 --- a/scripts/PSCodingStandards/Get-RuleForPath.ps1 +++ b/scripts/PSCodingStandards/Get-RuleForPath.ps1 @@ -41,11 +41,12 @@ function Get-RuleForPath { $allQueries = @() $queriesToCheck = @() - # load all the queries + foreach ($s in $AVAILABLE_SUITES) { $allQueries += Get-RulesInSuite -Suite $s -Language $Language } + $modifiedPathWithReplacement = Join-Path (Resolve-Path . -Relative) $Path # replace "src" with "test" to make it match up $sep = [IO.Path]::DirectorySeparatorChar @@ -57,20 +58,18 @@ function Get-RuleForPath { # for each query, create the test directory foreach($q in $allQueries){ - # get test directory $testDirs = (Get-ATestDirectory -RuleObject $q -Language $Language) foreach($testDirectory in $testDirs){ # resolve path to be compatible - $testPath = Join-Path (Resolve-Path . -Relative) $testDirectory + $testPath = (Join-Path (Resolve-Path . -Relative) $testDirectory) - # see if the TEST directory is a substring of the full path - if($modifiedPath.StartsWith($testPath)){ + if((Split-Path $modifiedPath -Parent) -eq $testPath){ $matchingRules += $q continue } - if($modifiedPathWithReplacement.StartsWith($testPath)){ + if((Split-Path $modifiedPathWithReplacement -Parent) -eq $testPath){ $matchingRules += $q continue } diff --git a/scripts/PSCodingStandards/Test-GetRuleForPath.ps1 b/scripts/PSCodingStandards/Test-GetRuleForPath.ps1 new file mode 100644 index 0000000000..b3c78cc3dc --- /dev/null +++ b/scripts/PSCodingStandards/Test-GetRuleForPath.ps1 @@ -0,0 +1,39 @@ +function Test-GetRuleForPath { +param( + [Parameter(Mandatory)] + [string] + $PR +) + +$prData = (gh pr view -R github/codeql-coding-standards $PR --json headRefOid,headRepository,author,isCrossRepository,headRepositoryOwner,headRefName,files) | ConvertFrom-Json + +foreach($f in $prData.files){ + try { + Write-Host "[C] Scanning file for relationship $($f.path)..." + $rulesToTest = Get-RuleForPath -Language c -Path "$($f.path)" + + Write-Host "[C] Got $($rulesToTest.Count) potential C rules..." + + foreach($r in $rulesToTest){ + $ruleNames += $r.__memberof_rule + Write-Host "[C] Found rule $r " + } + }catch{ + Write-Host "No $Language rules found for path: $($f.path)" + } + + + try { + Write-Host "[CPP] Scanning file for relationship $($f.path)..." + $rulesToTest = Get-RuleForPath -Language cpp -Path "$($f.path)" + + Write-Host "[CPP] Got $($rulesToTest.Count) potential CPP rules..." + + foreach($r in $rulesToTest){ + Write-Host "[CPP] Found rule $r " + } + }catch{ + Write-Host "No CPP rules found for path: $($f.path)" + } +} +} \ No newline at end of file diff --git a/scripts/matrix_testing/CompileFixTool.ps1 b/scripts/matrix_testing/CompileFixTool.ps1 index 1927e981c3..ba4cd2c146 100755 --- a/scripts/matrix_testing/CompileFixTool.ps1 +++ b/scripts/matrix_testing/CompileFixTool.ps1 @@ -37,7 +37,7 @@ Write-Host -ForegroundColor ([ConsoleColor]2) "OK" $CODEQL_VERSION = (codeql version --format json | ConvertFrom-Json).version Write-Host "Checking 'codeql' version = $REQUIRED_CODEQL_VERSION...." -NoNewline -if (-Not $CODEQL_VERSION -eq $REQUIRED_CODEQL_VERSION) { +if (-Not ($CODEQL_VERSION -eq $REQUIRED_CODEQL_VERSION)) { throw "Invalid CodeQL version $CODEQL_VERSION. Please install $REQUIRED_CODEQL_VERSION." } Write-Host -ForegroundColor ([ConsoleColor]2) "OK" diff --git a/scripts/matrix_testing/Config.ps1 b/scripts/matrix_testing/Config.ps1 index 05aad5dd61..9ae4bb9600 100644 --- a/scripts/matrix_testing/Config.ps1 +++ b/scripts/matrix_testing/Config.ps1 @@ -1,3 +1,5 @@ +Import-Module -Name "$PSScriptRoot/../PSCodingStandards/CodingStandards" + $COMPILER_MAPPINGS = @{ "cpp" = @{ "clang" = "clang++"; @@ -27,7 +29,7 @@ $COMPILER_ARGS = @{ } -$REQUIRED_CODEQL_VERSION = "2.6.3" +$REQUIRED_CODEQL_VERSION = (Get-Content (Join-Path (Get-RepositoryRoot) "supported_codeql_configs.json") | ConvertFrom-Json).supported_environment.codeql_cli $REPORT_QUERY = @" diff --git a/scripts/matrix_testing/CreateMatrixTestReport.ps1 b/scripts/matrix_testing/CreateMatrixTestReport.ps1 index 6928154d4d..f60889fa7a 100644 --- a/scripts/matrix_testing/CreateMatrixTestReport.ps1 +++ b/scripts/matrix_testing/CreateMatrixTestReport.ps1 @@ -262,7 +262,7 @@ Write-Host -ForegroundColor ([ConsoleColor]2) "OK" $CODEQL_VERSION = (codeql version --format json | ConvertFrom-Json).version Write-Host "Checking 'codeql' version = $REQUIRED_CODEQL_VERSION...." -NoNewline -if (-Not $CODEQL_VERSION -eq $REQUIRED_CODEQL_VERSION) { +if (-Not ($CODEQL_VERSION -eq $REQUIRED_CODEQL_VERSION)) { throw "Invalid CodeQL version $CODEQL_VERSION. Please install $REQUIRED_CODEQL_VERSION." } Write-Host -ForegroundColor ([ConsoleColor]2) "OK"