Skip to content
Merged
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
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import {
getModifiedFiles,
getOptionalEnvVariable,
readMarkdownFile,
shouldRunIaCScanner,
} from './util'
import { simpleGit } from 'simple-git'

// Global scanner toggles - set to false to disable a scanner globally
const enableScaRunning = true
const enableIacRunning = true
let enableIacRunning = false

async function runAnalysis() {
const target = getInput('target')
Expand Down Expand Up @@ -53,6 +54,13 @@ async function runAnalysis() {
}
}

// Skip the IaC scan if there no IaC-related files have been modified in the PR
if (modifiedFiles && target == 'new') {
if (shouldRunIaCScanner(modifiedFiles)) {
enableIacRunning = true
}
}

// Create scan-results directory
const resultsPath = path.join(process.cwd(), 'scan-results')

Expand Down
30 changes: 30 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,36 @@ export function getModifiedFiles(): string | undefined {
return files || undefined
}

export function shouldRunIaCScanner(modifiedFiles: string): boolean {
const iacFileExtensions = ['.tf', '.hcl', '.yaml', '.yml', '.json']
const nonIaCFilenames = [
'package.json',
'package-lock.json',
'tsconfig.json',
'tsconfig.build.json',
'tslint.json',
'jest.config.json',
'.eslintrc.json',
'.prettierrc.json',
'.prettierrc.yaml',
'.prettierrc.yml',
'renovate.json',
'lerna.json',
'bower.json',
'composer.json',
'composer.lock',
'Pipfile.lock',
'cargo.lock',
]
return modifiedFiles.split(',').some((file) => {
const filename = file.split('/').pop() || ''
if (nonIaCFilenames.includes(filename.toLowerCase())) {
return false
}
return iacFileExtensions.some((ext) => file.endsWith(ext))
})
}

// runCodesec - Docker-based scanner using codesec:latest image
//
// Modes:
Expand Down
Loading