@@ -2,6 +2,7 @@ import * as core from '@actions/core';
22import * as exec from '@actions/exec' ;
33import * as io from '@actions/io' ;
44import * as fs from 'fs' ;
5+ import * as os from 'os' ;
56import * as path from 'path' ;
67
78import * as configUtils from './config-utils' ;
@@ -10,6 +11,23 @@ import * as sharedEnv from './shared-environment';
1011import * as upload_lib from './upload-lib' ;
1112import * as util from './util' ;
1213
14+ function getMemoryFlag ( ) : string {
15+ let memoryToUseMegaBytes : number ;
16+ const memoryToUseString = core . getInput ( "ram" ) ;
17+ if ( memoryToUseString ) {
18+ memoryToUseMegaBytes = Number ( memoryToUseString ) ;
19+ if ( Number . isNaN ( memoryToUseMegaBytes ) || memoryToUseMegaBytes <= 0 ) {
20+ throw new Error ( "Invalid RAM setting \"" + memoryToUseString + "\", specified." ) ;
21+ }
22+ } else {
23+ const totalMemoryBytes = os . totalmem ( ) ;
24+ const totalMemoryMegaBytes = totalMemoryBytes / ( 1024 * 1024 ) ;
25+ const systemReservedMemoryMegaBytes = 256 ;
26+ memoryToUseMegaBytes = totalMemoryMegaBytes - systemReservedMemoryMegaBytes ;
27+ }
28+ return "--ram=" + Math . floor ( memoryToUseMegaBytes ) ;
29+ }
30+
1331async function createdDBForScannedLanguages ( codeqlCmd : string , databaseFolder : string ) {
1432 const scannedLanguages = process . env [ sharedEnv . CODEQL_ACTION_SCANNED_LANGUAGES ] ;
1533 if ( scannedLanguages ) {
@@ -113,6 +131,7 @@ async function runQueries(codeqlCmd: string, databaseFolder: string, sarifFolder
113131 await exec . exec ( codeqlCmd , [
114132 'database' ,
115133 'analyze' ,
134+ getMemoryFlag ( ) ,
116135 path . join ( databaseFolder , database ) ,
117136 '--format=sarif-latest' ,
118137 '--output=' + sarifFile ,
0 commit comments