Skip to content

Commit 2c0f61f

Browse files
committed
chore(COD-7131): remove the constant enableScaRunning
1 parent 1a7e2d5 commit 2c0f61f

2 files changed

Lines changed: 37 additions & 68 deletions

File tree

src/index.ts

Lines changed: 24 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ import {
1818
generateCacheKey,
1919
} from './util'
2020

21-
// Set to false to disable SCA globally
22-
const enableScaRunning = true
23-
2421
async function runAnalysis() {
2522
const target = getInput('target')
2623

@@ -68,7 +65,7 @@ async function runAnalysis() {
6865
let cacheHit = false
6966
let cacheKey: string | undefined
7067
if (targetScan === 'old') {
71-
cacheKey = await generateCacheKey(enableIacRunning, enableScaRunning, targetScan, modifiedFiles)
68+
cacheKey = await generateCacheKey(enableIacRunning, targetScan, modifiedFiles)
7269
if (cacheKey) {
7370
const restored = await cache.restoreCache([resultsPath], cacheKey)
7471
if (restored) {
@@ -83,23 +80,11 @@ async function runAnalysis() {
8380
}
8481

8582
if (!cacheHit) {
86-
let success = await runCodesec(
87-
'scan',
88-
enableIacRunning,
89-
enableScaRunning,
90-
resultsPath,
91-
targetScan,
92-
modifiedFiles
93-
)
83+
let success = await runCodesec('scan', enableIacRunning, resultsPath, targetScan, modifiedFiles)
9484
if (success && targetScan !== 'new') {
9585
// Save the analysis results when not scanning the PR source branch
9686
if (!cacheKey) {
97-
cacheKey = await generateCacheKey(
98-
enableIacRunning,
99-
enableScaRunning,
100-
targetScan,
101-
modifiedFiles
102-
)
87+
cacheKey = await generateCacheKey(enableIacRunning, targetScan, modifiedFiles)
10388
}
10489
if (cacheKey) {
10590
try {
@@ -113,14 +98,12 @@ async function runAnalysis() {
11398
} else {
11499
// Cache restored — rename files to match current targetScan if needed
115100
const possibleNames = ['old', 'scan']
116-
if (enableScaRunning) {
117-
const scaDir = path.join(resultsPath, 'sca')
118-
for (const name of possibleNames) {
119-
const existing = path.join(scaDir, `sca-${name}.sarif`)
120-
if (existsSync(existing) && name !== targetScan) {
121-
renameSync(existing, path.join(scaDir, `sca-${targetScan}.sarif`))
122-
break
123-
}
101+
const scaDir = path.join(resultsPath, 'sca')
102+
for (const name of possibleNames) {
103+
const existing = path.join(scaDir, `sca-${name}.sarif`)
104+
if (existsSync(existing) && name !== targetScan) {
105+
renameSync(existing, path.join(scaDir, `sca-${targetScan}.sarif`))
106+
break
124107
}
125108
}
126109
if (enableIacRunning) {
@@ -136,21 +119,19 @@ async function runAnalysis() {
136119
}
137120

138121
// Upload SCA SARIF from the returned results path
139-
if (enableScaRunning) {
140-
const scaSarifFile = path.join(resultsPath, 'sca', `sca-${targetScan}.sarif`)
141-
if (existsSync(scaSarifFile)) {
142-
info(`Found SCA SARIF file to upload: ${scaSarifFile}`)
143-
toUpload.push(scaSarifFile)
144-
145-
// Copy SARIF to code-scanning-path for backward compatibility
146-
const codeScanningPath = getInput('code-scanning-path')
147-
if (codeScanningPath) {
148-
info(`Copying SARIF to code-scanning-path: ${codeScanningPath}`)
149-
copyFileSync(scaSarifFile, codeScanningPath)
150-
}
151-
} else {
152-
info(`SCA SARIF file not found at: ${scaSarifFile}`)
122+
const scaSarifFile = path.join(resultsPath, 'sca', `sca-${targetScan}.sarif`)
123+
if (existsSync(scaSarifFile)) {
124+
info(`Found SCA SARIF file to upload: ${scaSarifFile}`)
125+
toUpload.push(scaSarifFile)
126+
127+
// Copy SARIF to code-scanning-path for backward compatibility
128+
const codeScanningPath = getInput('code-scanning-path')
129+
if (codeScanningPath) {
130+
info(`Copying SARIF to code-scanning-path: ${codeScanningPath}`)
131+
copyFileSync(scaSarifFile, codeScanningPath)
153132
}
133+
} else {
134+
info(`SCA SARIF file not found at: ${scaSarifFile}`)
154135
}
155136

156137
// Upload IAC JSON from the returned results path
@@ -180,16 +161,13 @@ async function displayResults() {
180161
const artifactNew = await downloadArtifact('results-new')
181162

182163
// Create local scan-results directory for compare
183-
if (enableScaRunning) {
184-
mkdirSync('scan-results/sca', { recursive: true })
185-
}
164+
mkdirSync('scan-results/sca', { recursive: true })
186165
if (enableIacRunning) {
187166
mkdirSync('scan-results/iac', { recursive: true })
188167
}
189168

190169
// Check and copy files for each scanner type
191-
const scaAvailable =
192-
enableScaRunning && (await prepareScannerFiles('sca', artifactOld, artifactNew))
170+
const scaAvailable = await prepareScannerFiles('sca', artifactOld, artifactNew)
193171
const iacAvailable =
194172
enableIacRunning && (await prepareScannerFiles('iac', artifactOld, artifactNew))
195173

@@ -202,12 +180,7 @@ async function displayResults() {
202180

203181
// Run codesec compare mode with available scanners
204182
const resultsPath = path.join(process.cwd(), 'scan-results')
205-
await runCodesec(
206-
'compare',
207-
enableIacRunning && iacAvailable,
208-
enableScaRunning && scaAvailable,
209-
resultsPath
210-
)
183+
await runCodesec('compare', enableIacRunning && iacAvailable, resultsPath)
211184

212185
// Read comparison output - check all possible outputs
213186
const outputs = [

src/util.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,12 @@ export function shouldRunIaCScanner(modifiedFiles: string): boolean {
165165
// 3. action='compare' -> compares new/old results, generates diff markdown for PR comment
166166
//
167167
// Parameters:
168-
// - runIac/runSca: which scanners to enable (default false - enable when ready to test)
168+
// - runIac: whether to enable the IaC scanner
169169
// - scanTarget: 'new', 'old', or 'scan' depending on mode
170170
// - computeCacheKey: if true, runs GENERATE_CACHE_KEY mode instead of scanning
171171
export async function runCodesec(
172172
action: string,
173173
runIac: boolean = false,
174-
runSca: boolean = false,
175174
reportsDir: string,
176175
scanTarget?: string,
177176
modifiedFiles?: string,
@@ -213,7 +212,7 @@ export async function runCodesec(
213212
'-e',
214213
`LW_API_SECRET=${lwApiSecret}`,
215214
'-e',
216-
`RUN_SCA=${runSca}`,
215+
`RUN_SCA=true`,
217216
'-e',
218217
`RUN_IAC=${runIac}`,
219218
'-e',
@@ -246,17 +245,15 @@ export async function runCodesec(
246245
}
247246

248247
// Copy results out of container to temp dir
249-
if (runSca) {
250-
const scaDir = path.join(reportsDir, 'sca')
251-
mkdirSync(scaDir, { recursive: true })
252-
await callCommand(
253-
'docker',
254-
'container',
255-
'cp',
256-
`${containerName}:/tmp/scan-results/sca/sca-${scanTarget || 'scan'}.sarif`,
257-
path.join(scaDir, `sca-${scanTarget || 'scan'}.sarif`)
258-
)
259-
}
248+
const scaDir = path.join(reportsDir, 'sca')
249+
mkdirSync(scaDir, { recursive: true })
250+
await callCommand(
251+
'docker',
252+
'container',
253+
'cp',
254+
`${containerName}:/tmp/scan-results/sca/sca-${scanTarget || 'scan'}.sarif`,
255+
path.join(scaDir, `sca-${scanTarget || 'scan'}.sarif`)
256+
)
260257

261258
if (runIac) {
262259
const iacDir = path.join(reportsDir, 'iac')
@@ -304,7 +301,7 @@ export async function runCodesec(
304301
'-e',
305302
`LW_API_SECRET=${lwApiSecret}`,
306303
'-e',
307-
`RUN_SCA=${runSca}`,
304+
`RUN_SCA=true`,
308305
'-e',
309306
`RUN_IAC=${runIac}`,
310307
'lacework/codesec:latest',
@@ -350,14 +347,13 @@ export function readMarkdownFile(filePath: string): string {
350347

351348
export async function generateCacheKey(
352349
runIac: boolean,
353-
runSca: boolean,
354350
scanTarget?: string,
355351
modifiedFiles?: string
356352
): Promise<string | undefined> {
357353
const reportsDir = path.join(os.tmpdir(), `codesec-cache-${Date.now()}`)
358354

359355
try {
360-
await runCodesec('scan', runIac, runSca, reportsDir, scanTarget, modifiedFiles, true)
356+
await runCodesec('scan', runIac, reportsDir, scanTarget, modifiedFiles, true)
361357
} catch (e) {
362358
info(`Cache key generation failed: ${(e as Error).message}`)
363359
return undefined

0 commit comments

Comments
 (0)