2020-04-28 16:46:47 +02: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 ;
2023-01-18 20:00:33 +00:00
var desc = Object . getOwnPropertyDescriptor ( m , k ) ;
if ( ! desc || ( "get" in desc ? ! m . _ _esModule : desc . writable || desc . configurable ) ) {
desc = { enumerable : true , get : function ( ) { return m [ k ] ; } } ;
}
Object . defineProperty ( o , k2 , desc ) ;
2021-07-27 17:59:59 +01:00
} ) : ( 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-04-28 16:46:47 +02: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-04-28 16:46:47 +02:00
return result ;
} ;
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
2021-06-29 16:00:55 -05:00
const path = _ _importStar ( require ( "path" ) ) ;
2021-06-29 16:17:28 -05:00
const core = _ _importStar ( require ( "@actions/core" ) ) ;
2021-05-20 15:20:32 -07:00
const actions _util _1 = require ( "./actions-util" ) ;
2022-03-14 08:20:27 -07:00
const api _client _1 = require ( "./api-client" ) ;
2021-09-15 14:49:20 +01:00
const codeql _1 = require ( "./codeql" ) ;
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" ) ;
2020-10-06 11:30:05 +02:00
const languages _1 = require ( "./languages" ) ;
2020-08-25 16:19:15 +01:00
const logging _1 = require ( "./logging" ) ;
2020-08-27 10:46:26 +01:00
const repository _1 = require ( "./repository" ) ;
2022-08-15 14:44:43 +01:00
const trap _caching _1 = require ( "./trap-caching" ) ;
2020-11-26 17:54:34 +00:00
const util _1 = require ( "./util" ) ;
2022-11-22 16:47:27 +00:00
const workflow _1 = require ( "./workflow" ) ;
2021-06-01 14:49:07 -07:00
// eslint-disable-next-line import/no-commonjs
const pkg = require ( "../package.json" ) ;
2022-08-16 13:30:49 +01:00
async function sendSuccessStatusReport ( startedAt , config , toolsVersion , logger ) {
2021-09-10 13:53:13 -07:00
const statusReportBase = await ( 0 , actions _util _1 . createStatusReportBase ) ( "init" , "success" , startedAt ) ;
2020-09-14 10:44:43 +01:00
const languages = config . languages . join ( "," ) ;
2021-09-10 13:53:13 -07:00
const workflowLanguages = ( 0 , actions _util _1 . getOptionalInput ) ( "languages" ) ;
2020-09-14 10:44:43 +01:00
const paths = ( config . originalUserInput . paths || [ ] ) . join ( "," ) ;
const pathsIgnore = ( config . originalUserInput [ "paths-ignore" ] || [ ] ) . join ( "," ) ;
const disableDefaultQueries = config . originalUserInput [ "disable-default-queries" ]
? languages
: "" ;
2020-09-17 17:29:45 +01:00
const queries = [ ] ;
2023-01-18 20:00:33 +00:00
let queriesInput = ( 0 , actions _util _1 . getOptionalInput ) ( "queries" ) ? . trim ( ) ;
2020-09-17 17:29:45 +01:00
if ( queriesInput === undefined || queriesInput . startsWith ( "+" ) ) {
queries . push ( ... ( config . originalUserInput . queries || [ ] ) . map ( ( q ) => q . uses ) ) ;
}
if ( queriesInput !== undefined ) {
queriesInput = queriesInput . startsWith ( "+" )
2022-03-20 05:55:28 +01:00
? queriesInput . slice ( 1 )
2020-09-17 17:29:45 +01:00
: queriesInput ;
queries . push ( ... queriesInput . split ( "," ) ) ;
}
2020-07-20 16:33:37 +01:00
const statusReport = {
... statusReportBase ,
2022-02-03 11:52:49 +00:00
disable _default _queries : disableDefaultQueries ,
2020-09-14 10:44:43 +01:00
languages ,
2022-02-09 12:56:31 +00:00
ml _powered _javascript _queries : ( 0 , util _1 . getMlPoweredJsQueriesStatus ) ( config ) ,
2020-09-14 10:44:43 +01:00
paths ,
2020-07-20 16:33:37 +01:00
paths _ignore : pathsIgnore ,
2020-09-17 17:29:45 +01:00
queries : queries . join ( "," ) ,
2021-09-10 13:53:13 -07:00
tools _input : ( 0 , actions _util _1 . getOptionalInput ) ( "tools" ) || "" ,
2020-11-11 18:22:12 +00:00
tools _resolved _version : toolsVersion ,
2022-02-03 11:52:49 +00:00
workflow _languages : workflowLanguages || "" ,
2022-08-15 14:44:43 +01:00
trap _cache _languages : Object . keys ( config . trapCaches ) . join ( "," ) ,
2022-08-17 13:30:17 +01:00
trap _cache _download _size _bytes : Math . round ( await ( 0 , trap _caching _1 . getTotalCacheSize ) ( config . trapCaches , logger ) ) ,
trap _cache _download _duration _ms : Math . round ( config . trapCacheDownloadTime ) ,
2020-07-20 16:33:37 +01:00
} ;
2021-09-10 13:53:13 -07:00
await ( 0 , actions _util _1 . sendStatusReport ) ( statusReport ) ;
2020-07-20 16:33:37 +01:00
}
2020-04-28 16:46:47 +02:00
async function run ( ) {
2020-07-20 16:33:37 +01:00
const startedAt = new Date ( ) ;
2021-09-10 13:53:13 -07:00
const logger = ( 0 , logging _1 . getActionsLogger ) ( ) ;
2022-11-14 16:37:48 +00:00
( 0 , util _1 . initializeEnvironment ) ( pkg . version ) ;
2022-04-26 16:45:44 +01:00
await ( 0 , util _1 . checkActionVersion ) ( pkg . version ) ;
2020-06-26 15:33:59 +01:00
let config ;
let codeql ;
2020-11-11 18:22:12 +00:00
let toolsVersion ;
2020-11-26 17:54:34 +00:00
const apiDetails = {
2021-09-10 13:53:13 -07:00
auth : ( 0 , actions _util _1 . getRequiredInput ) ( "token" ) ,
externalRepoAuth : ( 0 , actions _util _1 . getOptionalInput ) ( "external-repository-token" ) ,
url : ( 0 , util _1 . getRequiredEnvParam ) ( "GITHUB_SERVER_URL" ) ,
2022-08-10 21:11:50 +01:00
apiURL : ( 0 , util _1 . getRequiredEnvParam ) ( "GITHUB_API_URL" ) ,
2020-11-26 17:54:34 +00:00
} ;
2022-11-14 16:37:48 +00:00
const gitHubVersion = await ( 0 , api _client _1 . getGitHubVersion ) ( ) ;
( 0 , util _1 . checkGitHubVersionInRange ) ( gitHubVersion , logger ) ;
2021-12-15 13:34:29 +00:00
const repositoryNwo = ( 0 , repository _1 . parseRepositoryNwo ) ( ( 0 , util _1 . getRequiredEnvParam ) ( "GITHUB_REPOSITORY" ) ) ;
2022-11-21 11:14:38 -08:00
const features = new feature _flags _1 . Features ( gitHubVersion , repositoryNwo , ( 0 , actions _util _1 . getTemporaryDirectory ) ( ) , logger ) ;
2020-04-28 16:46:47 +02:00
try {
2022-11-22 16:47:27 +00:00
const workflowErrors = await ( 0 , workflow _1 . validateWorkflow ) ( ) ;
2021-09-10 13:53:13 -07:00
if ( ! ( await ( 0 , actions _util _1 . sendStatusReport ) ( await ( 0 , actions _util _1 . createStatusReportBase ) ( "init" , "starting" , startedAt , workflowErrors ) ) ) ) {
2020-04-28 16:46:47 +02:00
return ;
}
2022-11-23 14:53:40 -08:00
const initCodeQLResult = await ( 0 , init _1 . initCodeQL ) ( ( 0 , actions _util _1 . getOptionalInput ) ( "tools" ) , apiDetails , ( 0 , actions _util _1 . getTemporaryDirectory ) ( ) , gitHubVersion . type , await ( 0 , util _1 . shouldBypassToolcache ) ( features , ( 0 , actions _util _1 . getOptionalInput ) ( "tools" ) , ( 0 , actions _util _1 . getOptionalInput ) ( "languages" ) , repositoryNwo , logger ) , logger ) ;
2020-11-11 18:22:12 +00:00
codeql = initCodeQLResult . codeql ;
toolsVersion = initCodeQLResult . toolsVersion ;
2022-11-14 16:37:48 +00:00
await ( 0 , util _1 . enrichEnvironment ) ( codeql ) ;
2022-10-11 10:39:40 -07:00
config = await ( 0 , init _1 . initConfig ) ( ( 0 , actions _util _1 . getOptionalInput ) ( "languages" ) , ( 0 , actions _util _1 . getOptionalInput ) ( "queries" ) , ( 0 , actions _util _1 . getOptionalInput ) ( "packs" ) , ( 0 , actions _util _1 . getOptionalInput ) ( "registries" ) , ( 0 , actions _util _1 . getOptionalInput ) ( "config-file" ) , ( 0 , actions _util _1 . getOptionalInput ) ( "db-location" ) , await getTrapCachingEnabled ( features ) ,
2022-06-28 22:49:42 +01:00
// Debug mode is enabled if:
2022-07-12 16:19:13 +01:00
// - The `init` Action is passed `debug: true`.
2022-06-28 22:49:42 +01:00
// - Actions step debugging is enabled (e.g. by [enabling debug logging for a rerun](https://docs.github.com/en/actions/managing-workflow-runs/re-running-workflows-and-jobs#re-running-all-the-jobs-in-a-workflow),
// or by setting the `ACTIONS_STEP_DEBUG` secret to `true`).
2022-10-11 10:39:40 -07:00
( 0 , actions _util _1 . getOptionalInput ) ( "debug" ) === "true" || core . isDebug ( ) , ( 0 , actions _util _1 . getOptionalInput ) ( "debug-artifact-name" ) || util _1 . DEFAULT _DEBUG _ARTIFACT _NAME , ( 0 , actions _util _1 . getOptionalInput ) ( "debug-database-name" ) || util _1 . DEFAULT _DEBUG _DATABASE _NAME , repositoryNwo , ( 0 , actions _util _1 . getTemporaryDirectory ) ( ) , codeql , ( 0 , util _1 . getRequiredEnvParam ) ( "GITHUB_WORKSPACE" ) , gitHubVersion , apiDetails , features , logger ) ;
2020-10-27 10:06:17 +01:00
if ( config . languages . includes ( languages _1 . Language . python ) &&
2021-09-10 13:53:13 -07:00
( 0 , actions _util _1 . getRequiredInput ) ( "setup-python-dependencies" ) === "true" ) {
2020-10-06 11:30:05 +02:00
try {
2021-09-10 13:53:13 -07:00
await ( 0 , init _1 . installPythonDeps ) ( codeql , logger ) ;
2020-10-06 11:30:05 +02:00
}
catch ( err ) {
2021-09-10 13:53:13 -07:00
const message = err instanceof Error ? err . message : String ( err ) ;
logger . warning ( ` ${ message } You can call this action with 'setup-python-dependencies: false' to disable this process ` ) ;
2020-10-06 11:30:05 +02:00
}
2020-09-11 10:53:41 +02:00
}
2020-06-23 18:36:08 +02:00
}
catch ( e ) {
2021-09-10 13:53:13 -07:00
const message = e instanceof Error ? e . message : String ( e ) ;
core . setFailed ( message ) ;
2020-08-05 09:40:28 +01:00
console . log ( e ) ;
2021-09-10 13:53:13 -07:00
await ( 0 , actions _util _1 . sendStatusReport ) ( await ( 0 , actions _util _1 . createStatusReportBase ) ( "init" , "aborted" , startedAt , message ) ) ;
2020-06-23 18:36:08 +02:00
return ;
}
try {
2020-04-28 16:46:47 +02:00
// Forward Go flags
2020-09-14 10:44:43 +01:00
const goFlags = process . env [ "GOFLAGS" ] ;
2020-04-28 16:46:47 +02:00
if ( goFlags ) {
2020-09-14 10:44:43 +01:00
core . exportVariable ( "GOFLAGS" , goFlags ) ;
2020-04-28 16:46:47 +02:00
core . warning ( "Passing the GOFLAGS env parameter to the init action is deprecated. Please move this to the analyze action." ) ;
}
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.
core . exportVariable ( "CODEQL_RAM" , process . env [ "CODEQL_RAM" ] ||
( 0 , util _1 . getMemoryFlagValue ) ( ( 0 , actions _util _1 . getOptionalInput ) ( "ram" ) ) . toString ( ) ) ;
core . exportVariable ( "CODEQL_THREADS" , ( 0 , util _1 . getThreadsFlagValue ) ( ( 0 , actions _util _1 . getOptionalInput ) ( "threads" ) , logger ) . toString ( ) ) ;
2022-11-17 10:38:48 -08:00
// Disable Kotlin extractor if feature flag set
if ( await features . getValue ( feature _flags _1 . Feature . DisableKotlinAnalysisEnabled ) ) {
core . exportVariable ( "CODEQL_EXTRACTOR_JAVA_AGENT_DISABLE_KOTLIN" , "true" ) ;
}
2021-09-10 13:53:13 -07:00
const sourceRoot = path . resolve ( ( 0 , util _1 . getRequiredEnvParam ) ( "GITHUB_WORKSPACE" ) , ( 0 , actions _util _1 . getOptionalInput ) ( "source-root" ) || "" ) ;
2022-11-14 18:49:17 +00:00
const tracerConfig = await ( 0 , init _1 . runInit ) ( codeql , config , sourceRoot , "Runner.Worker.exe" , features , logger ) ;
2020-08-24 12:53:09 +01:00
if ( tracerConfig !== undefined ) {
2020-09-20 17:03:01 +08:00
for ( const [ key , value ] of Object . entries ( tracerConfig . env ) ) {
core . exportVariable ( key , value ) ;
}
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 ) ( "Runner.Worker.exe" , undefined , config , codeql , tracerConfig ) ;
2020-09-07 13:36:47 +01:00
}
2020-04-28 16:46:47 +02:00
}
2020-11-04 19:10:27 +00:00
core . setOutput ( "codeql-path" , config . codeQLCmd ) ;
2020-04-28 16:46:47 +02:00
}
catch ( error ) {
2021-09-10 13:53:13 -07:00
core . setFailed ( String ( error ) ) ;
2020-08-05 09:40:28 +01:00
console . log ( error ) ;
2022-02-17 11:47:04 -08:00
await ( 0 , actions _util _1 . sendStatusReport ) ( await ( 0 , actions _util _1 . createStatusReportBase ) ( "init" , ( 0 , actions _util _1 . getActionsStatus ) ( error ) , startedAt , String ( error ) , error instanceof Error ? error . stack : undefined ) ) ;
2020-04-28 16:46:47 +02:00
return ;
}
2022-08-16 13:30:49 +01:00
await sendSuccessStatusReport ( startedAt , config , toolsVersion , logger ) ;
2020-04-28 16:46:47 +02:00
}
2022-10-11 10:39:40 -07:00
async function getTrapCachingEnabled ( featureEnablement ) {
2022-10-13 14:31:54 +01:00
// If the workflow specified something always respect that
2022-08-02 17:52:22 +01:00
const trapCaching = ( 0 , actions _util _1 . getOptionalInput ) ( "trap-caching" ) ;
2022-10-13 14:31:54 +01:00
if ( trapCaching !== undefined )
2022-08-09 18:37:22 +01:00
return trapCaching === "true" ;
2022-10-13 14:31:54 +01:00
// On self-hosted runners which may have slow network access, disable TRAP caching by default
if ( ! ( 0 , util _1 . isHostedRunner ) ( ) )
return false ;
// On hosted runners, respect the feature flag
2022-10-11 10:39:40 -07:00
return await featureEnablement . getValue ( feature _flags _1 . Feature . TrapCachingEnabled ) ;
2022-08-02 17:52:22 +01:00
}
2020-11-25 22:46:30 +01:00
async function runWrapper ( ) {
try {
await run ( ) ;
}
catch ( error ) {
core . setFailed ( ` init action failed: ${ error } ` ) ;
console . log ( error ) ;
}
2022-11-16 11:20:47 +00:00
await ( 0 , util _1 . checkForTimeout ) ( ) ;
2020-11-25 22:46:30 +01:00
}
void runWrapper ( ) ;
2020-08-24 15:09:02 +01:00
//# sourceMappingURL=init-action.js.map