@@ -2,6 +2,9 @@ import * as core from '@actions/core'
22import { run } from '@github/dependency-snapshot-action'
33import { ProcessDependenciesContent } from '@github/dependency-snapshot-action/dist/processor'
44import { parseDependents } from './go_mod_parser'
5+ import * as path from 'path'
6+ import * as process from 'process'
7+ import execa from 'execa'
58
69const parseDependentsFunc : ProcessDependenciesContent = parseDependents
710
@@ -12,11 +15,43 @@ const detector = {
1215 version : core . getInput ( 'detector-version' )
1316}
1417
15- // If provided, set the metadata provided from the action workflow input
16- const metadataInput = core . getInput ( 'metadata' )
17- if ( metadataInput . length < 1 ) {
18- run ( parseDependentsFunc , { command : 'go mod graph' } , { detector } )
19- } else {
20- const metadata = JSON . parse ( metadataInput )
21- run ( parseDependentsFunc , { command : 'go mod graph' } , { metadata, detector } )
18+ async function searchForFile ( filename :string ) {
19+ const { stdout } = await execa ( 'find' , [
20+ '.' ,
21+ `-name ${ filename } `
22+ ] )
23+
24+ const dirs = stdout
25+ . split ( '\n' )
26+ // remove the file name
27+ . map ( ( filename ) => path . dirname ( filename ) )
28+ // map to absolute path
29+ . map ( ( pathname ) => path . resolve ( __dirname , pathname ) )
30+
31+ return dirs
32+ }
33+
34+ // Enumerate directories
35+ async function detect ( ) {
36+ const goModPaths = searchForFile ( 'go.mod' )
37+ const goSumPaths = searchForFile ( 'go.sum' )
38+
39+ // Concatenate both lists and remove duplicates
40+ const allPaths = new Set ( ( await goModPaths ) . concat ( await goSumPaths ) )
41+
42+ // If provided, set the metadata provided from the action workflow input
43+ const metadataInput = core . getInput ( 'metadata' )
44+
45+ allPaths . forEach ( ( path ) => {
46+ process . chdir ( path )
47+ console . log ( `Running go mod graph in ${ path } ` )
48+ if ( metadataInput . length < 1 ) {
49+ run ( parseDependentsFunc , { command : 'go mod graph' } , { detector } )
50+ } else {
51+ const metadata = JSON . parse ( metadataInput )
52+ run ( parseDependentsFunc , { command : 'go mod graph' } , { metadata, detector } )
53+ }
54+ } )
2255}
56+
57+ detect ( )
0 commit comments