Skip to content
Draft
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
34 changes: 6 additions & 28 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
} from './actions'
import {
callCommand,
runCodesec,
runCodesecScan,
runCodesecCompare,
getModifiedFiles,
getOptionalEnvVariable,
readMarkdownFile,
generateCacheKey,
} from './util'

Expand Down Expand Up @@ -73,7 +73,7 @@ async function runAnalysis() {
}

if (!cacheHit) {
let success = await runCodesec('scan', enableIacRunning, resultsPath, targetScan, modifiedFiles)
let success = await runCodesecScan(enableIacRunning, resultsPath, targetScan, modifiedFiles)
if (success && targetScan !== 'new') {
// Save the analysis results when not scanning the PR source branch
if (!cacheKey) {
Expand Down Expand Up @@ -145,8 +145,6 @@ async function runAnalysis() {
}

async function displayResults() {
const enableIacRunning = true

info('Displaying results')

// Download artifacts from previous jobs
Expand All @@ -155,37 +153,17 @@ async function displayResults() {

// Create local scan-results directory for compare
mkdirSync('scan-results/sca', { recursive: true })
if (enableIacRunning) {
mkdirSync('scan-results/iac', { recursive: true })
}
mkdirSync('scan-results/iac', { recursive: true })

// Check and copy files for each scanner type
if (!(await prepareScannerFiles('sca', artifactOld, artifactNew))) {
error('SCA files not found. Cannot perform compare.')
return
}
const iacAvailable =
enableIacRunning && (await prepareScannerFiles('iac', artifactOld, artifactNew))
const iacAvailable = await prepareScannerFiles('iac', artifactOld, artifactNew)

// Run codesec compare mode with available scanners
const resultsPath = path.join(process.cwd(), 'scan-results')
await runCodesec('compare', enableIacRunning && iacAvailable, resultsPath)

// Read comparison output - check all possible outputs
const outputs = [
'scan-results/compare/merged-compare.md',
'scan-results/compare/sca-compare.md',
'scan-results/compare/iac-compare.md',
]

let message: string | null = null
for (const output of outputs) {
if (existsSync(output)) {
info(`Using comparison output: ${output}`)
message = readMarkdownFile(output)
break
}
}
const message = await runCodesecCompare(iacAvailable)

if (!message) {
info('No comparison output produced. No changes detected.')
Expand Down
Loading
Loading