Skip to content
Merged
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
11 changes: 5 additions & 6 deletions scripts/PSCodingStandards/Get-RuleForPath.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
39 changes: 39 additions & 0 deletions scripts/PSCodingStandards/Test-GetRuleForPath.ps1
Original file line number Diff line number Diff line change
@@ -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)"
}
}
}
2 changes: 1 addition & 1 deletion scripts/matrix_testing/CompileFixTool.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion scripts/matrix_testing/Config.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Import-Module -Name "$PSScriptRoot/../PSCodingStandards/CodingStandards"

$COMPILER_MAPPINGS = @{
"cpp" = @{
"clang" = "clang++";
Expand Down Expand Up @@ -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 = @"
Expand Down
2 changes: 1 addition & 1 deletion scripts/matrix_testing/CreateMatrixTestReport.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down