Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 0 additions & 10 deletions integration-tests/init-with-token/expected/.codacy/codacy.yaml
Comment thread
zhamborova marked this conversation as resolved.

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
30 changes: 17 additions & 13 deletions utils/sarif.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,8 @@ func MergeSarifOutputs(inputFiles []string, outputFile string) error {
return fmt.Errorf("failed to read SARIF file %s: %w", file, err)
}

// Filter out rule definitions from each input file
filteredData, err := FilterRuleDefinitions(data)
if err != nil {
return fmt.Errorf("failed to filter rules from SARIF file %s: %w", file, err)
}

var sarif SimpleSarifReport
if err := json.Unmarshal(filteredData, &sarif); err != nil {
if err := json.Unmarshal(data, &sarif); err != nil {
return fmt.Errorf("failed to parse SARIF file %s: %w", file, err)
}

Expand All @@ -234,16 +228,26 @@ func MergeSarifOutputs(inputFiles []string, outputFile string) error {
return nil
}

// FilterRuleDefinitions removes rule definitions from SARIF output
func FilterRuleDefinitions(sarifData []byte) ([]byte, error) {
var report SarifReport
// FilterRulesFromSarif removes rule definitions from SARIF output if needed
// This should be called separately after MergeSarifOutputs if rule filtering is required
func FilterRulesFromSarif(sarifData []byte) ([]byte, error) {
// Use a map to preserve all fields during unmarshaling
var report map[string]interface{}
Copy link
Copy Markdown
Contributor

@andrzej-janczak andrzej-janczak May 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was ok work on the parsed (structure) version var report SarifReport

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these change are due to previously disappeared fields in serifs

Copy link
Copy Markdown
Contributor

@andrzej-janczak andrzej-janczak May 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what I mean is that this version, it has this longer implementation, but doing exactly same thing
So I think we can just get back to old impl of this and it should be fine right ? 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted to your versions, but there are now missing fields in the actual sarif that we used have, especially visible in eslint failure 🤔

if err := json.Unmarshal(sarifData, &report); err != nil {
return nil, fmt.Errorf("failed to parse SARIF data: %w", err)
}

// Remove rules from each run
for i := range report.Runs {
report.Runs[i].Tool.Driver.Rules = nil
// Navigate to the runs array and remove rules from each run
if runs, ok := report["runs"].([]interface{}); ok {
for _, run := range runs {
if runMap, ok := run.(map[string]interface{}); ok {
if tool, ok := runMap["tool"].(map[string]interface{}); ok {
if driver, ok := tool["driver"].(map[string]interface{}); ok {
driver["rules"] = nil
}
}
}
}
}

// Marshal back to JSON with indentation
Expand Down
Loading