Skip to content

Commit

Permalink
feat(COD-4237): add a working directory option to the action
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydubreil committed Jan 28, 2025
1 parent 8c0de50 commit 4e34426
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
6 changes: 3 additions & 3 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: 'lacework-code-security'
description: "Scan code with Lacework's Code Security offering"
author: 'Lacework'
inputs:
sources:
description: 'Sources directory to analyze'
working-directory:
description: 'Set working directory to run the analysis on'
required: false
default: '.'
target:
Expand Down Expand Up @@ -113,7 +113,7 @@ runs:
- id: run-analysis
uses: './../lacework-code-security'
with:
sources: '${{ inputs.sources }}'
working-directory: '${{ inputs.working-directory }}'
target: '${{ inputs.target }}'
debug: '${{ inputs.debug }}'
token: '${{ inputs.token || github.token }}'
Expand Down
12 changes: 7 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { error, getInput, info, setOutput, warning } from '@actions/core'
import { existsSync, appendFileSync } from 'fs'
import { appendFileSync, existsSync } from 'fs'
import {
downloadArtifact,
postCommentIfInPr,
resolveExistingCommentIfFound,
uploadArtifact,
} from './actions'
import { downloadKeys, trustedKeys } from './keys'
import { compareResults, createPRs, printResults } from './tool'
import {
autofix,
Expand All @@ -15,12 +16,11 @@ import {
getActionRef,
getMsSinceStart,
getOptionalEnvVariable,
getOrDefault,
getRequiredEnvVariable,
getRunUrl,
telemetryCollector,
getWorkingDirectory,
telemetryCollector
} from './util'
import { downloadKeys, trustedKeys } from './keys'

const scaSarifReport = 'scaReport/output.sarif'
const scaReport = 'sca.sarif'
Expand All @@ -46,11 +46,11 @@ async function runAnalysis() {
const toUpload: string[] = []

await downloadKeys()
const workingDirectory = getWorkingDirectory()
// command to print both sarif and lwjson formats
var args = [
'sca',
'scan',
'.',
'--save-results',
'-o',
scaDir,
Expand All @@ -61,7 +61,9 @@ async function runAnalysis() {
'--keyring',
trustedKeys,
'--secret',
workingDirectory,
]
args.push(getWorkingDirectory())
if (indirectDeps.toLowerCase() === 'false') {
args.push('--eval-direct-only')
}
Expand Down
7 changes: 5 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getInput, isDebug } from '@actions/core'
import { error, info } from '@actions/core'
import { error, getInput, info, isDebug } from '@actions/core'
import { spawn } from 'child_process'
import { TelemetryCollector } from './telemetry'

Expand Down Expand Up @@ -29,6 +28,10 @@ export function autofix() {
return getBooleanInput('autofix') && getInput('target') != 'old'
}

export function getWorkingDirectory() {
return getOrDefault('working-directory', '.')
}

export function getRunUrl(): string {
let result = getRequiredEnvVariable('GITHUB_SERVER_URL')
result += '/'
Expand Down

0 comments on commit 4e34426

Please sign in to comment.