@@ -321,11 +321,31 @@ export async function getSupportedLanguageMap(
321321 return supportedLanguages ;
322322}
323323
324+ const baseWorkflowsPath = ".github/workflows" ;
325+
326+ /**
327+ * Determines if there exists a `.github/workflows` directory with at least
328+ * one file in it, which we use as an indicator that there are Actions
329+ * workflows in the workspace. This doesn't perfectly detect whether there
330+ * are actually workflows, but should be a good approximation.
331+ *
332+ * Alternatively, we could check specifically for yaml files, or call the
333+ * API to check if it knows about workflows.
334+ *
335+ * @returns True if the non-empty directory exists, false if not.
336+ */
337+ export function hasActionsWorkflows ( sourceRoot : string ) : boolean {
338+ const workflowsPath = path . resolve ( sourceRoot , baseWorkflowsPath ) ;
339+ const stats = fs . lstatSync ( workflowsPath ) ;
340+ return stats . isDirectory ( ) && fs . readdirSync ( workflowsPath ) . length > 0 ;
341+ }
342+
324343/**
325344 * Gets the set of languages in the current repository.
326345 */
327346export async function getRawLanguagesInRepo (
328347 repository : RepositoryNwo ,
348+ sourceRoot : string ,
329349 logger : Logger ,
330350) : Promise < string [ ] > {
331351 logger . debug ( `GitHub repo ${ repository . owner } ${ repository . repo } ` ) ;
@@ -335,9 +355,18 @@ export async function getRawLanguagesInRepo(
335355 } ) ;
336356
337357 logger . debug ( `Languages API response: ${ JSON . stringify ( response ) } ` ) ;
338- return Object . keys ( response . data as Record < string , number > ) . map ( ( language ) =>
339- language . trim ( ) . toLowerCase ( ) ,
358+ const result = Object . keys ( response . data as Record < string , number > ) . map (
359+ ( language ) => language . trim ( ) . toLowerCase ( ) ,
340360 ) ;
361+
362+ if ( hasActionsWorkflows ( sourceRoot ) ) {
363+ logger . debug ( `Found a .github/workflows directory` ) ;
364+ result . push ( "actions" ) ;
365+ }
366+
367+ logger . debug ( `Raw languages in repository: ${ result . join ( ", " ) } ` ) ;
368+
369+ return result ;
341370}
342371
343372/**
@@ -354,12 +383,14 @@ export async function getLanguages(
354383 codeql : CodeQL ,
355384 languagesInput : string | undefined ,
356385 repository : RepositoryNwo ,
386+ sourceRoot : string ,
357387 logger : Logger ,
358388) : Promise < Language [ ] > {
359389 // Obtain languages without filtering them.
360390 const { rawLanguages, autodetected } = await getRawLanguages (
361391 languagesInput ,
362392 repository ,
393+ sourceRoot ,
363394 logger ,
364395 ) ;
365396
@@ -420,6 +451,7 @@ export function getRawLanguagesNoAutodetect(
420451export async function getRawLanguages (
421452 languagesInput : string | undefined ,
422453 repository : RepositoryNwo ,
454+ sourceRoot : string ,
423455 logger : Logger ,
424456) : Promise < {
425457 rawLanguages : string [ ] ;
@@ -432,7 +464,7 @@ export async function getRawLanguages(
432464 }
433465 // Otherwise, autodetect languages in the repository.
434466 return {
435- rawLanguages : await getRawLanguagesInRepo ( repository , logger ) ,
467+ rawLanguages : await getRawLanguagesInRepo ( repository , sourceRoot , logger ) ,
436468 autodetected : true ,
437469 } ;
438470}
@@ -481,6 +513,7 @@ export async function getDefaultConfig({
481513 repository,
482514 tempDir,
483515 codeql,
516+ sourceRoot,
484517 githubVersion,
485518 features,
486519 logger,
@@ -489,6 +522,7 @@ export async function getDefaultConfig({
489522 codeql ,
490523 languagesInput ,
491524 repository ,
525+ sourceRoot ,
492526 logger ,
493527 ) ;
494528
0 commit comments