Skip to content
Open
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
1 change: 0 additions & 1 deletion .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ env:
LW_ACCOUNT: ${{ secrets.LW_ACCOUNT_CAT }}
LW_API_KEY: ${{ secrets.LW_API_KEY_CAT }}
LW_API_SECRET: ${{ secrets.LW_API_SECRET_CAT }}
DEBUG: true

jobs:
build:
Expand Down
10 changes: 0 additions & 10 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ inputs:
target:
description: 'One of push, old or new to represent which is being analyzed'
required: false
debug:
description: 'Set to true to enable debug logging'
required: false
default: false
token:
description: 'Set to a GitHub token for the repository with write permissions for PRs to enable PR comments'
required: false
Expand Down Expand Up @@ -53,11 +49,6 @@ runs:
echo "Lacework context ID: $LACEWORK_CONTEXT_ID"
echo "LACEWORK_CONTEXT_ID=$(echo $LACEWORK_CONTEXT_ID)" >> $GITHUB_ENV
echo "LACEWORK_ACTION_REF=$(echo $LACEWORK_ACTION_REF)" >> $GITHUB_ENV
- name: Sets LW_LOG var for debug
shell: bash
if: ${{ inputs.debug == 'true' }}
run: |
echo "LW_LOG=debug" >> $GITHUB_ENV
- name: Set Lacework account environment variable
shell: bash
run: |
Expand All @@ -80,7 +71,6 @@ runs:
with:
sources: '${{ inputs.sources }}'
target: '${{ inputs.target }}'
debug: '${{ inputs.debug }}'
token: '${{ inputs.token || github.token }}'
footer: '${{ inputs.footer }}'
code-scanning-path: '${{ inputs.code-scanning-path }}'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"ts-md5": "^1.3.1"
},
"scripts": {
"test": "npx jest",
"test": "npx jest --passWithNoTests",
"compile": "npx tsc",
"lint-check": "npx eslint **/*.ts",
"lint-fix": "npx eslint --fix **/*.ts",
Expand Down
47 changes: 18 additions & 29 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,14 @@ async function runAnalysis() {
}
}

const enableIacRunning = true

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

// Cache the analysis results when scanning the target branch
let cacheHit = false
let cacheKey: string | undefined
if (targetScan === 'old') {
cacheKey = await generateCacheKey(enableIacRunning, targetScan, modifiedFiles)
cacheKey = await generateCacheKey(targetScan, modifiedFiles)
if (cacheKey) {
const restored = await cache.restoreCache([resultsPath], cacheKey)
if (restored) {
Expand All @@ -73,11 +71,11 @@ async function runAnalysis() {
}

if (!cacheHit) {
let success = await runCodesec('scan', enableIacRunning, resultsPath, targetScan, modifiedFiles)
let success = await runCodesec('scan', true, resultsPath, targetScan, modifiedFiles)
if (success && targetScan !== 'new') {
// Save the analysis results when not scanning the PR source branch
if (!cacheKey) {
cacheKey = await generateCacheKey(enableIacRunning, targetScan, modifiedFiles)
cacheKey = await generateCacheKey(targetScan, modifiedFiles)
}
if (cacheKey) {
try {
Expand All @@ -99,14 +97,12 @@ async function runAnalysis() {
break
}
}
if (enableIacRunning) {
const iacDir = path.join(resultsPath, 'iac')
for (const name of possibleNames) {
const existing = path.join(iacDir, `iac-${name}.json`)
if (existsSync(existing) && name !== targetScan) {
renameSync(existing, path.join(iacDir, `iac-${targetScan}.json`))
break
}
const iacDir = path.join(resultsPath, 'iac')
for (const name of possibleNames) {
const existing = path.join(iacDir, `iac-${name}.json`)
if (existsSync(existing) && name !== targetScan) {
renameSync(existing, path.join(iacDir, `iac-${targetScan}.json`))
break
}
}
}
Expand All @@ -128,14 +124,12 @@ async function runAnalysis() {
}

// Upload IAC JSON from the returned results path
if (enableIacRunning) {
const iacJsonFile = path.join(resultsPath, 'iac', `iac-${targetScan}.json`)
if (existsSync(iacJsonFile)) {
info(`Found IAC JSON file to upload: ${iacJsonFile}`)
toUpload.push(iacJsonFile)
} else {
info(`IAC JSON file not found at: ${iacJsonFile}`)
}
const iacJsonFile = path.join(resultsPath, 'iac', `iac-${targetScan}.json`)
if (existsSync(iacJsonFile)) {
info(`Found IAC JSON file to upload: ${iacJsonFile}`)
toUpload.push(iacJsonFile)
} else {
info(`IAC JSON file not found at: ${iacJsonFile}`)
}

const artifactName = 'results-' + target
Expand All @@ -145,8 +139,6 @@ async function runAnalysis() {
}

async function displayResults() {
const enableIacRunning = true

info('Displaying results')

// Download artifacts from previous jobs
Expand All @@ -155,21 +147,18 @@ 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)
await runCodesec('compare', iacAvailable, resultsPath)

// Read comparison output - check all possible outputs
const outputs = [
Expand Down
7 changes: 1 addition & 6 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ function getBooleanInput(name: string) {
return getInput(name).toLowerCase() === 'true'
}

export function debug() {
return getBooleanInput('debug') || isDebug()
}

export function getActionRef(): string {
return getOptionalEnvVariable('LACEWORK_ACTION_REF', 'unknown')
}
Expand Down Expand Up @@ -327,14 +323,13 @@ export function readMarkdownFile(filePath: string): string {
}

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

try {
await runCodesec('scan', runIac, reportsDir, scanTarget, modifiedFiles, true)
await runCodesec('scan', true, reportsDir, scanTarget, modifiedFiles, true)
} catch (e) {
info(`Cache key generation failed: ${(e as Error).message}`)
return undefined
Expand Down
21 changes: 0 additions & 21 deletions test/util.test.ts

This file was deleted.

1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"strict": true,
"skipLibCheck": true,
"sourceMap": true,
"rootDir": ".",
"outDir": "dist"
}
}
Loading