Skip to content
This repository was archived by the owner on Jun 16, 2022. It is now read-only.

Commit 9b96ecf

Browse files
committed
Search directory for go manifests
1 parent b35953e commit 9b96ecf

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
"eslint-plugin-promise": "^6.0.0"
3434
},
3535
"dependencies": {
36+
"@actions/core": "^1.6.0",
37+
"@actions/github": "^5.0.0",
3638
"@github/dependency-submission-toolkit": "^1.0.0",
3739
"jest": "^27.5.1"
3840
}

src/index.ts

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import * as core from '@actions/core'
22
import { run } from '@github/dependency-snapshot-action'
33
import { ProcessDependenciesContent } from '@github/dependency-snapshot-action/dist/processor'
44
import { parseDependents } from './go_mod_parser'
5+
import * as path from 'path'
6+
import * as process from 'process'
7+
import execa from 'execa'
58

69
const 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

Comments
 (0)