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
40 changes: 28 additions & 12 deletions .github/workflows/it-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,9 @@ jobs:
if: matrix.os != 'windows-latest'
run: chmod +x cli-v2

- name: Install yq on Windows
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
choco install yq -y
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
refreshenv

- name: Run init tests on Windows
if: matrix.os == 'windows-latest'
id: run_init_tests_windows
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
Expand All @@ -102,7 +95,7 @@ jobs:

- name: Run tool tests
if: matrix.os != 'windows-latest'
id: run_tests
id: run_tool_tests_unix
continue-on-error: true
shell: bash
run: |
Expand Down Expand Up @@ -136,7 +129,30 @@ jobs:
fi

- name: Check test results
if: failure()
if: always()
shell: bash
run: |
echo "Job failed because some tests failed. Please check the logs above for details."
exit 1
FAILED=false

# Check init tests on Windows
if [ "${{ matrix.os }}" = "windows-latest" ] && [ "${{ steps.run_init_tests_windows.outcome }}" = "failure" ]; then
echo "❌ Init tests failed on Windows"
FAILED=true
fi

# Check init tests on Unix
if [ "${{ matrix.os }}" != "windows-latest" ] && [ "${{ steps.run_init_tests_unix.outcome }}" = "failure" ]; then
echo "❌ Init tests failed on Unix"
FAILED=true
fi

# Check tool tests on Unix
if [ "${{ matrix.os }}" != "windows-latest" ] && [ "${{ steps.run_tool_tests_unix.outcome }}" = "failure" ]; then
echo "❌ Tool tests failed on Unix"
FAILED=true
fi

if [ "$FAILED" = true ]; then
echo "Job failed because some tests failed. Please check the logs above for details."
exit 1
fi
27 changes: 15 additions & 12 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,20 +482,23 @@ var analyzeCmd = &cobra.Command{
log.Fatalf("Failed to merge SARIF outputs: %v", err)
}

// Filter rules from the merged SARIF output
sarifData, err := os.ReadFile(tmpOutputFile)
if err != nil {
log.Fatalf("Failed to read merged SARIF output: %v", err)
}

filteredData, err := utils.FilterRulesFromSarif(sarifData)
if err != nil {
log.Fatalf("Failed to filter rules from SARIF: %v", err)
}

if outputFile != "" {
// copy tmpOutputFile to outputFile
content, err := os.ReadFile(tmpOutputFile)
if err != nil {
log.Fatalf("Failed to read merged SARIF output: %v", err)
}
os.WriteFile(outputFile, content, utils.DefaultFilePerms)
// Write filtered SARIF to output file
os.WriteFile(outputFile, filteredData, utils.DefaultFilePerms)
} else {
// println the output file content
content, err := os.ReadFile(tmpOutputFile)
if err != nil {
log.Fatalf("Failed to read merged SARIF output: %v", err)
}
fmt.Println(string(content))
// Print the filtered SARIF output
fmt.Println(string(filteredData))
}
} else {
// Run tools without merging outputs
Expand Down
10 changes: 0 additions & 10 deletions integration-tests/init-with-token/expected/.codacy/codacy.yaml

This file was deleted.

3 changes: 2 additions & 1 deletion integration-tests/init-with-token/expected/codacy.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
runtimes:
- node@22.2.0
- python@3.11.11
- java@17.0.10
tools:
- eslint@8.57.0
- trivy@0.59.1
- pylint@3.3.6
- pmd@6.55.0
- semgrep@1.78.0
- lizard@1.17.19
- lizard@1.17.19
3 changes: 2 additions & 1 deletion integration-tests/init-without-token/expected/codacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ runtimes:
- node@22.2.0
- python@3.11.11
- dart@3.7.2
- java@17.0.10
tools:
- eslint@9.3.0
- trivy@0.59.1
- pylint@3.3.6
- pmd@6.55.0
- dartanalyzer@3.7.2
- semgrep@1.78.0
- lizard@1.17.19
- lizard@1.17.19
48 changes: 44 additions & 4 deletions integration-tests/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,45 @@ function Normalize-Config {
$ext = [System.IO.Path]::GetExtension($file).TrimStart('.')

switch ($ext) {
{ $_ -in @('yaml', 'yml') } { yq e '.' $file | Sort-Object }
{ $_ -in @('yaml', 'yml') } {
# For YAML files, preserve structure and sort within sections
$content = Get-Content $file
$output = @()
$currentSection = ""
$sectionContent = @()

foreach ($line in $content) {
$line = $line.Trim()
if ($line -match '^(\w+):$') {
# If we have a previous section, sort and add its content
if ($currentSection -and $sectionContent.Count -gt 0) {
$output += $currentSection
$output += ($sectionContent | Sort-Object)
$sectionContent = @()
}
$currentSection = $line
}
elseif ($line -match '^\s*-\s*') {
$sectionContent += $line
}
elseif ($line -match '\S') {
$output += $line
}
}

# Add the last section
if ($currentSection -and $sectionContent.Count -gt 0) {
$output += $currentSection
$output += ($sectionContent | Sort-Object)
}

# Add empty line at the end if the original had one
if ($content[-1] -match '^\s*$') {
$output += ""
}

$output
}
{ $_ -in @('rc', 'conf', 'ini', 'xml') } {
Get-Content $file | ForEach-Object {
if ($_ -match '^[^#].*=.*,') {
Expand Down Expand Up @@ -54,14 +92,16 @@ function Compare-Files {
$expectedContent = Normalize-Config $_.FullName
$actualContent = Normalize-Config $actualFile

if (Compare-Object $expectedContent $actualContent) {
# Compare line by line
$diff = Compare-Object $expectedContent $actualContent -PassThru
if ($diff) {
Write-Host "❌ $label/$($_.Name) does not match expected"
Write-Host "=== Expected (normalized) ==="
$expectedContent
Write-Host "=== Actual (normalized) ==="
$actualContent
Write-Host "=== Diff ==="
Compare-Object $expectedContent $actualContent
$diff
Write-Host "==================="
exit 1
}
Expand All @@ -70,7 +110,7 @@ function Compare-Files {

# Compare subdirectories
Get-ChildItem -Path $expectedDir -Directory | Where-Object { $_.Name -ne "logs" } | ForEach-Object {
$actualSubDir = if ($_.Name -eq ".codacy") { $actualDir } else { Join-Path $actualDir $_.Name }
$actualSubDir = Join-Path $actualDir $_.Name

if (-not (Test-Path $actualSubDir)) {
Write-Host "❌ Directory $label/$($_.Name) does not exist in actual output"
Expand Down
3 changes: 2 additions & 1 deletion plugins/tools/codacy-enigma-cli/test/expected.sarif
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
{
"tool": {
"driver": {
"name": "codacy-enigma-cli"
"name": "codacy-enigma-cli",
"rules": null
}
},
"results": [
Expand Down
3 changes: 2 additions & 1 deletion plugins/tools/dartanalyzer/test/expected.sarif
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
],
"tool": {
"driver": {
"name": "dartanalyzer"
"name": "dartanalyzer",
"rules": null
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/tools/eslint/test/expected.sarif
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"driver": {
"informationUri": "https://eslint.org",
"name": "ESLint",
"rules": [],
"rules": null,
"version": "8.57.0"
}
}
Expand Down
47 changes: 1 addition & 46 deletions plugins/tools/lizard/test/expected.sarif
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,7 @@
"name": "Lizard",
"version": "1.17.10",
"informationUri": "https://github.com/terryyin/lizard",
"rules": [
{
"id": "Lizard_ccn-medium",
"shortDescription": {
"text": "Check the Cyclomatic Complexity value of a function or logic block. If the threshold is not met, raise a Medium issue. The default threshold is 8."
},
"properties": {
"tags": [
"warning"
]
}
},
{
"id": "Lizard_file-nloc-medium",
"shortDescription": {
"text": "Check the number of lines of code (without comments) in a file. If the threshold is not met, raise a Medium issue. The default threshold is 500."
},
"properties": {
"tags": [
"warning"
]
}
},
{
"id": "Lizard_nloc-medium",
"shortDescription": {
"text": "Check the number of lines of code (without comments) in a function. If the threshold is not met, raise a Medium issue. The default threshold is 50."
},
"properties": {
"tags": [
"warning"
]
}
},
{
"id": "Lizard_parameter-count-medium",
"shortDescription": {
"text": "Check the number of parameters sent to a function. If the threshold is not met, raise a Medium issue. The default threshold is 8."
},
"properties": {
"tags": [
"warning"
]
}
}
]
"rules": null
}
},
"results": [
Expand Down
Loading
Loading