|
1 | 1 | import { error, getInput, info, isDebug } from '@actions/core' |
2 | 2 | import { context } from '@actions/github' |
3 | 3 | import { spawn } from 'child_process' |
4 | | -import { readFileSync, mkdirSync, writeFileSync } from 'fs' |
| 4 | +import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'fs' |
5 | 5 | import * as os from 'os' |
6 | 6 | import * as path from 'path' |
7 | 7 |
|
@@ -246,51 +246,20 @@ export async function runCodesec( |
246 | 246 | const compareDir = path.join(reportsDir, 'compare') |
247 | 247 | mkdirSync(compareDir, { recursive: true }) |
248 | 248 |
|
249 | | - // Copy all available comparison outputs |
250 | | - // merged-compare.md exists when both SCA and IAC comparisons succeed |
251 | | - // sca-compare.md / iac-compare.md exist for individual comparisons |
252 | | - let copiedAny = false |
| 249 | + // Copy the entire compare directory out |
| 250 | + await callCommand( |
| 251 | + 'docker', |
| 252 | + 'container', |
| 253 | + 'cp', |
| 254 | + `${containerName}:/tmp/scan-results/compare/.`, |
| 255 | + compareDir |
| 256 | + ) |
253 | 257 |
|
254 | | - try { |
255 | | - await callCommand( |
256 | | - 'docker', |
257 | | - 'container', |
258 | | - 'cp', |
259 | | - `${containerName}:/tmp/scan-results/compare/merged-compare.md`, |
260 | | - path.join(compareDir, 'merged-compare.md') |
261 | | - ) |
262 | | - copiedAny = true |
263 | | - } catch { |
264 | | - info('Merged compare output not found (partial compare mode)') |
265 | | - } |
266 | | - |
267 | | - try { |
268 | | - await callCommand( |
269 | | - 'docker', |
270 | | - 'container', |
271 | | - 'cp', |
272 | | - `${containerName}:/tmp/scan-results/compare/sca-compare.md`, |
273 | | - path.join(compareDir, 'sca-compare.md') |
274 | | - ) |
275 | | - copiedAny = true |
276 | | - } catch { |
277 | | - info('SCA compare output not found (may have been skipped)') |
278 | | - } |
279 | | - |
280 | | - try { |
281 | | - await callCommand( |
282 | | - 'docker', |
283 | | - 'container', |
284 | | - 'cp', |
285 | | - `${containerName}:/tmp/scan-results/compare/iac-compare.md`, |
286 | | - path.join(compareDir, 'iac-compare.md') |
287 | | - ) |
288 | | - copiedAny = true |
289 | | - } catch { |
290 | | - info('IAC compare output not found (may have been skipped)') |
291 | | - } |
| 258 | + // Verify at least one output was produced |
| 259 | + const compareFiles = ['merged-compare.md', 'sca-compare.md', 'iac-compare.md'] |
| 260 | + const copied = compareFiles.filter((f) => existsSync(path.join(compareDir, f))) |
292 | 261 |
|
293 | | - if (!copiedAny) { |
| 262 | + if (copied.length === 0) { |
294 | 263 | throw new Error('No comparison outputs found in container') |
295 | 264 | } |
296 | 265 |
|
|
0 commit comments