Skip to content
Merged
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
52 changes: 5 additions & 47 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
import { error, getInput, info, setOutput, warning } from '@actions/core'
import { appendFileSync, existsSync, readFileSync } from 'fs'
import { error, getInput, info, setOutput } from '@actions/core'
import { existsSync, readFileSync } from 'fs'
import {
downloadArtifact,
postCommentIfInPr,
resolveExistingCommentIfFound,
uploadArtifact,
} from './actions'
import {
callLaceworkCli,
debug,
generateUILink,
getActionRef,
getMsSinceStart,
getOptionalEnvVariable,
getRequiredEnvVariable,
getRunUrl,
telemetryCollector,
} from './util'
import { callLaceworkCli, debug, generateUILink, getOptionalEnvVariable } from './util'

import path from 'path'

Expand All @@ -41,17 +31,7 @@ async function runAnalysis() {
const toUpload: string[] = []

// command to print both sarif and lwjson formats
var args = [
'sca',
'scan',
'.',
'--formats',
'sarif',
'--output',
sarifReportPath,
'--deployment',
'ci',
]
var args = ['scan', '.', '--formats', 'sarif', '--output', sarifReportPath, '--deployment', 'ci']
if (target === 'push') {
args.push('--save-results')
}
Expand All @@ -64,14 +44,11 @@ async function runAnalysis() {
const uploadStart = Date.now()

await uploadArtifact(getArtifactName(target), ...toUpload)

telemetryCollector.addField('duration.upload-artifacts', (Date.now() - uploadStart).toString())
setOutput(`${target}-completed`, true)
}

export async function compareResults(oldReport: string, newReport: string): Promise<string> {
const args = [
'sca',
'compare',
'--old',
oldReport,
Expand Down Expand Up @@ -101,10 +78,6 @@ async function displayResults() {
const downloadStart = Date.now()
const artifactOld = await downloadArtifact(getArtifactName('old'))
const artifactNew = await downloadArtifact(getArtifactName('new'))
telemetryCollector.addField(
'duration.download-artifacts',
(Date.now() - downloadStart).toString()
)
const sarifFileOld = path.join(artifactOld, sarifReportPath)
const sarifFileNew = path.join(artifactNew, sarifReportPath)

Expand All @@ -129,7 +102,6 @@ async function displayResults() {
} else {
await resolveExistingCommentIfFound()
}
telemetryCollector.addField('duration.comment', (Date.now() - commentStart).toString())
setOutput(`display-completed`, true)
}

Expand All @@ -142,29 +114,15 @@ function getArtifactName(target: string): string {
}

async function main() {
telemetryCollector.addField('duration.install', getMsSinceStart())
telemetryCollector.addField('version', getActionRef())
telemetryCollector.addField('url', getRunUrl())
telemetryCollector.addField('repository', getRequiredEnvVariable('GITHUB_REPOSITORY'))
if (getInput('target') !== '') {
telemetryCollector.addField('run-type', 'analysis')
await runAnalysis()
} else {
telemetryCollector.addField('run-type', 'display')
await displayResults()
}
}

main()
.catch((e) => {
telemetryCollector.addError('error', e)
error(e.message) // TODO: Use setFailed once we want failures to be fatal
})
.finally(async () => {
telemetryCollector.addField('metadata.integration', 'github')
telemetryCollector.addField('duration.total', getMsSinceStart())
await telemetryCollector.report().catch((err) => {
warning('Failed to report telemetry: ' + err.message)
})
appendFileSync(getRequiredEnvVariable('GITHUB_ENV'), 'LACEWORK_WROTE_TELEMETRY=true\n')
})
.finally(async () => {})
15 changes: 1 addition & 14 deletions src/post.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { info, warning } from '@actions/core'
import { context } from '@actions/github'
import { getActionsApi } from './actions'
import {
getActionRef,
getMsSinceStart,
getOptionalEnvVariable,
getRequiredEnvVariable,
getRunUrl,
telemetryCollector,
} from './util'
import { getOptionalEnvVariable, getRequiredEnvVariable } from './util'

async function main() {
if (getOptionalEnvVariable('LACEWORK_WROTE_TELEMETRY', 'false') !== 'true') {
Expand All @@ -27,12 +20,6 @@ async function main() {
}

info('Reporting unknown failure')
telemetryCollector.addField('version', getActionRef())
telemetryCollector.addField('url', getRunUrl())
telemetryCollector.addField('repository', getRequiredEnvVariable('GITHUB_REPOSITORY'))
telemetryCollector.addField('duration.total', getMsSinceStart())
telemetryCollector.addField('error', 'Unknown catastrophic error')
await telemetryCollector.report()
} else {
info('Telemetry has been reported previously')
}
Expand Down
27 changes: 0 additions & 27 deletions src/telemetry.ts

This file was deleted.

4 changes: 1 addition & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import { error, getInput, info, isDebug } from '@actions/core'
import { context } from '@actions/github'
import { spawn } from 'child_process'
import { readFileSync } from 'fs'
import { TelemetryCollector } from './telemetry'

export const telemetryCollector = new TelemetryCollector()

export function getMsSinceStart(): string {
const now = Date.now()
Expand Down Expand Up @@ -74,6 +71,7 @@ export async function callLaceworkCli(...args: string[]) {
apiKey,
'--api_secret',
apiSecret,
'sca',
...args,
]
info('Calling lacework ' + expandedArgs.join(' '))
Expand Down
Loading