Skip to content

Commit 4e34426

Browse files
committed
feat(COD-4237): add a working directory option to the action
1 parent 8c0de50 commit 4e34426

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

action.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: 'lacework-code-security'
22
description: "Scan code with Lacework's Code Security offering"
33
author: 'Lacework'
44
inputs:
5-
sources:
6-
description: 'Sources directory to analyze'
5+
working-directory:
6+
description: 'Set working directory to run the analysis on'
77
required: false
88
default: '.'
99
target:
@@ -113,7 +113,7 @@ runs:
113113
- id: run-analysis
114114
uses: './../lacework-code-security'
115115
with:
116-
sources: '${{ inputs.sources }}'
116+
working-directory: '${{ inputs.working-directory }}'
117117
target: '${{ inputs.target }}'
118118
debug: '${{ inputs.debug }}'
119119
token: '${{ inputs.token || github.token }}'

src/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { error, getInput, info, setOutput, warning } from '@actions/core'
2-
import { existsSync, appendFileSync } from 'fs'
2+
import { appendFileSync, existsSync } from 'fs'
33
import {
44
downloadArtifact,
55
postCommentIfInPr,
66
resolveExistingCommentIfFound,
77
uploadArtifact,
88
} from './actions'
9+
import { downloadKeys, trustedKeys } from './keys'
910
import { compareResults, createPRs, printResults } from './tool'
1011
import {
1112
autofix,
@@ -15,12 +16,11 @@ import {
1516
getActionRef,
1617
getMsSinceStart,
1718
getOptionalEnvVariable,
18-
getOrDefault,
1919
getRequiredEnvVariable,
2020
getRunUrl,
21-
telemetryCollector,
21+
getWorkingDirectory,
22+
telemetryCollector
2223
} from './util'
23-
import { downloadKeys, trustedKeys } from './keys'
2424

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

4848
await downloadKeys()
49+
const workingDirectory = getWorkingDirectory()
4950
// command to print both sarif and lwjson formats
5051
var args = [
5152
'sca',
5253
'scan',
53-
'.',
5454
'--save-results',
5555
'-o',
5656
scaDir,
@@ -61,7 +61,9 @@ async function runAnalysis() {
6161
'--keyring',
6262
trustedKeys,
6363
'--secret',
64+
workingDirectory,
6465
]
66+
args.push(getWorkingDirectory())
6567
if (indirectDeps.toLowerCase() === 'false') {
6668
args.push('--eval-direct-only')
6769
}

src/util.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { getInput, isDebug } from '@actions/core'
2-
import { error, info } from '@actions/core'
1+
import { error, getInput, info, isDebug } from '@actions/core'
32
import { spawn } from 'child_process'
43
import { TelemetryCollector } from './telemetry'
54

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

31+
export function getWorkingDirectory() {
32+
return getOrDefault('working-directory', '.')
33+
}
34+
3235
export function getRunUrl(): string {
3336
let result = getRequiredEnvVariable('GITHUB_SERVER_URL')
3437
result += '/'

0 commit comments

Comments
 (0)