Skip to content

Commit 7c0c420

Browse files
committed
fix sarifs
1 parent bb33d65 commit 7c0c420

2 files changed

Lines changed: 44 additions & 17 deletions

File tree

.github/workflows/it-test.yml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ jobs:
7878
7979
- name: Run init tests on Windows
8080
if: matrix.os == 'windows-latest'
81+
id: run_init_tests_windows
8182
shell: pwsh
8283
run: |
8384
$ErrorActionPreference = "Stop"
@@ -102,7 +103,7 @@ jobs:
102103
103104
- name: Run tool tests
104105
if: matrix.os != 'windows-latest'
105-
id: run_tests
106+
id: run_tool_tests_unix
106107
continue-on-error: true
107108
shell: bash
108109
run: |
@@ -136,7 +137,29 @@ jobs:
136137
fi
137138
138139
- name: Check test results
139-
if: failure()
140+
if: always()
140141
run: |
141-
echo "Job failed because some tests failed. Please check the logs above for details."
142-
exit 1
142+
FAILED=false
143+
144+
# Check init tests on Windows
145+
if [ "${{ matrix.os }}" = "windows-latest" ] && [ "${{ steps.run_init_tests_windows.outcome }}" = "failure" ]; then
146+
echo "❌ Init tests failed on Windows"
147+
FAILED=true
148+
fi
149+
150+
# Check init tests on Unix
151+
if [ "${{ matrix.os }}" != "windows-latest" ] && [ "${{ steps.run_init_tests_unix.outcome }}" = "failure" ]; then
152+
echo "❌ Init tests failed on Unix"
153+
FAILED=true
154+
fi
155+
156+
# Check tool tests on Unix
157+
if [ "${{ matrix.os }}" != "windows-latest" ] && [ "${{ steps.run_tool_tests_unix.outcome }}" = "failure" ]; then
158+
echo "❌ Tool tests failed on Unix"
159+
FAILED=true
160+
fi
161+
162+
if [ "$FAILED" = true ]; then
163+
echo "Job failed because some tests failed. Please check the logs above for details."
164+
exit 1
165+
fi

utils/sarif.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,8 @@ func MergeSarifOutputs(inputFiles []string, outputFile string) error {
204204
return fmt.Errorf("failed to read SARIF file %s: %w", file, err)
205205
}
206206

207-
// Filter out rule definitions from each input file
208-
filteredData, err := FilterRuleDefinitions(data)
209-
if err != nil {
210-
return fmt.Errorf("failed to filter rules from SARIF file %s: %w", file, err)
211-
}
212-
213207
var sarif SimpleSarifReport
214-
if err := json.Unmarshal(filteredData, &sarif); err != nil {
208+
if err := json.Unmarshal(data, &sarif); err != nil {
215209
return fmt.Errorf("failed to parse SARIF file %s: %w", file, err)
216210
}
217211

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

237-
// FilterRuleDefinitions removes rule definitions from SARIF output
238-
func FilterRuleDefinitions(sarifData []byte) ([]byte, error) {
239-
var report SarifReport
231+
// FilterRulesFromSarif removes rule definitions from SARIF output if needed
232+
// This should be called separately after MergeSarifOutputs if rule filtering is required
233+
func FilterRulesFromSarif(sarifData []byte) ([]byte, error) {
234+
// Use a map to preserve all fields during unmarshaling
235+
var report map[string]interface{}
240236
if err := json.Unmarshal(sarifData, &report); err != nil {
241237
return nil, fmt.Errorf("failed to parse SARIF data: %w", err)
242238
}
243239

244-
// Remove rules from each run
245-
for i := range report.Runs {
246-
report.Runs[i].Tool.Driver.Rules = nil
240+
// Navigate to the runs array and remove rules from each run
241+
if runs, ok := report["runs"].([]interface{}); ok {
242+
for _, run := range runs {
243+
if runMap, ok := run.(map[string]interface{}); ok {
244+
if tool, ok := runMap["tool"].(map[string]interface{}); ok {
245+
if driver, ok := tool["driver"].(map[string]interface{}); ok {
246+
driver["rules"] = nil
247+
}
248+
}
249+
}
250+
}
247251
}
248252

249253
// Marshal back to JSON with indentation

0 commit comments

Comments
 (0)