@@ -321,23 +321,58 @@ 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 (
341+ stats !== undefined &&
342+ stats . isDirectory ( ) &&
343+ fs . readdirSync ( workflowsPath ) . length > 0
344+ ) ;
345+ }
346+
324347/**
325348 * Gets the set of languages in the current repository.
326349 */
327350export async function getRawLanguagesInRepo (
328351 repository : RepositoryNwo ,
352+ sourceRoot : string ,
329353 logger : Logger ,
330354) : Promise < string [ ] > {
331- logger . debug ( `GitHub repo ${ repository . owner } ${ repository . repo } ` ) ;
355+ logger . debug (
356+ `Automatically detecting languages (${ repository . owner } /${ repository . repo } )` ,
357+ ) ;
332358 const response = await api . getApiClient ( ) . rest . repos . listLanguages ( {
333359 owner : repository . owner ,
334360 repo : repository . repo ,
335361 } ) ;
336362
337363 logger . debug ( `Languages API response: ${ JSON . stringify ( response ) } ` ) ;
338- return Object . keys ( response . data as Record < string , number > ) . map ( ( language ) =>
339- language . trim ( ) . toLowerCase ( ) ,
364+ const result = Object . keys ( response . data as Record < string , number > ) . map (
365+ ( language ) => language . trim ( ) . toLowerCase ( ) ,
340366 ) ;
367+
368+ if ( hasActionsWorkflows ( sourceRoot ) ) {
369+ logger . debug ( `Found a .github/workflows directory` ) ;
370+ result . push ( "actions" ) ;
371+ }
372+
373+ logger . debug ( `Raw languages in repository: ${ result . join ( ", " ) } ` ) ;
374+
375+ return result ;
341376}
342377
343378/**
@@ -354,12 +389,14 @@ export async function getLanguages(
354389 codeql : CodeQL ,
355390 languagesInput : string | undefined ,
356391 repository : RepositoryNwo ,
392+ sourceRoot : string ,
357393 logger : Logger ,
358394) : Promise < Language [ ] > {
359395 // Obtain languages without filtering them.
360396 const { rawLanguages, autodetected } = await getRawLanguages (
361397 languagesInput ,
362398 repository ,
399+ sourceRoot ,
363400 logger ,
364401 ) ;
365402
@@ -420,6 +457,7 @@ export function getRawLanguagesNoAutodetect(
420457export async function getRawLanguages (
421458 languagesInput : string | undefined ,
422459 repository : RepositoryNwo ,
460+ sourceRoot : string ,
423461 logger : Logger ,
424462) : Promise < {
425463 rawLanguages : string [ ] ;
@@ -432,7 +470,7 @@ export async function getRawLanguages(
432470 }
433471 // Otherwise, autodetect languages in the repository.
434472 return {
435- rawLanguages : await getRawLanguagesInRepo ( repository , logger ) ,
473+ rawLanguages : await getRawLanguagesInRepo ( repository , sourceRoot , logger ) ,
436474 autodetected : true ,
437475 } ;
438476}
@@ -481,6 +519,7 @@ export async function getDefaultConfig({
481519 repository,
482520 tempDir,
483521 codeql,
522+ sourceRoot,
484523 githubVersion,
485524 features,
486525 logger,
@@ -489,6 +528,7 @@ export async function getDefaultConfig({
489528 codeql ,
490529 languagesInput ,
491530 repository ,
531+ sourceRoot ,
492532 logger ,
493533 ) ;
494534
0 commit comments