File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -288,7 +288,13 @@ jobs:
288288
289289 - name : Vendor Go workspace dependencies
290290 if : ${{ hashFiles('go.work') != '' }}
291- run : go work vendor
291+ run : |
292+ go work vendor
293+ # Tell all subsequent Go commands (including those run by Detect) to use the vendor directory
294+ echo "GOFLAGS=-mod=vendor" >> "$GITHUB_ENV"
295+ # Calculate the detector search depth needed to find go.mod files in workspace module subdirs
296+ GO_WORK_DEPTH=$(grep -E '^\s*use\s+\.' go.work | awk '{print $2}' | tr -d '"' | awk -F'/' '{print NF-1}' | sort -n | tail -1)
297+ echo "GO_WORK_DETECTOR_DEPTH=${GO_WORK_DEPTH}" >> "$GITHUB_ENV"
292298
293299 - name : Construct BlackDuck detect arguments
294300 id : detect-args
@@ -314,9 +320,9 @@ jobs:
314320 DETECT_ARGS="${DETECT_ARGS} --detect.blackduck.scan.mode=RAPID"
315321 fi
316322
317- # If a Go workspace was vendored, tell Detect to use the vendor directory
318- if [[ -f "go.work" && -d "vendor" ]]; then
319- DETECT_ARGS="${DETECT_ARGS} --detect.go.mod.cli.opts=vendor "
323+ # If a Go workspace was vendored, set detector search depth so Detect finds go.mod in module subdirs
324+ if [[ -f "go.work" && -d "vendor" && -n "${{ env.GO_WORK_DETECTOR_DEPTH }}" ]]; then
325+ DETECT_ARGS="${DETECT_ARGS} --detect.detector.search.depth=${{ env.GO_WORK_DETECTOR_DEPTH }} "
320326 fi
321327
322328 echo "DETECT_ARGS=${DETECT_ARGS}" >> $GITHUB_ENV
You can’t perform that action at this time.
0 commit comments