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 66f227f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
uses: ./../action
with:
target: push
sources: ${{ github.workspace }}
working-directory: ${{ github.workspace }}
debug: true
- name: Check run succeeded
env:
Expand Down
8 changes: 4 additions & 4 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 @@ -80,7 +80,7 @@ runs:
shell: bash
if: ${{ inputs.debug == 'true' }}
run: |
echo "LW_LOG=debug" >> $GITHUB_ENV
echo "LW_LOG=debug" >> $GITHUB_ENV
- if: steps.cache.outputs.cache-hit != 'true'
shell: bash
run: |
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
10 changes: 6 additions & 4 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,
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 66f227f

Please sign in to comment.