Permalink
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/src/upload-sarif.ts
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Robert Brignull
Add a CLI interface to the upload-sarif action
58 lines (51 sloc)
1.77 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as core from '@actions/core'; | |
import { getActionsLogger } from './logging'; | |
import { parseRepositoryNwo } from './repository'; | |
import * as upload_lib from './upload-lib'; | |
import * as util from './util'; | |
interface UploadSarifStatusReport extends util.StatusReportBase, upload_lib.UploadStatusReport {} | |
async function sendSuccessStatusReport(startedAt: Date, uploadStats: upload_lib.UploadStatusReport) { | |
const statusReportBase = await util.createStatusReportBase('upload-sarif', 'success', startedAt); | |
const statusReport: UploadSarifStatusReport = { | |
...statusReportBase, | |
... uploadStats, | |
}; | |
await util.sendStatusReport(statusReport); | |
} | |
async function run() { | |
const startedAt = new Date(); | |
if (!await util.sendStatusReport(await util.createStatusReportBase('upload-sarif', 'starting', startedAt), true)) { | |
return; | |
} | |
try { | |
const uploadStats = await upload_lib.upload( | |
core.getInput('sarif_file'), | |
parseRepositoryNwo(util.getRequiredEnvParam('GITHUB_REPOSITORY')), | |
await util.getCommitOid(), | |
util.getRef(), | |
await util.getAnalysisKey(), | |
util.getRequiredEnvParam('GITHUB_WORKFLOW'), | |
util.getWorkflowRunID(), | |
core.getInput('checkout_path'), | |
core.getInput('matrix'), | |
core.getInput('token'), | |
util.getRequiredEnvParam('GITHUB_API_URL'), | |
'actions', | |
getActionsLogger()); | |
await sendSuccessStatusReport(startedAt, uploadStats); | |
} catch (error) { | |
core.setFailed(error.message); | |
console.log(error); | |
await util.sendStatusReport(await util.createStatusReportBase( | |
'upload-sarif', | |
'failure', | |
startedAt, | |
error.message, | |
error.stack)); | |
return; | |
} | |
} | |
run().catch(e => { | |
core.setFailed("codeql/upload-sarif action failed: " + e); | |
console.log(e); | |
}); |