2020-08-11 12:43:27 +01:00
"use strict" ;
2021-07-27 17:59:59 +01:00
var _ _createBinding = ( this && this . _ _createBinding ) || ( Object . create ? ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
Object . defineProperty ( o , k2 , { enumerable : true , get : function ( ) { return m [ k ] ; } } ) ;
} ) : ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
o [ k2 ] = m [ k ] ;
} ) ) ;
var _ _setModuleDefault = ( this && this . _ _setModuleDefault ) || ( Object . create ? ( function ( o , v ) {
Object . defineProperty ( o , "default" , { enumerable : true , value : v } ) ;
} ) : function ( o , v ) {
o [ "default" ] = v ;
} ) ;
2020-08-11 12:43:27 +01:00
var _ _importStar = ( this && this . _ _importStar ) || function ( mod ) {
if ( mod && mod . _ _esModule ) return mod ;
var result = { } ;
2021-07-27 17:59:59 +01:00
if ( mod != null ) for ( var k in mod ) if ( k !== "default" && Object . prototype . hasOwnProperty . call ( mod , k ) ) _ _createBinding ( result , mod , k ) ;
_ _setModuleDefault ( result , mod ) ;
2020-08-11 12:43:27 +01:00
return result ;
} ;
2021-12-08 12:00:54 -08:00
var _ _importDefault = ( this && this . _ _importDefault ) || function ( mod ) {
return ( mod && mod . _ _esModule ) ? mod : { "default" : mod } ;
} ;
2020-08-11 12:43:27 +01:00
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
2020-08-25 16:19:15 +01:00
const fs = _ _importStar ( require ( "fs" ) ) ;
2020-08-11 12:43:27 +01:00
const path = _ _importStar ( require ( "path" ) ) ;
2020-10-01 11:03:30 +01:00
const commander _1 = require ( "commander" ) ;
2021-12-08 12:00:54 -08:00
const del _1 = _ _importDefault ( require ( "del" ) ) ;
2020-08-25 16:19:15 +01:00
const analyze _1 = require ( "./analyze" ) ;
const autobuild _1 = require ( "./autobuild" ) ;
const codeql _1 = require ( "./codeql" ) ;
2020-08-27 14:04:09 +01:00
const config _utils _1 = require ( "./config-utils" ) ;
2021-12-15 13:34:29 +00:00
const feature _flags _1 = require ( "./feature-flags" ) ;
2020-08-25 16:19:15 +01:00
const init _1 = require ( "./init" ) ;
const languages _1 = require ( "./languages" ) ;
2020-08-11 12:43:27 +01:00
const logging _1 = require ( "./logging" ) ;
const repository _1 = require ( "./repository" ) ;
const upload _lib = _ _importStar ( require ( "./upload-lib" ) ) ;
2020-09-01 14:13:10 +01:00
const util _1 = require ( "./util" ) ;
2021-05-31 09:35:13 -07:00
// eslint-disable-next-line import/no-commonjs
const pkg = require ( "../package.json" ) ;
2020-08-11 12:43:27 +01:00
const program = new commander _1 . Command ( ) ;
2021-05-31 11:14:03 -07:00
program . version ( pkg . version ) . hook ( "preAction" , ( ) => {
2021-09-10 13:53:13 -07:00
( 0 , util _1 . initializeEnvironment ) ( util _1 . Mode . runner , pkg . version ) ;
2021-05-31 11:14:03 -07:00
} ) ;
2020-08-25 16:19:15 +01:00
function getTempDir ( userInput ) {
2020-09-14 10:44:43 +01:00
const tempDir = path . join ( userInput || process . cwd ( ) , "codeql-runner" ) ;
2020-08-25 16:19:15 +01:00
if ( ! fs . existsSync ( tempDir ) ) {
fs . mkdirSync ( tempDir , { recursive : true } ) ;
}
return tempDir ;
}
2020-09-14 10:44:43 +01:00
const codeqlEnvJsonFilename = "codeql-env.json" ;
2021-10-28 15:09:59 -07:00
function loadTracerEnvironment ( config ) {
const jsonEnvFile = path . join ( config . tempDir , codeqlEnvJsonFilename ) ;
return JSON . parse ( fs . readFileSync ( jsonEnvFile ) . toString ( "utf-8" ) ) ;
}
2020-08-28 17:22:26 +01:00
// Imports the environment from codeqlEnvJsonFilename if not already present
function importTracerEnvironment ( config ) {
2020-09-14 10:44:43 +01:00
if ( ! ( "ODASA_TRACER_CONFIGURATION" in process . env ) ) {
2021-10-28 15:09:59 -07:00
const env = loadTracerEnvironment ( config ) ;
2020-09-20 17:03:01 +08:00
for ( const key of Object . keys ( env ) ) {
process . env [ key ] = env [ key ] ;
}
2020-08-27 14:22:16 +01:00
}
}
2020-09-02 18:00:46 +01:00
// Allow the user to specify refs in full refs/heads/branch format
// or just the short branch name and prepend "refs/heads/" to it.
function parseRef ( userInput ) {
2020-09-14 10:44:43 +01:00
if ( userInput . startsWith ( "refs/" ) ) {
2020-09-02 18:00:46 +01:00
return userInput ;
}
else {
2020-09-14 10:44:43 +01:00
return ` refs/heads/ ${ userInput } ` ;
2020-09-02 18:00:46 +01:00
}
}
2020-09-07 13:36:47 +01:00
// Parses the --trace-process-name arg from process.argv, or returns undefined
function parseTraceProcessName ( ) {
for ( let i = 0 ; i < process . argv . length - 1 ; i ++ ) {
2020-09-14 10:44:43 +01:00
if ( process . argv [ i ] === "--trace-process-name" ) {
2020-09-07 13:36:47 +01:00
return process . argv [ i + 1 ] ;
}
}
return undefined ;
}
// Parses the --trace-process-level arg from process.argv, or returns undefined
function parseTraceProcessLevel ( ) {
for ( let i = 0 ; i < process . argv . length - 1 ; i ++ ) {
2020-09-14 10:44:43 +01:00
if ( process . argv [ i ] === "--trace-process-level" ) {
2020-09-07 13:36:47 +01:00
const v = parseInt ( process . argv [ i + 1 ] , 10 ) ;
return isNaN ( v ) ? undefined : v ;
}
}
return undefined ;
}
2020-08-25 16:19:15 +01:00
program
2020-09-14 10:44:43 +01:00
. command ( "init" )
. description ( "Initializes CodeQL" )
. requiredOption ( "--repository <repository>" , "Repository name. (Required)" )
. requiredOption ( "--github-url <url>" , "URL of GitHub instance. (Required)" )
2021-02-12 14:31:38 -08:00
. option ( "--github-auth <auth>" , "GitHub Apps token or personal access token. This option is insecure and deprecated, please use `--github-auth-stdin` instead." )
. option ( "--github-auth-stdin" , "Read GitHub Apps token or personal access token from stdin." )
2020-09-14 10:44:43 +01:00
. option ( "--languages <languages>" , "Comma-separated list of languages to analyze. Otherwise detects and analyzes all supported languages from the repo." )
. option ( "--queries <queries>" , "Comma-separated list of additional queries to run. This overrides the same setting in a configuration file." )
2021-06-24 14:50:34 -07:00
. option ( "--packs <packs>" , ` [Experimental] Comma-separated list of packs to run. Reference a pack in the format scope/name[@version]. If version is not
2021-06-23 15:41:52 -07:00
specified, then the latest version of the pack is used. By default, this overrides the same setting in a
configuration file; prefix with "+" to use both sets of packs.
2021-06-24 14:50:34 -07:00
This option is only available in single-language analyses. To use packs in multi-language
analyses, you must specify packs in the codeql-config.yml file. ` )
2020-09-14 10:44:43 +01:00
. option ( "--config-file <file>" , "Path to config file." )
. option ( "--codeql-path <path>" , "Path to a copy of the CodeQL CLI executable to use. Otherwise downloads a copy." )
. option ( "--temp-dir <dir>" , 'Directory to use for temporary files. Default is "./codeql-runner".' )
. option ( "--tools-dir <dir>" , "Directory to use for CodeQL tools and other files to store between runs. Default is a subdirectory of the home directory." )
. option ( "--checkout-path <path>" , "Checkout path. Default is the current working directory." )
. option ( "--debug" , "Print more verbose output" , false )
2021-04-16 11:54:18 -07:00
. option ( "--trace-process-name <string>" , "(Advanced, windows-only) Inject a windows tracer of this process into a process with the given process name." )
. option ( "--trace-process-level <number>" , "(Advanced, windows-only) Inject a windows tracer of this process into a parent process <number> levels up." )
2021-10-28 15:09:59 -07:00
. option ( "--ram <number>" , "The amount of memory in MB that can be used by CodeQL extractors. " +
"By default, CodeQL extractors will use most of the memory available in the system. " +
'This input also sets the amount of memory that can later be used by the "analyze" command.' )
. option ( "--threads <number>" , "The number of threads that can be used by CodeQL extractors. " +
"By default, CodeQL extractors will use all the hardware threads available in the system. " +
'This input also sets the number of threads that can later be used by the "analyze" command.' )
2020-08-25 16:19:15 +01:00
. action ( async ( cmd ) => {
2021-09-10 13:53:13 -07:00
const logger = ( 0 , logging _1 . getRunnerLogger ) ( cmd . debug ) ;
2020-08-25 16:19:15 +01:00
try {
const tempDir = getTempDir ( cmd . tempDir ) ;
2021-06-29 15:16:32 -05:00
const checkoutPath = cmd . checkoutPath || process . cwd ( ) ;
2020-08-25 16:19:15 +01:00
// Wipe the temp dir
2020-08-27 16:45:41 +01:00
logger . info ( ` Cleaning temp directory ${ tempDir } ` ) ;
2021-12-08 12:00:54 -08:00
await ( 0 , del _1 . default ) ( tempDir , { force : true } ) ;
2020-08-25 16:19:15 +01:00
fs . mkdirSync ( tempDir , { recursive : true } ) ;
2021-09-10 13:53:13 -07:00
const auth = await ( 0 , util _1 . getGitHubAuth ) ( logger , cmd . githubAuth , cmd . githubAuthStdin ) ;
2020-11-24 11:20:13 +00:00
const apiDetails = {
2021-02-12 14:31:38 -08:00
auth ,
2021-02-17 10:04:02 +00:00
externalRepoAuth : auth ,
2021-09-10 13:53:13 -07:00
url : ( 0 , util _1 . parseGitHubUrl ) ( cmd . githubUrl ) ,
2022-08-10 21:11:50 +01:00
apiURL : undefined ,
2020-11-24 11:20:13 +00:00
} ;
2021-09-10 13:53:13 -07:00
const gitHubVersion = await ( 0 , util _1 . getGitHubVersion ) ( apiDetails ) ;
( 0 , util _1 . checkGitHubVersionInRange ) ( gitHubVersion , logger , util _1 . Mode . runner ) ;
2021-10-28 15:09:59 -07:00
// Limit RAM and threads for extractors. When running extractors, the CodeQL CLI obeys the
// CODEQL_RAM and CODEQL_THREADS environment variables to decide how much RAM and how many
// threads it would ask extractors to use. See help text for the "--ram" and "--threads"
// options at https://codeql.github.com/docs/codeql-cli/manual/database-trace-command/
// for details.
process . env [ "CODEQL_RAM" ] = ( 0 , util _1 . getMemoryFlagValue ) ( cmd . ram ) . toString ( ) ;
process . env [ "CODEQL_THREADS" ] = ( 0 , util _1 . getThreadsFlagValue ) ( cmd . threads , logger ) . toString ( ) ;
2020-08-25 16:19:15 +01:00
let codeql ;
if ( cmd . codeqlPath !== undefined ) {
2021-09-10 13:53:13 -07:00
codeql = await ( 0 , codeql _1 . getCodeQL ) ( cmd . codeqlPath ) ;
2020-08-25 16:19:15 +01:00
}
else {
2022-08-16 13:58:59 +01:00
codeql = ( await ( 0 , init _1 . initCodeQL ) ( undefined , apiDetails , tempDir , gitHubVersion . type , ( 0 , feature _flags _1 . createFeatureFlags ) ( [ ] ) , logger ) ) . codeql ;
2020-08-25 16:19:15 +01:00
}
2021-09-15 14:49:20 +01:00
await ( 0 , util _1 . enrichEnvironment ) ( util _1 . Mode . runner , codeql ) ;
2021-07-01 11:38:14 +02:00
const workspacePath = checkoutPath ;
2022-09-01 16:07:26 -07:00
const config = await ( 0 , init _1 . initConfig ) ( cmd . languages , cmd . queries , cmd . packs , undefined , // we won't support registries in the runner
cmd . configFile , undefined , false , false , "" , "" , ( 0 , repository _1 . parseRepositoryNwo ) ( cmd . repository ) , tempDir , codeql , workspacePath , gitHubVersion , apiDetails , ( 0 , feature _flags _1 . createFeatureFlags ) ( [ ] ) , logger ) ;
2021-07-01 11:38:14 +02:00
const sourceRoot = checkoutPath ;
2022-08-24 11:34:00 +01:00
const tracerConfig = await ( 0 , init _1 . runInit ) ( codeql , config , sourceRoot , parseTraceProcessName ( ) , parseTraceProcessLevel ( ) , ( 0 , feature _flags _1 . createFeatureFlags ) ( [ ] ) , logger ) ;
2020-08-27 16:34:09 +01:00
if ( tracerConfig === undefined ) {
return ;
}
2021-09-15 14:49:20 +01:00
if ( process . platform === "win32" &&
! ( await ( 0 , util _1 . codeQlVersionAbove ) ( codeql , codeql _1 . CODEQL _VERSION _NEW _TRACING ) ) ) {
2021-09-10 13:53:13 -07:00
await ( 0 , init _1 . injectWindowsTracer ) ( parseTraceProcessName ( ) , parseTraceProcessLevel ( ) , config , codeql , tracerConfig ) ;
2020-09-07 13:36:47 +01:00
}
2020-11-20 11:35:59 +01:00
// Always output a json file of the env that can be consumed programmatically
2020-08-28 17:22:26 +01:00
const jsonEnvFile = path . join ( config . tempDir , codeqlEnvJsonFilename ) ;
fs . writeFileSync ( jsonEnvFile , JSON . stringify ( tracerConfig . env ) ) ;
2020-09-14 10:44:43 +01:00
if ( process . platform === "win32" ) {
const batEnvFile = path . join ( config . tempDir , "codeql-env.bat" ) ;
2020-08-27 16:34:09 +01:00
const batEnvFileContents = Object . entries ( tracerConfig . env )
. map ( ( [ key , value ] ) => ` Set ${ key } = ${ value } ` )
2020-09-14 10:44:43 +01:00
. join ( "\n" ) ;
2020-08-27 16:34:09 +01:00
fs . writeFileSync ( batEnvFile , batEnvFileContents ) ;
2020-09-14 10:44:43 +01:00
const powershellEnvFile = path . join ( config . tempDir , "codeql-env.sh" ) ;
2020-08-27 16:34:09 +01:00
const powershellEnvFileContents = Object . entries ( tracerConfig . env )
. map ( ( [ key , value ] ) => ` $ env: ${ key } =" ${ value } " ` )
2020-09-14 10:44:43 +01:00
. join ( "\n" ) ;
2020-08-27 16:34:09 +01:00
fs . writeFileSync ( powershellEnvFile , powershellEnvFileContents ) ;
2020-09-02 19:58:03 +01:00
logger . info ( ` \n CodeQL environment output to " ${ jsonEnvFile } ", " ${ batEnvFile } " and " ${ powershellEnvFile } ". ` +
2020-11-13 15:04:54 +00:00
` Please export these variables to future processes so that CodeQL can monitor the build. ` +
2020-09-02 19:58:03 +01:00
` If using cmd/batch run "call ${ batEnvFile } " ` +
2020-08-27 16:34:09 +01:00
` or if using PowerShell run "cat ${ powershellEnvFile } | Invoke-Expression". ` ) ;
}
else {
// Assume that anything that's not windows is using a unix-style shell
2020-09-14 10:44:43 +01:00
const shEnvFile = path . join ( config . tempDir , "codeql-env.sh" ) ;
2020-08-28 17:22:26 +01:00
const shEnvFileContents = Object . entries ( tracerConfig . env )
2020-08-27 16:34:09 +01:00
// Some vars contain ${LIB} that we do not want to be expanded when executing this script
2021-05-05 19:57:44 +02:00
. map ( ( [ key , value ] ) => ` export ${ key } =' ${ value . replace ( /'/g , "'\"'\"'" ) } ' ` )
2020-09-14 10:44:43 +01:00
. join ( "\n" ) ;
2020-08-28 17:22:26 +01:00
fs . writeFileSync ( shEnvFile , shEnvFileContents ) ;
logger . info ( ` \n CodeQL environment output to " ${ jsonEnvFile } " and " ${ shEnvFile } ". ` +
2020-11-13 15:04:54 +00:00
` Please export these variables to future processes so that CodeQL can monitor the build, ` +
2020-08-28 17:22:26 +01:00
` for example by running ". ${ shEnvFile } ". ` ) ;
2020-08-26 13:20:46 +01:00
}
2020-08-25 16:19:15 +01:00
}
catch ( e ) {
2020-09-14 10:44:43 +01:00
logger . error ( "Init failed" ) ;
2021-09-10 13:53:13 -07:00
logger . error ( e instanceof Error ? e : new Error ( String ( e ) ) ) ;
2020-08-25 16:19:15 +01:00
process . exitCode = 1 ;
}
} ) ;
program
2020-09-14 10:44:43 +01:00
. command ( "autobuild" )
. description ( "Attempts to automatically build code" )
. option ( "--language <language>" , "The language to build. Otherwise will detect the dominant compiled language." )
. option ( "--temp-dir <dir>" , 'Directory to use for temporary files. Default is "./codeql-runner".' )
. option ( "--debug" , "Print more verbose output" , false )
2020-08-25 16:19:15 +01:00
. action ( async ( cmd ) => {
2021-09-10 13:53:13 -07:00
const logger = ( 0 , logging _1 . getRunnerLogger ) ( cmd . debug ) ;
2020-08-25 16:19:15 +01:00
try {
2021-09-10 13:53:13 -07:00
const config = await ( 0 , config _utils _1 . getConfig ) ( getTempDir ( cmd . tempDir ) , logger ) ;
2020-08-28 09:43:25 +01:00
if ( config === undefined ) {
throw new Error ( "Config file could not be found at expected location. " +
"Was the 'init' command run with the same '--temp-dir' argument as this command." ) ;
}
2021-09-15 14:49:20 +01:00
await ( 0 , util _1 . enrichEnvironment ) ( util _1 . Mode . runner , await ( 0 , codeql _1 . getCodeQL ) ( config . codeQLCmd ) ) ;
2020-08-28 17:22:26 +01:00
importTracerEnvironment ( config ) ;
2022-09-12 17:18:39 +01:00
let languages = undefined ;
2020-08-27 14:04:09 +01:00
if ( cmd . language !== undefined ) {
2022-09-12 17:18:39 +01:00
const language = ( 0 , languages _1 . parseLanguage ) ( cmd . language ) ;
2020-08-27 14:04:09 +01:00
if ( language === undefined || ! config . languages . includes ( language ) ) {
throw new Error ( ` " ${ cmd . language } " is not a recognised language. ` +
2020-09-14 10:44:43 +01:00
` Known languages in this project are ${ config . languages . join ( ", " ) } . ` ) ;
2020-08-27 14:04:09 +01:00
}
2022-09-12 17:18:39 +01:00
languages = [ language ] ;
2020-08-27 14:04:09 +01:00
}
else {
2022-09-12 17:18:39 +01:00
languages = await ( 0 , autobuild _1 . determineAutobuildLanguages ) ( config , ( 0 , feature _flags _1 . createFeatureFlags ) ( [ ] ) , logger ) ;
2020-08-27 14:04:09 +01:00
}
2022-09-12 17:18:39 +01:00
if ( languages !== undefined ) {
for ( const language of languages ) {
await ( 0 , autobuild _1 . runAutobuild ) ( language , config , logger ) ;
}
2020-08-25 16:19:15 +01:00
}
}
catch ( e ) {
2020-09-14 10:44:43 +01:00
logger . error ( "Autobuild failed" ) ;
2021-09-10 13:53:13 -07:00
logger . error ( e instanceof Error ? e : new Error ( String ( e ) ) ) ;
2020-08-25 16:19:15 +01:00
process . exitCode = 1 ;
}
} ) ;
program
2020-09-14 10:44:43 +01:00
. command ( "analyze" )
. description ( "Finishes extracting code and runs CodeQL queries" )
. requiredOption ( "--repository <repository>" , "Repository name. (Required)" )
. requiredOption ( "--commit <commit>" , "SHA of commit that was analyzed. (Required)" )
. requiredOption ( "--ref <ref>" , "Name of ref that was analyzed. (Required)" )
. requiredOption ( "--github-url <url>" , "URL of GitHub instance. (Required)" )
2021-02-12 14:31:38 -08:00
. option ( "--github-auth <auth>" , "GitHub Apps token or personal access token. This option is insecure and deprecated, please use `--github-auth-stdin` instead." )
. option ( "--github-auth-stdin" , "Read GitHub Apps token or personal access token from stdin." )
2020-09-14 10:44:43 +01:00
. option ( "--checkout-path <path>" , "Checkout path. Default is the current working directory." )
. option ( "--no-upload" , "Do not upload results after analysis." )
. option ( "--output-dir <dir>" , "Directory to output SARIF files to. Default is in the temp directory." )
2021-10-28 15:09:59 -07:00
. option ( "--ram <ram>" , "The amount of memory in MB that can be used by CodeQL for database finalization and query execution. " +
'By default, this command will use the same amount of memory as previously set in the "init" command. ' +
'If the "init" command also does not have an explicit "ram" flag, this command will use most of the ' +
"memory available in the system." )
2020-09-14 10:44:43 +01:00
. option ( "--no-add-snippets" , "Specify whether to include code snippets in the sarif output." )
2021-10-28 15:09:59 -07:00
. option ( "--threads <threads>" , "The number of threads that can be used by CodeQL for database finalization and query execution. " +
'By default, this command will use the same number of threads as previously set in the "init" command. ' +
'If the "init" command also does not have an explicit "threads" flag, this command will use all the ' +
"hardware threads available in the system." )
2020-09-14 10:44:43 +01:00
. option ( "--temp-dir <dir>" , 'Directory to use for temporary files. Default is "./codeql-runner".' )
2021-04-29 14:59:36 +02:00
. option ( "--category <category>" , "String used by Code Scanning for matching the analyses." )
2020-09-14 10:44:43 +01:00
. option ( "--debug" , "Print more verbose output" , false )
2020-08-25 16:19:15 +01:00
. action ( async ( cmd ) => {
2021-09-10 13:53:13 -07:00
const logger = ( 0 , logging _1 . getRunnerLogger ) ( cmd . debug ) ;
2020-08-25 16:19:15 +01:00
try {
2021-09-10 13:53:13 -07:00
const config = await ( 0 , config _utils _1 . getConfig ) ( getTempDir ( cmd . tempDir ) , logger ) ;
2020-08-28 09:43:25 +01:00
if ( config === undefined ) {
throw new Error ( "Config file could not be found at expected location. " +
"Was the 'init' command run with the same '--temp-dir' argument as this command." ) ;
}
2021-09-15 14:49:20 +01:00
await ( 0 , util _1 . enrichEnvironment ) ( util _1 . Mode . runner , await ( 0 , codeql _1 . getCodeQL ) ( config . codeQLCmd ) ) ;
2021-09-10 13:53:13 -07:00
const auth = await ( 0 , util _1 . getGitHubAuth ) ( logger , cmd . githubAuth , cmd . githubAuthStdin ) ;
2020-11-24 11:20:13 +00:00
const apiDetails = {
2021-02-12 14:31:38 -08:00
auth ,
2021-09-10 13:53:13 -07:00
url : ( 0 , util _1 . parseGitHubUrl ) ( cmd . githubUrl ) ,
2022-08-10 21:11:50 +01:00
apiURL : undefined ,
2020-11-24 11:20:13 +00:00
} ;
2021-03-16 13:14:17 +00:00
const outputDir = cmd . outputDir || path . join ( config . tempDir , "codeql-sarif" ) ;
2021-10-28 15:09:59 -07:00
let initEnv = { } ;
try {
initEnv = loadTracerEnvironment ( config ) ;
}
catch ( err ) {
// The init command did not generate a tracer environment file
}
const threads = ( 0 , util _1 . getThreadsFlag ) ( cmd . threads || initEnv [ "CODEQL_THREADS" ] , logger ) ;
const memory = ( 0 , util _1 . getMemoryFlag ) ( cmd . ram || initEnv [ "CODEQL_RAM" ] ) ;
2022-06-24 10:26:12 +00:00
await ( 0 , analyze _1 . runFinalize ) ( outputDir , threads , memory , config , logger , ( 0 , feature _flags _1 . createFeatureFlags ) ( [ ] ) ) ;
2022-09-26 19:56:42 -07:00
await ( 0 , analyze _1 . runQueries ) ( outputDir , memory , ( 0 , util _1 . getAddSnippetsFlag ) ( cmd . addSnippets ) , threads , cmd . category , config , logger , ( 0 , feature _flags _1 . createFeatureFlags ) ( [ ] ) ) ;
2020-11-27 12:23:06 +00:00
if ( ! cmd . upload ) {
logger . info ( "Not uploading results" ) ;
return ;
}
2021-07-01 11:38:14 +02:00
const sourceRoot = cmd . checkoutPath || process . cwd ( ) ;
2021-09-10 13:53:13 -07:00
await upload _lib . uploadFromRunner ( outputDir , ( 0 , repository _1 . parseRepositoryNwo ) ( cmd . repository ) , cmd . commit , parseRef ( cmd . ref ) , cmd . category , sourceRoot , config . gitHubVersion , apiDetails , logger ) ;
2020-08-25 16:19:15 +01:00
}
catch ( e ) {
2020-09-14 10:44:43 +01:00
logger . error ( "Analyze failed" ) ;
2021-09-10 13:53:13 -07:00
logger . error ( e instanceof Error ? e : new Error ( String ( e ) ) ) ;
2020-08-25 16:19:15 +01:00
process . exitCode = 1 ;
}
} ) ;
2020-08-11 12:43:27 +01:00
program
2020-09-14 10:44:43 +01:00
. command ( "upload" )
. description ( "Uploads a SARIF file, or all SARIF files from a directory, to code scanning" )
. requiredOption ( "--sarif-file <file>" , "SARIF file to upload, or a directory containing multiple SARIF files. (Required)" )
. requiredOption ( "--repository <repository>" , "Repository name. (Required)" )
. requiredOption ( "--commit <commit>" , "SHA of commit that was analyzed. (Required)" )
. requiredOption ( "--ref <ref>" , "Name of ref that was analyzed. (Required)" )
. requiredOption ( "--github-url <url>" , "URL of GitHub instance. (Required)" )
2021-02-12 14:31:38 -08:00
. option ( "--github-auth <auth>" , "GitHub Apps token or personal access token. This option is insecure and deprecated, please use `--github-auth-stdin` instead." )
. option ( "--github-auth-stdin" , "Read GitHub Apps token or personal access token from stdin." )
2020-09-14 10:44:43 +01:00
. option ( "--checkout-path <path>" , "Checkout path. Default is the current working directory." )
2021-04-29 14:59:36 +02:00
. option ( "--category <category>" , "String used by Code Scanning for matching the analyses." )
2020-09-14 10:44:43 +01:00
. option ( "--debug" , "Print more verbose output" , false )
2020-08-11 12:43:27 +01:00
. action ( async ( cmd ) => {
2021-09-10 13:53:13 -07:00
const logger = ( 0 , logging _1 . getRunnerLogger ) ( cmd . debug ) ;
const auth = await ( 0 , util _1 . getGitHubAuth ) ( logger , cmd . githubAuth , cmd . githubAuthStdin ) ;
2020-11-24 11:20:13 +00:00
const apiDetails = {
2021-02-12 14:31:38 -08:00
auth ,
2021-09-10 13:53:13 -07:00
url : ( 0 , util _1 . parseGitHubUrl ) ( cmd . githubUrl ) ,
2022-08-10 21:11:50 +01:00
apiURL : undefined ,
2020-11-24 11:20:13 +00:00
} ;
2020-08-11 12:43:27 +01:00
try {
2021-09-10 13:53:13 -07:00
const gitHubVersion = await ( 0 , util _1 . getGitHubVersion ) ( apiDetails ) ;
2021-07-01 11:38:14 +02:00
const sourceRoot = cmd . checkoutPath || process . cwd ( ) ;
2021-09-10 13:53:13 -07:00
await upload _lib . uploadFromRunner ( cmd . sarifFile , ( 0 , repository _1 . parseRepositoryNwo ) ( cmd . repository ) , cmd . commit , parseRef ( cmd . ref ) , cmd . category , sourceRoot , gitHubVersion , apiDetails , logger ) ;
2020-08-11 12:43:27 +01:00
}
catch ( e ) {
2020-09-14 10:44:43 +01:00
logger . error ( "Upload failed" ) ;
2021-09-10 13:53:13 -07:00
logger . error ( e instanceof Error ? e : new Error ( String ( e ) ) ) ;
2020-08-12 18:00:01 +01:00
process . exitCode = 1 ;
2020-08-11 12:43:27 +01:00
}
} ) ;
program . parse ( process . argv ) ;
2020-08-24 14:21:03 +01:00
//# sourceMappingURL=runner.js.map