Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(COD-4237): add a working directory option to the action #215

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
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
Loading