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

SIGINT-864: Support async mode #244

Merged
merged 5 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 6 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ inputs:
polaris_assessment_mode:
description: 'The test mode type of this scan'
required: false
project_directory:
description: 'The project source directory. Defaults to repository root directory. Set this to specify a custom folder that is other than repository root'
required: false
project_source_archive:
description: 'The zipped source file path. It overrides the project directory setting'
required: false
Expand Down Expand Up @@ -215,6 +212,12 @@ inputs:
blackduck_execution_path:
description: 'Black Duck execution path'
required: false
project_directory:
description: 'The project source directory. Defaults to repository root directory. Set this to specify a custom folder that is other than repository root'
required: false
wait_for_scan:
description: 'It specifies whether the workflow should wait for the analysis to complete or not'
required: false
github_token:
description: 'Github token to be used for git related rest operation'
required: false
Expand Down
163 changes: 89 additions & 74 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/application-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export const PROJECT_SOURCE_ARCHIVE_KEY = 'project_source_archive'
export const PROJECT_SOURCE_PRESERVESYMLINKS_KEY = 'project_source_preserveSymLinks'
export const PROJECT_SOURCE_EXCLUDES_KEY = 'project_source_excludes'
export const PROJECT_DIRECTORY_KEY = 'project_directory'
export const WAIT_FOR_SCAN_KEY = 'wait_for_scan'

// Blackduck
export const BLACKDUCK_URL_KEY = 'blackduck_url'
Expand Down
3 changes: 3 additions & 0 deletions src/synopsys-action/input-data/async-mode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface AsyncMode {
waitForScan?: boolean
}
3 changes: 2 additions & 1 deletion src/synopsys-action/input-data/blackduck.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Reports} from './reports'
import {AsyncMode} from './async-mode'

export enum BLACKDUCK_SCAN_FAILURE_SEVERITIES {
ALL = 'ALL',
Expand All @@ -19,7 +20,7 @@ export interface Blackduck {
network?: NetworkAirGap
}

export interface BlackduckData extends BlackDuckArbitrary {
export interface BlackduckData extends BlackDuckArbitrary, AsyncMode {
url: string
token: string
install?: {directory: string}
Expand Down
3 changes: 2 additions & 1 deletion src/synopsys-action/input-data/coverity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {GithubData} from './github'
import {AsyncMode} from './async-mode'

export interface Coverity {
coverity: CoverityConnect
Expand All @@ -17,7 +18,7 @@ export interface AutomationData {
prcomment?: boolean
}

export interface CoverityConnect extends CoverityArbitrary {
export interface CoverityConnect extends CoverityArbitrary, AsyncMode {
connect: CoverityData
install?: {directory: string}
automation?: AutomationData
Expand Down
3 changes: 2 additions & 1 deletion src/synopsys-action/input-data/polaris.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {BlackDuckArbitrary} from './blackduck'
import {CoverityArbitrary} from './coverity'
import {GithubData} from './github'
import {Reports} from './reports'
import {AsyncMode} from './async-mode'

export interface Polaris {
polaris: PolarisData
Expand All @@ -11,7 +12,7 @@ export interface Polaris {
blackduck?: BlackDuckArbitrary
}

export interface PolarisData {
export interface PolarisData extends AsyncMode {
triage?: string
accesstoken: string
serverUrl: string
Expand Down
3 changes: 2 additions & 1 deletion src/synopsys-action/input-data/srm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {BlackDuckArbitrary} from './blackduck'
import {CoverityArbitrary} from './coverity'
import {AsyncMode} from './async-mode'

export interface SRM {
srm: SRMData
Expand All @@ -8,7 +9,7 @@ export interface SRM {
blackduck?: BlackduckData
}

export interface SRMData {
export interface SRMData extends AsyncMode {
url: string
apikey: string
project?: {id?: string; name?: string}
Expand Down
5 changes: 4 additions & 1 deletion src/synopsys-action/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export const ENABLE_NETWORK_AIR_GAP = getInput(constants.NETWORK_AIRGAP_KEY)?.tr
export const BRIDGE_DOWNLOAD_URL = getInput(constants.BRIDGE_DOWNLOAD_URL_KEY)?.trim() || getInput(constants.SYNOPSYS_BRIDGE_DOWNLOAD_URL_KEY)?.trim() || ''
export const BRIDGE_DOWNLOAD_VERSION = getInput(constants.BRIDGE_DOWNLOAD_VERSION_KEY)?.trim() || getInput(constants.SYNOPSYS_BRIDGE_DOWNLOAD_VERSION_KEY)?.trim() || ''

// Common inputs for all products
export const PROJECT_DIRECTORY = getInput(constants.PROJECT_DIRECTORY_KEY)?.trim() || ''
export const WAIT_FOR_SCAN = getInput(constants.WAIT_FOR_SCAN_KEY)?.trim() || ''

// Srm related inputs
export const SRM_URL = getInput(constants.SRM_URL_KEY)?.trim() || ''
export const SRM_API_KEY = getInput(constants.SRM_API_KEY)?.trim() || ''
Expand Down Expand Up @@ -38,7 +42,6 @@ export const POLARIS_REPORTS_SARIF_GROUP_SCA_ISSUES = getInput(constants.POLARIS
export const POLARIS_REPORTS_SARIF_ISSUE_TYPES = getInput(constants.POLARIS_REPORTS_SARIF_ISSUE_TYPES_KEY)?.trim() || ''
export const POLARIS_UPLOAD_SARIF_REPORT = getInput(constants.POLARIS_UPLOAD_SARIF_REPORT_KEY)?.trim() || ''
export const POLARIS_ASSESSMENT_MODE = getInput(constants.POLARIS_ASSESSMENT_MODE_KEY)?.trim() || ''
export const PROJECT_DIRECTORY = getInput(constants.PROJECT_DIRECTORY_KEY)?.trim() || ''
export const PROJECT_SOURCE_ARCHIVE = getInput(constants.PROJECT_SOURCE_ARCHIVE_KEY)?.trim() || ''
export const PROJECT_SOURCE_PRESERVESYMLINKS = getInput(constants.PROJECT_SOURCE_PRESERVESYMLINKS_KEY)?.trim() || ''
export const PROJECT_SOURCE_EXCLUDES = getInput(constants.PROJECT_SOURCE_EXCLUDES_KEY)?.trim() || ''
Expand Down
16 changes: 16 additions & 0 deletions src/synopsys-action/tools-parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ export class SynopsysToolsParameter {
}
}

if (isBoolean(inputs.WAIT_FOR_SCAN)) {
polData.data.polaris.waitForScan = parseToBoolean(inputs.WAIT_FOR_SCAN)
}

if (inputs.PROJECT_DIRECTORY || inputs.PROJECT_SOURCE_ARCHIVE || inputs.PROJECT_SOURCE_EXCLUDES || inputs.PROJECT_SOURCE_PRESERVESYMLINKS) {
polData.data.project = {}

Expand Down Expand Up @@ -263,6 +267,10 @@ export class SynopsysToolsParameter {
covData.data.coverity.connect.policy = {view: inputs.COVERITY_POLICY_VIEW}
}

if (isBoolean(inputs.WAIT_FOR_SCAN)) {
covData.data.coverity.waitForScan = parseToBoolean(inputs.WAIT_FOR_SCAN)
}

if (inputs.COVERITY_REPOSITORY_NAME || inputs.COVERITY_BRANCH_NAME || inputs.PROJECT_DIRECTORY) {
covData.data.project = {
...(inputs.COVERITY_REPOSITORY_NAME && {
Expand Down Expand Up @@ -374,6 +382,10 @@ export class SynopsysToolsParameter {
}
}

if (isBoolean(inputs.WAIT_FOR_SCAN)) {
blackduckData.data.blackduck.waitForScan = parseToBoolean(inputs.WAIT_FOR_SCAN)
}

if (inputs.PROJECT_DIRECTORY) {
blackduckData.data.project = {
directory: inputs.PROJECT_DIRECTORY
Expand Down Expand Up @@ -508,6 +520,10 @@ export class SynopsysToolsParameter {
}
}

if (isBoolean(inputs.WAIT_FOR_SCAN)) {
srmData.data.srm.waitForScan = parseToBoolean(inputs.WAIT_FOR_SCAN)
}

if (inputs.PROJECT_DIRECTORY) {
srmData.data.project = {
directory: inputs.PROJECT_DIRECTORY
Expand Down
77 changes: 77 additions & 0 deletions test/unit/synopsys-action/tools-parameter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,28 @@ test('Test getFormattedCommandForBlackduck with sarif params', () => {
expect(resp).toContain('--stage blackduck')
})

it('should pass polaris fields and wait for scan field to bridge', () => {
Object.defineProperty(inputs, 'POLARIS_SERVER_URL', {value: 'server_url'})
Object.defineProperty(inputs, 'POLARIS_ACCESS_TOKEN', {value: 'access_token'})
Object.defineProperty(inputs, 'POLARIS_APPLICATION_NAME', {value: 'POLARIS_APPLICATION_NAME'})
Object.defineProperty(inputs, 'POLARIS_PROJECT_NAME', {value: 'POLARIS_PROJECT_NAME'})
Object.defineProperty(inputs, 'POLARIS_ASSESSMENT_TYPES', {value: 'SCA, SAST'})
Object.defineProperty(inputs, 'WAIT_FOR_SCAN', {value: true})
const stp: SynopsysToolsParameter = new SynopsysToolsParameter(tempPath)
const resp = stp.getFormattedCommandForPolaris('synopsys-action')

const jsonString = fs.readFileSync(tempPath.concat(polaris_input_file), 'utf-8')
const jsonData = JSON.parse(jsonString)
expect(resp).not.toBeNull()
expect(resp).toContain('--stage polaris')
expect(jsonData.data.polaris.serverUrl).toContain('server_url')
expect(jsonData.data.polaris.accesstoken).toContain('access_token')
expect(jsonData.data.polaris.application.name).toContain('POLARIS_APPLICATION_NAME')
expect(jsonData.data.polaris.project.name).toContain('POLARIS_PROJECT_NAME')
expect(jsonData.data.polaris.assessment.types).toEqual(['SCA', 'SAST'])
expect(jsonData.data.polaris.waitForScan).toBe(true)
})

it('should pass polaris source upload fields to bridge', () => {
Object.defineProperty(inputs, 'POLARIS_SERVER_URL', {value: 'server_url'})
Object.defineProperty(inputs, 'POLARIS_ACCESS_TOKEN', {value: 'access_token'})
Expand Down Expand Up @@ -794,6 +816,23 @@ it('should pass polaris SCA and SAST arbitrary fields to bridge', () => {
expect(jsonData.data.blackduck.args).toBe('BLACKDUCK_ARGS')
})

it('should pass black duck fields and wait for scan field to bridge', () => {
Object.defineProperty(inputs, 'BLACKDUCK_URL', {value: 'BLACKDUCK_URL'})
Object.defineProperty(inputs, 'BLACKDUCK_API_TOKEN', {value: 'BLACKDUCK_API_TOKEN'})
Object.defineProperty(inputs, 'WAIT_FOR_SCAN', {value: true})

const stp: SynopsysToolsParameter = new SynopsysToolsParameter(tempPath)
const resp = stp.getFormattedCommandForBlackduck()

const jsonString = fs.readFileSync(tempPath.concat(blackduck_input_file), 'utf-8')
const jsonData = JSON.parse(jsonString)
expect(resp).not.toBeNull()
expect(resp).toContain('--stage blackduck')
expect(jsonData.data.blackduck.url).toBe('BLACKDUCK_URL')
expect(jsonData.data.blackduck.token).toBe('BLACKDUCK_API_TOKEN')
expect(jsonData.data.blackduck.waitForScan).toBe(true)
})

it('should pass black duck fields and project directory field to bridge', () => {
Object.defineProperty(inputs, 'BLACKDUCK_URL', {value: 'BLACKDUCK_URL'})
Object.defineProperty(inputs, 'BLACKDUCK_API_TOKEN', {value: 'BLACKDUCK_API_TOKEN'})
Expand Down Expand Up @@ -832,6 +871,25 @@ it('should pass blackduck arbitrary fields to bridge', () => {
expect(jsonData.data.blackduck.args).toBe('BLACKDUCK_ARGS')
})

it('should pass coverity fields and wait for scan field to bridge', () => {
Object.defineProperty(inputs, 'COVERITY_URL', {value: 'COVERITY_URL'})
Object.defineProperty(inputs, 'COVERITY_USER', {value: 'COVERITY_USER'})
Object.defineProperty(inputs, 'COVERITY_PASSPHRASE', {value: 'COVERITY_PASSPHRASE'})
Object.defineProperty(inputs, 'WAIT_FOR_SCAN', {value: true})

const stp: SynopsysToolsParameter = new SynopsysToolsParameter(tempPath)
const resp = stp.getFormattedCommandForCoverity('synopsys-action')

const jsonString = fs.readFileSync(tempPath.concat(coverity_input_file), 'utf-8')
const jsonData = JSON.parse(jsonString)
expect(resp).not.toBeNull()
expect(resp).toContain('--stage connect')
expect(jsonData.data.coverity.connect.url).toBe('COVERITY_URL')
expect(jsonData.data.coverity.connect.user.name).toBe('COVERITY_USER')
expect(jsonData.data.coverity.connect.user.password).toBe('COVERITY_PASSPHRASE')
expect(jsonData.data.coverity.waitForScan).toBe(true)
})

it('should pass coverity fields and project directory field to bridge', () => {
Object.defineProperty(inputs, 'COVERITY_URL', {value: 'COVERITY_URL'})
Object.defineProperty(inputs, 'COVERITY_USER', {value: 'COVERITY_USER'})
Expand Down Expand Up @@ -1150,6 +1208,25 @@ it('should pass SRM SCA and SAST arbitrary fields to bridge', () => {
expect(jsonData.data.blackduck.args).toBe('BLACKDUCK_ARGS')
})

it('should pass SRM fields and wait for scan field to bridge', () => {
Object.defineProperty(inputs, 'SRM_URL', {value: 'srm_url'})
Object.defineProperty(inputs, 'SRM_API_KEY', {value: 'api_key'})
Object.defineProperty(inputs, 'SRM_ASSESSMENT_TYPES', {value: 'SCA,SAST'})
Object.defineProperty(inputs, 'WAIT_FOR_SCAN', {value: true})

const stp: SynopsysToolsParameter = new SynopsysToolsParameter(tempPath)
const resp = stp.getFormattedCommandForSRM('synopsys-action')

const jsonString = fs.readFileSync(tempPath.concat(srm_input_file), 'utf-8')
const jsonData = JSON.parse(jsonString)
expect(resp).not.toBeNull()
expect(resp).toContain('--stage srm')
expect(jsonData.data.srm.url).toContain('srm_url')
expect(jsonData.data.srm.apikey).toContain('api_key')
expect(jsonData.data.srm.assessment.types).toEqual(['SCA', 'SAST'])
expect(jsonData.data.srm.waitForScan).toBe(true)
})

it('should pass SRM fields and project directory field to bridge', () => {
Object.defineProperty(inputs, 'SRM_URL', {value: 'srm_url'})
Object.defineProperty(inputs, 'SRM_API_KEY', {value: 'api_key'})
Expand Down
Loading