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

Go list implementation for detecting dependencies #5

Merged
merged 23 commits into from
May 24, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove prefix from go target
  • Loading branch information
lseppala authored May 18, 2022
commit e42670539957f51bb2df4da874301c404794206c
16 changes: 10 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,27 @@ async function detect () {
}
const goModDir = path.dirname(goModPath)

const goBuildTarget = path.normalize(core.getInput('go-build-target'))
let goBuildTarget = path.normalize(core.getInput('go-build-target'))
if (goBuildTarget !== 'all' && goBuildTarget !== '...') {
if (!fs.existsSync(goBuildTarget)) {
throw new Error(`The build target '${goBuildTarget}' does not exist`)
}
if (goModDir !== '.' && !goBuildTarget.startsWith(goModDir)) {
throw new Error(
`The build target ${goBuildTarget} is not a sub-directory of ${goModDir}`
)
if (goBuildTarget.startsWith(goModDir)) {
goBuildTarget = goBuildTarget.replace(goModDir, '')
} else {
throw new Error(
`The build target ${goBuildTarget} is not a sub-directory of ${goModDir}`
)
}
}
}

const metadataInput = core.getInput('metadata')
go(goModDir, goBuildTarget, metadataInput)
processGoTarget(goModDir, goBuildTarget, metadataInput)
}

function go (goModDir: string, goBuildTarget: string, metadataInput?: string) {
function processGoTarget (goModDir: string, goBuildTarget: string, metadataInput?: string) {
process.chdir(goModDir)
console.log(
`Running go package detection in ${process.cwd()} on build target ${goBuildTarget}`
Expand Down