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" ) ;
2023-04-06 15:08:48 +01:00
async function sendCompletedStatusReport ( startedAt , config , toolsDownloadDurationMs , toolsFeatureFlagsValid , toolsSource , toolsVersion , logger , error ) {
const statusReportBase = await ( 0 , actions _util _1 . createStatusReportBase ) ( "init" , ( 0 , actions _util _1 . getActionsStatus ) ( error ) , startedAt , error ? . message , error ? . stack ) ;
2021-09-10 13:53:13 -07:00
const workflowLanguages = ( 0 , actions _util _1 . getOptionalInput ) ( "languages" ) ;
2023-01-25 11:09:18 -08:00
const initStatusReport = {
2020-07-20 16:33:37 +01:00
... statusReportBase ,
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 ,
2023-01-25 11:09:18 -08:00
tools _source : toolsSource || init _1 . ToolsSource . Unknown ,
2022-02-03 11:52:49 +00:00
workflow _languages : workflowLanguages || "" ,
2020-07-20 16:33:37 +01:00
} ;
2023-02-13 13:45:54 -08:00
const initToolsDownloadFields = { } ;
if ( toolsDownloadDurationMs !== undefined ) {
initToolsDownloadFields . tools _download _duration _ms =
toolsDownloadDurationMs ;
}
if ( toolsFeatureFlagsValid !== undefined ) {
initToolsDownloadFields . tools _feature _flags _valid = toolsFeatureFlagsValid ;
2023-01-25 11:09:18 -08:00
}
if ( config !== undefined ) {
const languages = config . languages . join ( "," ) ;
const paths = ( config . originalUserInput . paths || [ ] ) . join ( "," ) ;
const pathsIgnore = ( config . originalUserInput [ "paths-ignore" ] || [ ] ) . join ( "," ) ;
const disableDefaultQueries = config . originalUserInput [ "disable-default-queries" ]
? languages
: "" ;
const queries = [ ] ;
let queriesInput = ( 0 , actions _util _1 . getOptionalInput ) ( "queries" ) ? . trim ( ) ;
if ( queriesInput === undefined || queriesInput . startsWith ( "+" ) ) {
queries . push ( ... ( config . originalUserInput . queries || [ ] ) . map ( ( q ) => q . uses ) ) ;
}
if ( queriesInput !== undefined ) {
queriesInput = queriesInput . startsWith ( "+" )
? queriesInput . slice ( 1 )
: queriesInput ;
queries . push ( ... queriesInput . split ( "," ) ) ;
}
// Append fields that are dependent on `config`
const initWithConfigStatusReport = {
... initStatusReport ,
disable _default _queries : disableDefaultQueries ,
languages ,
ml _powered _javascript _queries : ( 0 , util _1 . getMlPoweredJsQueriesStatus ) ( config ) ,
paths ,
paths _ignore : pathsIgnore ,
queries : queries . join ( "," ) ,
trap _cache _languages : Object . keys ( config . trapCaches ) . join ( "," ) ,
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 ) ,
} ;
await ( 0 , actions _util _1 . sendStatusReport ) ( {
... initWithConfigStatusReport ,
... initToolsDownloadFields ,
} ) ;
}
else {
await ( 0 , actions _util _1 . sendStatusReport ) ( { ... initStatusReport , ... initToolsDownloadFields } ) ;
}
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 ) ( ) ;
2023-01-20 12:03:17 +00:00
( 0 , util _1 . initializeEnvironment ) ( ( 0 , actions _util _1 . getActionVersion ) ( ) ) ;
2020-06-26 15:33:59 +01:00
let config ;
let codeql ;
2023-01-25 11:09:18 -08:00
let toolsDownloadDurationMs ;
let toolsFeatureFlagsValid ;
let toolsSource ;
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" ) ) ;
2023-02-07 10:40:49 -08:00
const registriesInput = ( 0 , actions _util _1 . getOptionalInput ) ( "registries" ) ;
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 {
2023-04-11 18:25:14 +01:00
const workflowErrors = await ( 0 , workflow _1 . validateWorkflow ) ( logger ) ;
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 ;
}
2023-01-25 11:09:18 -08:00
const codeQLDefaultVersionInfo = await features . getDefaultCliVersion ( gitHubVersion . type ) ;
if ( codeQLDefaultVersionInfo . variant === util _1 . GitHubVariant . DOTCOM ) {
toolsFeatureFlagsValid = codeQLDefaultVersionInfo . toolsFeatureFlagsValid ;
}
2023-02-08 15:20:51 +00:00
const initCodeQLResult = await ( 0 , init _1 . initCodeQL ) ( ( 0 , actions _util _1 . getOptionalInput ) ( "tools" ) , apiDetails , ( 0 , actions _util _1 . getTemporaryDirectory ) ( ) , gitHubVersion . type , codeQLDefaultVersionInfo , logger ) ;
2020-11-11 18:22:12 +00:00
codeql = initCodeQLResult . codeql ;
2023-01-25 11:09:18 -08:00
toolsDownloadDurationMs = initCodeQLResult . toolsDownloadDurationMs ;
2020-11-11 18:22:12 +00:00
toolsVersion = initCodeQLResult . toolsVersion ;
2023-01-25 11:09:18 -08:00
toolsSource = initCodeQLResult . toolsSource ;
2023-03-24 20:14:00 +00:00
await ( 0 , codeql _1 . enrichEnvironment ) ( codeql ) ;
2023-02-26 18:35:21 -08: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" ) , registriesInput , ( 0 , actions _util _1 . getOptionalInput ) ( "config-file" ) , ( 0 , actions _util _1 . getOptionalInput ) ( "db-location" ) , getTrapCachingEnabled ( ) ,
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
}
2023-04-06 17:04:21 +01:00
catch ( unwrappedError ) {
const error = ( 0 , util _1 . wrapError ) ( unwrappedError ) ;
logger . warning ( ` ${ error . 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
}
2023-04-06 17:04:21 +01:00
catch ( unwrappedError ) {
const error = ( 0 , util _1 . wrapError ) ( unwrappedError ) ;
core . setFailed ( error . message ) ;
await ( 0 , actions _util _1 . sendStatusReport ) ( await ( 0 , actions _util _1 . createStatusReportBase ) ( "init" , "aborted" , startedAt , error . message , error . stack ) ) ;
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" ) || "" ) ;
2023-02-07 10:40:49 -08:00
const tracerConfig = await ( 0 , init _1 . runInit ) ( codeql , config , sourceRoot , "Runner.Worker.exe" , registriesInput , features , apiDetails , 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
}
2023-04-06 17:04:21 +01:00
catch ( unwrappedError ) {
const error = ( 0 , util _1 . wrapError ) ( unwrappedError ) ;
core . setFailed ( error . message ) ;
await sendCompletedStatusReport ( startedAt , config , toolsDownloadDurationMs , toolsFeatureFlagsValid , toolsSource , toolsVersion , logger , error ) ;
2020-04-28 16:46:47 +02:00
return ;
}
2023-04-06 15:08:48 +01:00
await sendCompletedStatusReport ( startedAt , config , toolsDownloadDurationMs , toolsFeatureFlagsValid , toolsSource , toolsVersion , logger ) ;
2020-04-28 16:46:47 +02:00
}
2023-02-10 09:27:16 -08:00
function getTrapCachingEnabled ( ) {
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 ;
2023-02-10 09:27:16 -08:00
// On hosted runners, enable TRAP caching by default
return true ;
2022-08-02 17:52:22 +01:00
}
2020-11-25 22:46:30 +01:00
async function runWrapper ( ) {
try {
await run ( ) ;
}
catch ( error ) {
2023-04-06 17:04:21 +01:00
core . setFailed ( ` init action failed: ${ ( 0 , util _1 . wrapError ) ( error ) . message } ` ) ;
2020-11-25 22:46:30 +01:00
}
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